KEEP DYNDNS.ORG ENTRIES UPDATED

DynDNS.org offers a free dynamic DNS service, and a number of clients exist for Windows, Linux, and Mac OS X. One of the more stable Linux clients is ez-ipupdate, a great tool that takes the IP address of your system and sends the data to DynDNS.org to update the DNS record for your particular host name (as chosen when you sign up).

Unfortunately, ez-ipupdate falls short when you're executing it from a host that doesn't have the IP address you wish to set. For example, let's say you have a LAN behind an external firewall appliance and want to set your DynDNS.org host name to the IP address held by the firewall.

Because most firewalls use network address translation (NAT), you can work around this if you have a Web site where you can put a simple PHP script. Place the following PHP script on a remote server, outside of the LAN; we'll call it getaddress.php.

<?php print($_SERVER['REMOTE_ADDR'] . "\n"); ?>

On your internal Linux machine, create a script that you'll run hourly via cron. This script should contain the following:

#!/bin/sh

config="/etc/ez-ipupdate.conf"
current_ip=`curl -sf http://externalhost/getaddress.php`
if [ "x$?" != "x0" ]; then
exit $?
fi

old_ip=`grep address $config|sed s/address\=//g`

if [ "$current_ip" != "$old_ip" ]; then
perl -pi -e "s/$old_ip/$current_ip/g" $config
/etc/ez-ipupdate
fi

This script executes /etc/ez-ipupdate, which is the configuration file and the runtime script for ez-ipupdate if the IP address returned by the PHP script differs from the address currently in the /etc/ez-ipupdate config file. Running this every hour will update your DynDNS.org entry if your dynamic IP address changes.