Join Amazon Student FREE Two-Day Shipping for College Students!
13904

Host Your DNS With Google Cloud DNS

Host Your DNS With Google Cloud DNS

Can Google host my DNS? Yes. We can set domain DNS zones using the Google Cloud DNS service. Google Cloud DNS is a high performance, resilient, and global DNS service, which allows you to easily publish and manage DNS records.

It is FREE? Google Cloud DNS provide max billable limit: 50,000 requests/day, so is almost free for a small website.

For a website with huge amount of traffic, see https://developers.google.com/cloud-dns/pricing
for pricing.

1. Create a new Cloud Project.

Google Cloud DNS is part of the Google Cloud Platform. First you need to create a new Cloud Project.

  1. Go to https://console.developers.google.com/project
  2. Create a new project and choose a descriptive project name such as "Google DNS", copy down the project ID because we need it later.
    google-project
  3. Click "Enable an API" from the Project Dashboard.
    google-project-enable-api
  4. Enable "Google Cloud DNS API" (Required). Disable the other default enabled APIs (such as Google Cloud Storage) as they are not required for this project (optional).
    google-cloud-dns-api

2. Install the Google Cloud SDK

Google Cloud SDK contains tools and libraries that enable you to create and manage resources on Google Cloud DNS.

Go to https://developers.google.com/cloud/sdk/, download and install the SDK before you continue.

We only need the Cloud SDK Core Libraries and Tools for Google Cloud DNS.

google-cloud-sdk

Once the Cloud SDK is installed, make sure it includes the required DNS component. Open the Google Cloud SDK shell and execute the following command.

gcloud components list

Cloud-DNS-Admin-Command-Line

If you don't see "Cloud DNS Admin Command Line Interface" as "Installed", run the following command.

gcloud components update dns

Next, authorize access to the Google APIs with your Google domain admin account.

gcloud auth login

You will be asked to give permissions to "Google Cloud SDK" to perform operations on your behalf, and the list of permissions is sufficient to use any of the tools included in the SDK. The command will prompt you to enter the project ID. Enter the value from the Developers Console when you created the project.

Once you see You are now authenticated with the Google Cloud SDK! you can close the browser and continue.

To see if your account has been successfully added run the following command.

gcloud auth list

3. Create a Managed DNS Zone

You will need to set the project ID first. Change the value to the one that you created in the Developers Console.

gcloud config set project all4os

Let’s create a new Cloud DNS managed zone so we can manage DNS zones and records.

gcloud dns managed-zone create --description="all4os.com zone" --dns_name="all4os." all4os
  • –description="all4os.com zone" is a readable description of your DNS zone.
  • –dns_name="all4os.com." is your domain name. Make sure you include the trailing dot.
  • all4os is the name of our managed zone.

You will see:

Creating {'dnsName': 'all4os.com.', 'name': 'all4os', 'description':
'all4os.com zone'} in google-dns

Do you want to continue (Y/n)? Y

{
"creationTime": "2014-07-24T07:15:31.276Z",
"description": "all4os.com zone",
"dnsName": "all4os.com.",
"id": "5988761527897559933",
"kind": "dns#managedZone",
"name": "all4os",
"nameServers": [
"ns-cloud-e1.googledomains.com.",
"ns-cloud-e2.googledomains.com.",
"ns-cloud-e3.googledomains.com.",
"ns-cloud-e4.googledomains.com."
]
}

4. Modify an existing DNS Record

In default, Google has added NS and SOA for us, to see the default detail, run the follow command.

gcloud dns records --zone=all4os list

You will see:

[
{
"kind": "dns#resourceRecordSet",
"name": "all4os.com.",
"rrdatas": [
"ns-cloud-e1.googledomains.com.",
"ns-cloud-e2.googledomains.com.",
"ns-cloud-e3.googledomains.com.",
"ns-cloud-e4.googledomains.com."
],
"ttl": 21600,
"type": "NS"
},
{
"kind": "dns#resourceRecordSet",
"name": "all4os.com.",
"rrdatas": [
"ns-cloud-e1.googledomains.com. dns-admin.google.com. 0 21600 3600 1209600 300"
],
"ttl": 21600,
"type": "SOA"
}
]

The NS record specifies four authoritative name server that you will need when you update your domain's name servers to use Google Cloud DNS

The SOA record specifies the base DNS information about the domain:

  • the primary name server is ns-cloud-e1.googledomains.com
  • the domain administrator's contact e-mail is dns-admin@google.com, in SOA, it replace @ into a dot.
  • the initial serial number (which has to be incremented with every DNS update) is 0
  • the refresh time that secondary DNS servers wait before querying the primary DNS server's SOA record to check for changes is 21600 seconds
  • retry interval that a secondary server waits before retrying a failed zone transfer is 3600 seconds
  • the expire time that a secondary server will keep trying to complete a zone transfer is 1209600 seconds
  • the default minimum time to live is 300 seconds (used for negative caching, meaning that all the queries that don’t have a valid response are cached for this amount of seconds)

Now lets edit the DNS record.

gcloud dns records --zone=all4os edit

Your default editor appears with an example of a change with both the additions and deletions sections displayed in JSON notation. You can edit it by entering your additions, deletions or both.
Additions is for new record, deletions is for deleting old record. If you want to change a record, make sure you delete the old record, otherwise it will shows error. After you done your editing, save and close your editor and all changes will be updated to the cloud DNS.

