DynamicDNS setup

I registered a couple of domains with DynDNS which point to a host on my home network. My ISP gives me dynamic IP addresses that my Netgear RT-314 uses and also handles firewall/NAT duties. I needed a way of determining my public IP address and using it to update the name servers at DynDNS.

This problem has been well solved by, among other packages, ddclient.

It almost did what I wanted, and the nicest thing about OpenSource is that it is so easy to go from 'almost' to 'exactly'! I wanted to cut down my network traffic - after all most of the time the IP address doesn't change so why leave my network to figure out what the current public IP is? I figured the best way to do this was to login to the RT-314 and get the public IP address off the status page.

I didn't need to change ddclient to support this - I could just invoke it with '-ip w.x.y.z' and it would work fine. The trick was getting the IP address out of the RT-314.

I have disabled management of the RT-314 over the network - I have to connect to it via a console line. That meant I'd have to drive a terminal program and automate the interaction with the management interface. I've played with Expect before and figured that would be the way to go on this. You can get the script I came up with here.

I downloaded the ddclient, installed it and configured it.

The only changes I had to make to the conf file were:
fw-password=XXXXXX # FW login and password
login=my_user_name> # default login
password=my_password # default password
server=members.dyndns.org, \
protocol=dyndns2 \

I changed the code a bit too. The default behaviour is to email you after each invocation. If I get an email every 10min saying that nothing happened - well, that get's old fast. I changed one line to have it only email me when it didn't work.
root@ioslave:/home/jardine/Source/ddclient-3.7.3# diff ddclient /usr/sbin/ddclient
< sendmail();
> sendmail() if $result;

The last step is to automate it all. If ddclient was getting the IP address itself then I'd just run ddclient in daemon mode and it's job done. I'm getting the IP address myself though - that means that I need to run the expect script and then follow it up by invoking ddclient. I setup two cronjobs as root, the first runs every 10 minutes and the second runs twice a month but forces an update. Here's the crontab entries:
# Check IP address every 10 minutes. Drives DynDNS updates
6,16,26,36,46,56 * * * * /etc/ddclient/updatedyndns.bash >>/tmp/updatedyndns.stdout 2>>/tmp/updatedyndns.stderr
14 18 3,23 * * /etc/ddclient/forceupdatedyndns.bash >>/tmp/updatedyndns.stdout 2>>/tmp/updatedyndns.stderr