In this blog, I’m going to talk you through getting started with using the K5 DNS as a Service. This service provides an environment for running zone management and record management operations via the API, without the need to build and manage your own DNS server.
To get started, you need to own and have registered your own public Domain Name. For the purpose of this blog, I have registered the domain ianpurvis.co.uk with uk.godaddy.com.
Managing DNS Zones
The first thing you need to do is create a new DNS zone within your project using the API. To start, open up your K5 API environment and obtain your authentication token. Next, run the following command to list any/all existing zones for your project:
If this is the first time you have configured DNS, you should see the following information, indicating no zones are present:
Use the following command to create a DNS Zone, substituting “ianpurvis.co.uk” for your registered DNS name:
If successful, the output of this command will include an ‘Unauthorized’ error and a confirmation code, that you must use to verify/prove that you are the domain owner. There are two methods for doing this, the first if your domain is not yet managed by any DNS yet, and second if it is managed by DNS. As my domain “ianpurvis.co.uk” is currently managed by Godaddy, I will use the second method.
This second method requires that you create a DNS TXT record within your existing DNS , so in my case Godaddy. The value of this text record is of the form: nifty-dns-verify=.
The below screen shot shows how this record is created within Godaddy:
Once done, running the Create DNS Zone command again should result in output as shown below. For troubleshooting, you can verify what TXT records are being returned from your domain using an online tool such as https://mxtoolbox.com/TXTLookup.aspx or”NSLookup.exe -q=TXT ianpurvis.co.uk”
Now the DNS zone is verified, you can update the Nameservers for your existing managed Domain, to point to the K5 Name Servers shown above. The below screenshot shows how this is done within Godaddy, by choosing ‘custom’, entering the nameservers and clicking ‘save’ (note this may take up to an hour or two to complete):
For information, the registered DNS zone can be deleted with the following command (substituting “ianpurvis.co.uk” with your own domain name)
Now that the DNS Zone is configured, DNS records can be added to it. To list any existing DNS records, enter the following command (substituting “ianpurvis.co.uk” for your domain):
The following output is displayed for an empty DNS Zone:
To help get you started, the following example shows you how to add basic A, TXT, CNAME and MX records. Remember to substitute your domain for “ianpurvis.co.uk”. I’ll cover more advanced features like Latency-based routing and failover in subsequent blogs.
- To add an A record, use the following command :
In the above example, I am setting the A record to http://www.ianpurvis.co.uk to refer to the public IP Address of my webserver on 18.104.22.168
- To add a TXT record, use the following command:
- To add a CNAME record, use the following command:
- To add a MX record, use the following command:
To delete a particular record, resubmit the same command only this time change the Action to Delete:
The entire DNZ zone can be deleted with the following command:
curl -X DELETE $DNS/v1.0/hostedzone/<DOMAIN NAME> -H “X-Auth-Token:$OS_AUTH_TOKEN” -H “Content-Type:application/xml” | xmllint –format –