Google Cloud DNS

Google Cloud DNS is one of products of Google Cloud Platform (it's placed under Network products) that allows you to manage DNS records for your domain. Just to explain briefly, DNS stands for Domain Name System. To take excerpt from  Wikipedia, article starts with "DNS is a hierarchical  decentralized naming system for computers, services, or an resource connected to the Internet or a private network. In more simpler words, when you type url of some website in browser, computer knows to which IP address of the server it needs to connect in order to obtain data for the website. Good example is phonebook. Except for the name of the person you have webdomain or webpage and for phone number stands for IP address of the server. So every time you go to see some webpage, DNS server looks IP address of the server which is connected to the domain of that webpage.

There are different DNS records with which we can manage domain. Each record has it's purpose, some type of DNS records are:

  • A - IPv4 address, maps IP of host with domain
  • CNAME - alias for one name to another, for example www.example.com  points to example.com
  • MX - manages where emails should be delivered
  • TXT - whatever text, for example, Google use it to verify that you own domain

There are many more. Important thing to emphasize is that, to lower load of DNS servers, DNS records are cached for certain time (which you can set with TTL parameter), so when some change is done, it can take some time to reflect.

Now, thruth is that you can manage your DNS records within your domain registrar account. It's also possible to have your own server and use it as DNS for your domain. So why would you use Google Cloud to manage DNS records for your domain?

  • It's managed by Google, i.e. it runs on it's infrastructure so that means it's fast, reliable, secure
  • You have everything in one place for your project
  • It's in the same network as your servers (either Google App Engine or Google Compute Engine) so requests have smaller latency
  • Possibility to manage DNS records through:
    • Cloud Console
    • REST API
    • gcloud (command line interface)
  • Price - 0.2$/month for one zone + extra $$$ based on how many queries

Basically, if you have simple website, you don't have to necessarily use Google Cloud DNS, but if you have complex project that involves multiple domains, subdomains, it can be handy.

I recorded demo in which I did basic operations through Cloud Console

 

Here is step by step how to do similar things through gcloud command. What I'm gonna do (similar as in Youtube video):

  • I have domain mytestdomain.net and 2 web applications on Google Compute Engine.
  • I will connect Wordpress app to mytestdomain.net
  • I will add CNAME record so it alias www.mytestdomain.net to mytestdomain.net
  • I will create subdomain crm and connect second app SuiteCRM

Full reference for gcloud commands are here https://cloud.google.com/sdk/gcloud/reference/dns/

lets start with basic command and that is current DNS settings for project:

all commands regarding DNS have format:

gcloud dns

To list zones (domains) in project:

zdenulo@linux:~> gcloud dns managed-zones list
Listed 0 items.

It displays zero zones since I didn't create any, lets do that:

zdenulo@linux:~> gcloud dns managed-zones create mytestdomain --description "Testing managing DNS records" --dns-name mytestdomain.net
Created [https://www.googleapis.com/dns/v1/projects/adventures-on-gcp/managedZones/mytestdomain].
NAME          DNS_NAME           DESCRIPTION
mytestdomain  mytestdomain.net.  Testing managing DNS records

when I again list zones, I see newly created:

zdenulo@linux:~> gcloud dns managed-zones list
NAME          DNS_NAME           DESCRIPTION
mytestdomain  mytestdomain.net.  Testing managing DNS records

one possibility is to use YAML file where are described actions to do like add or remove records. another way is to do operations one by one in command and then push changes. I'll do second way, here is list of commands which I executed in shell:

zdenulo@linux:~> gcloud dns record-sets transaction start --zone mytestdomain
Transaction started [transaction.yaml].
zdenulo@linux:~> gcloud dns record-sets transaction add --zone mytestdomain --name mytestdomain.net --type A "104.154.92.142" --ttl 10 Record addition appended to transaction at [transaction.yaml].
zdenulo@linux:~> gcloud dns record-sets transaction add --zone mytestdomain --name crm.mytestdomain.net --type A "104.197.69.8" --ttl 10 Record addition appended to transaction at [transaction.yaml].
zdenulo@linux:~> gcloud dns record-sets transaction add --zone mytestdomain --name www.mytestdomain.net --type CNAME mytestdomain.net --ttl 10 Record addition appended to transaction at [transaction.yaml].
zdenulo@linux:~> gcloud dns record-sets transaction execute --zone mytestdomain Executed transaction [transaction.yaml] for managed-zone [mytestdomain]. Created [https://www.googleapis.com/dns/v1/projects/adventures-on-gcp/managedZones/mytestdomain/changes/1]. ID START_TIME STATUS 1 2016-09-03T22:27:51.675Z pending

We start by starting transaction. What happens is that file transaction.yaml is created and there all actions are added. Until we execute transcation nothing really happens in the project with records. 

As you can see mandatory parameters in command are:

  • zone - zone name
  • name - DNS name of record which will be added
  • type - type of record (A, CNAME etc)
  • ttl - time to live for record

When we look before executing transaction file, it looks like this:

---
additions:
- kind: dns#resourceRecordSet
  name: mytestdomain.net.
  rrdatas:
  - ns-cloud-d1.googledomains.com. cloud-dns-hostmaster.google.com. 3 21600 3600 259200
    300
  ttl: 21600
  type: SOA
- kind: dns#resourceRecordSet
  name: mytestdomain.net.
  rrdatas:
  - 104.154.92.142
  ttl: 10
  type: A
- kind: dns#resourceRecordSet
  name: crm.mytestdomain.net.
  rrdatas:
  - 104.197.69.8
  ttl: 10
  type: A
- kind: dns#resourceRecordSet
  name: www.mytestdomain.net.
  rrdatas:
  - mytestdomain.net
  ttl: 10
  type: CNAME
deletions:
- kind: dns#resourceRecordSet
  name: mytestdomain.net.
  rrdatas:
  - ns-cloud-d1.googledomains.com. cloud-dns-hostmaster.google.com. 2 21600 3600 259200
    300
  ttl: 21600
  type: SOA

When you execute transaction, file is deleted and we can see update in Cloud Console under Network -> Cloud DNS

To list records with gcloud, we use command:

zdenulo@linux:~> gcloud dns record-sets list --zone mytestdomain
NAME                   TYPE   TTL    DATA
mytestdomain.net.      A      10     104.154.92.142
mytestdomain.net.      NS     21600  ns-cloud-d1.googledomains.com.,ns-cloud-d2.googledomains.com.,ns-cloud-d3.googledomains.com.,ns-cloud-d4.googledomains.com.
mytestdomain.net.      SOA    21600  ns-cloud-d1.googledomains.com. cloud-dns-hostmaster.google.com. 2 21600 3600 259200 300
crm.mytestdomain.net.  A      10     104.197.69.8
www.mytestdomain.net.  CNAME  10     mytestdomain.net.

 

 

blog comments powered by Disqus