This has nothing to do with search engine marketing, but everything to do with automation. If you’ve ever wanted to host a server at a location that doesn’t have a static IP address then you know just how much of a pain it can be.

Hopefully by the time you read this you’re familiar with what DNS is and what dynamic DNS is. If not, those links should catch you up to speed quick enough. I’ve tried a few different dynamic DNS providers but for the past few years I’ve been using freedns.afraid.org. I don’t host this site (of course), but I do host FTP and a few other services that allow me to get to my machines at home where ever I am.

I’m writing this post today because I just happened to have to update my scripts that keep my DNS up to date when my IP changes today.

Script Explanation

Really the script is simple but the first thing you have to do is sign up for an account at freedns.afraid.org and choose your domain name. Once you’ve done that, you’re ready to get yourself setup with this script.

Save the script above as dns.sh.

Make sure that the script is set as executable. You can run sudo chmod +x dns.sh to make sure it is.

You now need to get your API key. To do that, go to http://freedns.afraid.org/api/ and it will explain what you need to do. Basically, you need to hash your username and password, but you can find it on that page if you don’t want to hash it yourself.

In the script, replace the string <paste_your_password_hash_here> with the actual hash (don’t forget to save…).

Now you can run the script when ever your IP address updates. Alternatively (my way), you can setup the script as a cron job and have the script check at regular intervals to make sure everything is up to date.

Setting up the Script as a Cron Job

Open a terminal and run crontab -e. If you’ve never done this before, it will probably prompt you to choose an editor. If you don’t know how to use any of the command line editors then you’ll need to do some additional Googleing, I’m not going to explain it. Although, I prefer nano because I don’t understand vi or vim.

Once you have your crontab open, paste the following line somewhere to run the script every 5 minutes.

*/5 * * * * /path/to/script/dns.sh

From now on your DNS information should be up to date. You may have noticed that I’m scraping Google to get your actual current IP address. That was the change I made to the script today. I used to use another site (commented out) but apparently the focus of the site has changed and they don’t really like scripts using it to get the current IP address. What a shame.