Manage DNS on Google Cloud
Use this guide to manage DNS at Google Cloud.
Requirements
You’ll need the following before you can manage DNS at Google Cloud:
- A Google Cloud account and project.
- A domain you’ve registered at any domain registrar.
Learn how to create a Google Cloud account and project.
Manage DNS zones
All DNS records belong to a DNS zone.
Create a DNS zone
Before you can create a DNS zone, you must first enable the Cloud DNS API in your project.
- Go to the Cloud DNS API page in Google Cloud console.
- Click Enable. If there is no Enable button, then the Cloud DNS API is already enabled for this project.
Enable the Cloud DNS API using the gcloud services enable
command.
gcloud services enable dns.googleapis.com
Use your registered domain name as the name of your DNS zone.
A registered domain name, also known as an apex domain, is a domain such as example.com
.
- In Google Cloud console, go to the Cloud DNS Zones page.
- Click Create Zone.
- In the form, enter the following values and leave all other fields set to their defaults values:
- Zone name — Your registered (apex) domain with
the periods replaced with hyphens (
-
). - DNS name — Your registered (apex) domain.
- Zone name — Your registered (apex) domain with
the periods replaced with hyphens (
- Click Create.
Set a shell variable with the registered (apex) domain of the DNS zone.
APEX_DOMAIN="example.com"
Create a DNS zone using the gcloud dns managed-zones create
command.
# The DNS zone name is the apex domain with periods replaced by dashes.DNS_ZONE_NAME="${APEX_DOMAIN//./-}"
gcloud dns managed-zones create "${DNS_ZONE_NAME}" \ --dns-name="${APEX_DOMAIN}." \ --visibility="public" \ --dnssec-state="off"
Update nameservers
DNS queries for your domain will be answered by Google Cloud’s DNS servers after you update your domain’s nameservers at your domain registrar.
Use the following instructions to get the nameservers for your DNS zone.
- In Google Cloud console, go to the Cloud DNS Zones page.
- Click on the name of the DNS zone.
- Click on the DNS record that has the type “NS”.
- The four values in the “Routing data” table are the nameservers for your DNS zone.
Set a shell variable with the registered (apex) domain of the DNS zone.
APEX_DOMAIN="example.com"
Delete a DNS zone using the gcloud dns managed-zones delete
command.
# The DNS zone name is the apex domain with periods replaced by dashes.DNS_ZONE_NAME="${APEX_DOMAIN//./-}"
gcloud dns record-sets list \ --zone="${DNS_ZONE_NAME}" \ --name="${APEX_DOMAIN}." \ --type="NS" \ --format="value(rrdatas[].list())" \ | tr ',' '\n'
Once you know the nameservers for your DNS zone, do the following:
- Log into your domain registrar (the site where you purchased your domain).
- Select your domain and choose the option to edit the domain’s nameservers.
- Add the Google Cloud DNS nameservers. Do not include a period at the end of nameserver values.
- Remove the old nameservers.
Delete a DNS zone
When you delete a DNS zone, the zone and its records will be deleted.
- In Google Cloud console, go to the Cloud DNS Zones page.
- Click on the name of the DNS zone.
- Click on Delete zone.
- In the confirmation dialog box, enter the name of the zone then click Delete.
Set a shell variable with the registered (apex) domain of the DNS zone.
APEX_DOMAIN="example.com"
Delete a DNS zone using the gcloud dns managed-zones delete
command.
# The DNS zone name is the apex domain with periods replaced by dashes.DNS_ZONE_NAME="${APEX_DOMAIN//./-}"
gcloud dns managed-zones delete "${DNS_ZONE_NAME}"
Manage DNS records
Create and delete DNS records in your DNS zone.
Create a DNS record
Use the instructions below to create a DNS record.
- In Google Cloud console, go to the Cloud DNS Zones page.
- Click on the name of the DNS zone.
- Click on Add standard.
- For the DNS Name, enter the subdomain the DNS record is for or leave empty if the DNS record is for your registered (apex) domain.
- For the Resource record type, select the type of DNS record you want to create.
- For the DNS record’s value, set the desired value.
- Click Create.
Set a shell variable with the registered (apex) domain of the DNS zone.
APEX_DOMAIN="example.com"
Set a shell variable with the full domain of the DNS record.
DNS_RECORD_DOMAIN="www.example.com"
Set a shell variable with the IP address value of the DNS record.
IP_ADDRESS="x.x.x.x"
Create a DNS record using the gcloud dns record-sets create
command.
# The DNS zone name is the apex domain with periods replaced by dashes.DNS_ZONE_NAME="${APEX_DOMAIN//./-}"
gcloud dns record-sets create "${DNS_RECORD_DOMAIN}". \ --zone="${DNS_ZONE_NAME}" \ --type="A" \ --ttl="300" \ --rrdatas="${IP_ADDRESS}"
Delete a DNS record
Use the instructions below to delete a DNS record.
- In Google Cloud console, go to the Cloud DNS Zones page.
- Click on the name of the DNS zone.
- Click the DNS record you want to delete.
- Click on Delete resource record set.
- In the confirmation dialog box, click on Delete.
Set a shell variable with the registered (apex) domain of the DNS zone.
APEX_DOMAIN="example.com"
Set a shell variable with the full domain of the DNS record.
DNS_RECORD_DOMAIN="www.example.com"
Create a DNS record using the gcloud dns record-sets delete
command.
# The DNS zone name is the apex domain with periods replaced by dashes.DNS_ZONE_NAME="${APEX_DOMAIN//./-}"
gcloud dns record-sets delete "${DNS_RECORD_DOMAIN}". \ --zone="${DNS_ZONE_NAME}" \ --type="A"