Build a Dynamic DNS Client with Rackspace API
How to Build a Dynamic DNS via API
This time I’ve want to create a homemade Server with my Raspberry Pi2 and publish it using my own sub-domain, the main problem is that the ISP provide me an dynamic IP and we should ensure that if my IP address change the sub-domain record should point to the new IP.
The instructions assume that you:
Have a domain
Have already changed your NS records to point to dns1.stabletransit.com and dns2.stabletransit.com.
You should download the latest version of rsdns from github
cd ~/bin/ git clone https://github.com/linickx/rsdns.git
Go to your Rackspace portal https://login.rackspace.com/ and grab your Username & API key (It’s under “Your Account” -> “Account Settings” -> “API Key”)
Create a configuration file for rsdns (~/.rsdns_config) with your settings.
#!/bin/bash RSUSER=lcacho RSAPIKEY=1234567890 RSPATH=~/bin/rsdns/
You need your domain created on Rackspace(It’s under “Networking” -> “Cloud DNS” -> “Create Domain”) if you don’t have your domain created you are able to created using rsdns:
./rsdns-domain.sh -d www.luiscachog.io -e [email protected]
Once you have a domain setup you need to create an A record. To create the A record you going to need an IP address, you can use http://icanhazip.com to get your actual current IP. Again to create a record you are able to do it from Rackspace panel (It’s under “Networking” -> “Cloud DNS” -> YOUR_DOMAIN -> “Add Record”) or you can use rsdns:
./rsdns-a.sh -n dynamic-host.luiscachog.io -i 126.96.36.199 -t 3600
In the above the TTL is set to 1hr (3600 secs), this is so that DNS caches do not keep the record too long. That’s all the pre-work done, now lets get your dynamic host setup!
The script to update your a record is rsdns-dc.sh, and you run it like this:
./rsdns-dc.sh -n dynamic-host.luiscachog.io
The script uses icanhazip to get your current IP, it then update the A record with it.
I never switch off my router so I have create a created a cronjob to run that script every 2 hours, plus the 1hr TTL should mean that the record is roughly in sync with my IP without making unnecessary requests
I use CentOS, so I can simply drop the following file called rsdns-dc into /etc/cron.d/ with this…
vim /etc/cron.d/rsdns-dc * */2 * * * lcacho /home/lcacho/bin/rsdns/rsdns-dc.sh -n dynamic-host.luiscachog.io &>/dev/null
Now we are done! Private Dynamic DNS on your own zone using the Rackspace API.