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.

1
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.

1
gcloud components update dns

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

1
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.

1
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.

1
gcloud config set project  qualityology

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

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

You will see:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Creating {'dnsName': 'qualityology.com.', 'name': 'qualityology', 'description':
'qualityology.com zone'} in google-dns

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

{
"creationTime": "2014-07-24T07:15:31.276Z",
"description": "qualityology.com zone",
"dnsName": "qualityology.com.",
"id": "5988761527897559933",
"kind": "dns#managedZone",
"name": "qualityology",
"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.

1
gcloud dns records --zone=qualityology list

You will see:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[
{
"kind": "dns#resourceRecordSet",
"name": "qualityology.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": "qualityology.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.

1
gcloud dns records --zone=qualityology 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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
"additions": [
{
"kind": "dns#resourceRecordSet",
"name": "qualityology.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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
{
"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:

1
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.

1
mode 120,500

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

1
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:

1
gcloud dns managed-zone get all4os
1
2
3
4
5
6
7
"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

Rotate Apache logs on a daily basis using rotatelogs Installing EPEL and REMI repository on CentOS 5.x, 6.x, or 7.x

Comments