Of all the things to outsource, mail and DNS should be first. :)
I’m going to migrate my serverascode.com domain DNS from an old hosting company to Google Cloud DNS. Finally.
I also have some DNS hosting done with AWS Route 53, but I am trying to learn more about gcloud. Also, I think hosting DNS at Google is slightly cheaper, in that each “zone” is $0.20/month vs $0.50/month at AWS. Each charges $0.40 for some huge number of DNS requests.
One thing I find that is a problem with gcloud is that there is very little documentation outside of gclouds official docs. I am not really a fan of any of the official docs, be it for AWS or gcloud…they always read like autogenerated API docs. Also I find gclouds look, feel, and organization to be difficult to grasp.
I’m only going to use the gcloud command line.
First, setup a new project. I’m not sure if the best way to use gcloud is to setup multiple projects, but I’m going to setup a DNS hosting project.
NOTE: Replace “some-uuid” with some kind of random string. Projects need to have a unique name.
$ gcloud projects create dns-hosting-<some-uuid> --name "DNS Hosting"
List your billing accounts. This assumes you have setup at least one account for billing.
$ gcloud alpha billing accounts list ID NAME OPEN <billing account ID> My Billing Account
Switch to the DNS project.
$ gcloud config set project dns-hosting-<some-uuid> Updated property [core/project].
Assign a billing account to the DNS project.
$ gcloud alpha billing accounts projects link dns-hosting-<some-uuid> --account-id=<billing account ID>
Now the project can be billed.
Enable the DNS API on this project.
$ gcloud services enable dns.googleapis.com
DNS should be in the list of available services for this project.
$ gcloud services list NAME TITLE bigquery-json.googleapis.com BigQuery API cloudtrace.googleapis.com Stackdriver Trace API servicemanagement.googleapis.com Google Service Management API monitoring.googleapis.com Stackdriver Monitoring API storage-api.googleapis.com Google Cloud Storage JSON API dns.googleapis.com Google Cloud DNS API logging.googleapis.com Stackdriver Logging API clouddebugger.googleapis.com Stackdriver Debugger API datastore.googleapis.com Google Cloud Datastore API sql-component.googleapis.com Google Cloud SQL cloudapis.googleapis.com Google Cloud APIs storage-component.googleapis.com Google Cloud Storage
Now for the actual DNS setup.
Now that the project is created and has a billing account we can setup the DNS zone.
$ gcloud dns managed-zones create --dns-name="serverascode.com." --description="serverascode"
$ gcloud dns managed-zones list NAME DNS_NAME DESCRIPTION serverascode serverascode.com. serverascode
The process is:
Start a DNS zone editing transaction.
$ gcloud dns record-sets transaction start --zone=serverascode
transaction.yaml file will be created where ever you run this command. Further commands will edit this file, and then finally we will execute this file to push the changes up to gcloud.
Add an A record. In this example I am pointing
serverascode.com to Github’s page servers.
$ gcloud dns record-sets transaction add --zone=serverascode --name="serverascode.com" --ttl 3600 --type A 126.96.36.199 188.8.131.52
Add a CNAME for www.
$ gcloud dns record-sets transaction add -z=serverascode --type=CNAME --name="www.serverascode.com" --ttl 3600 "serverascode.com."
If you host your mail somewhere for this domain, add MX records. Here I enter two mail hosts.
gcloud dns record-sets transaction add --zone=serverascode --name="serverascode.com" --ttl 3600 --type MX "10 mail1.somemailhost.com." "20 mail2.somemailhost.com."
Finally execute those changes.
$ gcloud dns record-sets transaction execute --zone serverascode
And once they have been pushed we can list them.
$ gcloud dns record-sets list --zone=serverascode NAME TYPE TTL DATA serverascode.com. A 3600 184.108.40.206,220.127.116.11 serverascode.com. MX 3600 10 mail1.somemailhost.com.,20 mail2.somemailhost.com. serverascode.com. NS 21600 ns-cloud-d1.googledomains.com.,ns-cloud-d2.googledomains.com.,ns-cloud-d3.googledomains.com.,ns-cloud-d4.googledomains.com. serverascode.com. SOA 21600 ns-cloud-d1.googledomains.com. cloud-dns-hostmaster.google.com. 6 21600 3600 259200 300 www.serverascode.com. CNAME 3600 serverascode.com.
If that looks good then go to your registar and change the nameservers to Google’s, which is what I did.
If you are reading this post then it must have worked!