Many people are familiar with dynamic DNS services like DynDNS and No-IP. One that I sometimes use, which is perhaps not so widely known for its capabilities for dynamic DNS, is provided by ZoneEdit.
If you use ZoneEdit to manage and host your DNS records, and want to automatically update one or more host records when your dynamic IP changes, here’s a simple command-line method to do so using tools that are built in to every unix-based operating system, including Mac OS X and Linux.
First, a quick overview of dynamic DNS: services like DynDNS and No-IP are DNS providers that publish hostname records, and also provide a tool to enable “dynamic” updating of IP addresses for those hostnames when your public IP address changes. Many people use a hostname on one of the provider’s domains, like “yourname.dyndns.org”.
If you have registered your own domain name, and maintain your own DNS records for that domain using ZoneEdit, you can achieve the same thing for hostnames on your own domain, like “yourname.yourdomain.com”.
First you’ll need an account at ZoneEdit, and your domain will need to be configured to use their DNS servers. I’m assuming you already have this, or you wouldn’t need to know how this works…
Then, create a host record for the hostname you want to use, something like “yourname.yourdomain.com”. Create an A record and give it an invalid public IP address, like 10.2.3.4. Save and publish your changes.
Next, make sure you have
curl installed. To test your IP update for the DNS record, we’re going to use
curl to get your public IP address from ifconfig.me. From a terminal window or prompt on your computer, run the following command:
You should get back your current connection’s public IP address. If you get an error or a warning that
curl is not installed, go take care of that, then come back here and continue once it is working.
Now that you have the requisite tools, you need just a few bits of information to continue:
- your ZoneEdit username and password
- the hostname whose IP value you want to update
- the command to update the record
You bring the first two, and I’ll show you how to use the command.
ZoneEdit enables updating the IP address for an A record on your account by calling a web address with the correct authentication and parameters. I chose to use
curl to handle this task, as it is installed by default on Mac OS X and common Linux distributions. You could also use
wget if that’s more your style.
The update address is “https://dynamic.zoneedit.com/auth/update.html”.
host parameter is required to update a specific hostname, so you’ll use
host=yourname.yourdomain.com for this. Your ZoneEdit username and password are required to authorize the update request, which you can instruct
curl to pass with the https request.
For this example, I’ll use “yourname.yourdomain.com” as the A record to update, “zeuser” as your ZoneEdit username, and “zepass” as your ZoneEdit password. Putting it all together, here’s what the command looks like:
curl -u zeuser:zepass https://dynamic.zoneedit.com/auth/update.html?host=yourname.yourdomain.com
The command above will cause ZoneEdit to update the A record for the specified hostname to the public IP of your current connection. If you are doing this from elsewhere, or need to specify a different IP address, add the
dnsto parameter to the end, like so:
curl -u zeuser:zepass http://dynamic.zoneedit.com/auth/update.html?host=yourname.yourdomain.com&dnsto=184.108.40.206
ZoneEdit should return a success code that looks something like this:
<SUCCESS CODE="200" TEXT="yourname.yourdomain.com updated to 220.127.116.11" ZONE="yourname.yourdomain.com">
After running the command successfully, you will want to verify the hostname’s A record was in fact updated. Log in to your ZoneEdit account, go to Manage Zones, click the zone (domain name) where your host is configured, and find the hostname in the list. Its IP address should now be updated with either your current public IP address (if you used the first command), or the address you specified (if you used the variant with the
There are a couple of additional things you may want to do to make this work seamlessly for you.
First, set the TTL (time-to-live) value for this A record to something very small, like 300 seconds (5 minutes). This should prevent long-term caching of this record on other DNS servers; you want them to look up the value again as soon as possible after you change it. In terms of DNS, 5 minutes is a pretty quick update.
Second, automate the updating. Use
cron (or your favorite scheduling tool) to run that command every few minutes. I have mine set to run every 12 minutes on my Mac so that the IP address for my hostname myhost.mydomain.com is never more than a few minutes out of date, no matter where I take my computer.
Note: while testing, ZoneEdit warned me that I should wait a minimum 600 seconds, or 10 minutes, between requests. That’s why I chose 12 minutes as my update interval.
For the automated command, I added
--silent, i.e. don’t output error messages) to the
curl command, and also redirected standard output to
/dev/null so the scheduled command executes quietly. Make sure you test the exact command syntax before adding your
My cron entry looks like this:
# 20130525 /TE.dm update ZoneEdit A record myhost.mydomain.com every 12 minutes */12 * * * * curl -s -u zeuser:zepass https://dynamic.zoneedit.com/auth/update.html?host=myhost.mydomain.com >/dev/null 2>&1
Verify the scheduled update works as expected. Change your IP to something invalid like 10.2.3.4, then wait for your cron job to run and verify the update succeeded. Mind the update frequency; you might need to wait a few minutes between updates while testing.
ZoneEdit provides stable, reliable, and robust DNS services. You can manage your DNS records here, and use ZoneEdit’s DNS servers for your domains. It’s a great service for those who really get DNS by a company that really gets DNS. ↩
wgetcommand worked for me: ↩
wget -O - --http-user=zeuser --http-passwd=zepass 'https://dynamic.zoneedit.com/auth/dynamic.html?host=yourname.yourdomain.com&dnsto=18.104.22.168'