{
"additions": [
{
"kind": "dns#resourceRecordSet",
"name": "all4os.com.",
"rrdatas": [
"ns-cloud-e1.googledomains.com. dns-admin.google.com. 1 21600 3600 1209600 300"
],
"ttl": 21600,
"type": "SOA"
}
],
"deletions": [
{
"kind": "dns#resourceRecordSet",
"name": "all4os.com.",
"rrdatas": [
"ns-cloud-e1.googledomains.com. dns-admin.google.com. 0 21600 3600 1209600 300"
],
"ttl": 21600,
"type": "SOA"
}
]
}

The gcloud tool automatically incremented the serial counter of the SOA record, so the SOA records always shows in both additions and deletions.

Google Cloud DNS supported record types:
https://developers.google.com/cloud-dns/what-is-cloud-dns#supported_record_types

You can add all records in one batch. Here is the example of a adding records to Google Cloud DNS:

{
    "additions": [
        {  
        "kind": "dns#resourceRecordSet",
        "name": "all4os.com.",
        "rrdatas": [
            "38.109.218.151"
        ],
        "ttl": 86400,
        "type": "A"
    },
    {
        "kind": "dns#resourceRecordSet",
        "name": "all4os.com.",
        "rrdatas": [
            "2605:6f00:877::3b9e:9265"
        ],
        "ttl": 86400,
        "type": "AAAA"
    },
    {
        "kind": "dns#resourceRecordSet",
        "name": "all4os.com.",
        "rrdatas": [
            "10 aspmx.l.google.com.",
            "20 alt1.aspmx.l.google.com.",
            "20 alt2.aspmx.l.google.com.",
            "30 alt3.aspmx.l.google.com.",
            "30 alt4.aspmx.l.google.com."
        ],
        "ttl": 3600,
        "type": "MX"
    },
    {
        "kind": "dns#resourceRecordSet",
        "name": "all4os.com.",
        "rrdatas": [
            "ns-cloud-e1.googledomains.com.",
            "ns-cloud-e2.googledomains.com.",
            "ns-cloud-e3.googledomains.com.",
            "ns-cloud-e4.googledomains.com."
        ],
        "ttl": 21600,
        "type": "NS"
    },
    {
        "kind": "dns#resourceRecordSet",
        "name": "all4os.com.",
        "rrdatas": [
            "ns-cloud-e1.googledomains.com. admin.all4os.com. 1 21600 3600 1209600 300"
        ],
        "ttl": 21600,
        "type": "SOA"
    },
    {
        "kind": "dns#resourceRecordSet",
        "name": "all4os.com.",
        "rrdatas": [
            "\"v=spf1 include:_spf.google.com ~all\""
        ],
        "ttl": 21600,
        "type": "SPF"
    },
    {
        "kind": "dns#resourceRecordSet",
        "name": "all4os.com.",
        "rrdatas": [
            "\"v=spf1 include:_spf.google.com ~all\""
        ],
        "ttl": 21600,
        "type": "TXT"
    },
    {
        "kind": "dns#resourceRecordSet",
        "name": "gmail._domainkey.all4os.com.",
        "rrdatas": [
            "\"v=DKIM1; k=rsa; p=all4os\""
        ],
        "ttl": 86400,
        "type": "TXT"
    },
    {
        "kind": "dns#resourceRecordSet",
        "name": "www.all4os.com.",
        "rrdatas": [
            "38.109.218.151"
        ],
        "ttl": 86400,
        "type": "A"
    },
    {
        "kind": "dns#resourceRecordSet",
        "name": "www.all4os.com.",
        "rrdatas": [
            "2605:6f00:877::3b9e:9265"
        ],
        "ttl": 86400,
        "type": "AAAA"
    }
]
 
    "deletions": [
        {   
            "kind": "dns#resourceRecordSet",
            "name": "all4os.com.",
            "rrdatas": [
                "ns-cloud-e1.googledomains.com. dns-admin.google.com. 0 21600 3600 1209600 300"
            ],  
            "ttl": 21600,
            "type": "SOA"
        }   
    ]   
}

Note: we always use the same command to add or remove DNS record. However, your record will not show in your editor when you re-run the command again.

To list the records from your zone:

gcloud dns records --zone="all4os" list

You probably notice that the Shell only show part of the dns records and we are unable to scroll the window to see more information. Google Cloud SDK Shell for Windows in default limits 40 lines in a screen and the it is not scrollable. We need to change to mode to make the shell be able show more lines. If your display isn't large enough to show all lines, you can still have a shell box that can have much more virtual lines, so that you can scroll up to view the results of a long operation.

mode 120,500

Now re-run the the list command you will be able to see up to 500 lines.

gcloud dns records --zone="all4os" list

5. Update domain name servers

After you edited the DNS record, you are almost done. The last thing you need to do is point your domain's DNS to Google Cloud DNS.

To determine the Cloud DNS name server associated with the zone, use the following command:

gcloud dns managed-zone get all4os
"nameServers": [
"ns-cloud-e1.googledomains.com.",
"ns-cloud-e2.googledomains.com.",
"ns-cloud-e3.googledomains.com.",
"ns-cloud-e4.googledomains.com."
]
}

Change your domain registrar's name servers for your domain, replace the name servers in the registrar’s NS records with the four name servers we looked up in the previous step (without the trailing dot).

You're all set. It can take up to 24-48 hours for the new nameservers to become fully active.

Other useful Google Cloud DNS commands: https://developers.google.com/cloud-dns/gcloud-dns-command

Leave a Reply

Your email address will not be published. Required fields are marked *

 

Your browser is out-of-date. Upgrade your browser today! Internet Explorer | FireFox | Chrome

X