Dynamic DNS HOWTO

Mr. Walter Phillips


Table of Contents
1. Introduction
1.1. Motivation
1.2. What is Dynamic DNS?
1.3. Free third level domain names
2. The simple setup
3. Tips and Tricks
3.1. Finding the public address through a NAT
3.2. Checking for a changed address
4. Conclusion

1. Introduction


1.1. Motivation

Although there are many methods to set up dynamic DNS, and many work well, none have been satisfactory for my purposes. For this reason, I am setting up this guide, which gives a step-by-step explaination of how to create exactly the results that I have for dynamic DNS.


1.2. What is Dynamic DNS?

NoteFrom the DNS Howto:
 

DNS is the Domain Name System. DNS converts machine names to the IP addresses that all machines on the net have. It translates (or "maps" as the jargon would have it) from name to address and from address to name, and some other things.

A mapping is simply an association between two things, in this case a machine name, like ftp.linux.org, and the machine's IP number (or address) 199.249.150.4. DNS also contains mappings the other way, from the IP number to the machine name; this is called a "reverse mapping".

A dynamic DNS, or more accurately, a dynamic DNS entry, is one such mapping, except that the IP number changes frequently, and must be constantly updated on some DNS server. For example, consider that you have a machine that you use with dialup, and you want to be able to log in remotely to, say, your.machine.com no matter what the address is. Your computer will have to change the DNS entry on someone else's server every single time it goes online in order for this to work.


1.3. Free third level domain names

Third level domain names are names with three parts, such as ftp.linux.org - as opposed to, for example, linux.org. Unlike second level domains, these are not handed out by a government board (for a price), but rather by whoever owns the second level domain. The practical result of this is that there are many different second-level domain owners who hand out free third level domains and also ways to administrate them (such as updating whenever the IP address changes). They do this partially to be nice, but partially because doing so is a cheap source of word-of-mouth advertisement. This HOWTO covers a specific set of these that are useable with the program ez-ipupdate, as well as all domains covered by whyi.org.


2. The simple setup

If you only want to use a single DNS entry, or aren't picky, ez-ipupdate can be simply run in daemon mode and keep track of your IP address by itself. To have it run continuously, you'd simply add a line to /etc/inittab (or use daemontools).

Example 1. A line from /etc/inittab

Z5:345:respawn:/usr/bin/ez-ipupdate -d -S dyndns -u username:password -i eth0


3. Tips and Tricks


3.1. Finding the public address through a NAT

If you're behind a router doing Network Address Translation, you may have a private IP address, which is therefore not accessable to anyone else. You'll have to do port forwarding (from the router) to ge to any of your services, and more importantly, you need a way to find your ip-address.

The easiest way I could think to do this is to go to a site that reports it. The one I chose is hn.org. Using a combination of wget, grep, and tr, three widely available (and if you don't have them you should get them) pieces of *nix software, we can store the address to a variable:

Example 2. Putting an IP-address into a variable

ipaddress=`wget http://myip.hn.org/ip.cgi/ -O /dev/stdout | grep -i 'PADDR=' | tr -c '.[:digit:]' '\n'| grep -e '[0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*'`
ez-ipupdate -S hn -u username:password -i eth0 -a $ipaddress
/usr/local/bin/skeleton_client.pl --set user='email@bob.org' --set pass='thepassword' --nosave "a(tld.yi.org)=$ipaddress"
echo $ipaddress > /etc/ipaddress


3.2. Checking for a changed address

Here's a script that does just that, and if the address changes, it runs the first script. It assumes that the script is in /etc/cron.monthly/ezscript.watcher. Obviously, if this is not the case, you'll have to slightly modify it.

Example 3. Change detection script


#!/bin/bash
ipaddress=`wget http://myip.hn.org/ip.cgi/ -O /dev/stdout | grep -i '<!--IPADDR=' | tr -c '.[:digit:]' '\n'| grep -e '[0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*'`

if [ $ipaddress != `cat /etc/ipaddress` ]
then
/etc/cron.monthly/ezscript #THIS IS THE SPOT YOU MIGHT HAVE TO CHANGE.
fi

I put this in /etc/cron.hourly, so that any changes will be detected every hour.


4. Conclusion

That should be everything you need. If you have noticed any errors or omissions (besides omitting any particular other method of going about this, please Send me an email. This HOWTO is being actively maintained.