Linux notes
>
Home|Notes|Linux|Using ddclient
Using ddclient to keep your static IP address up-to-date
If, as many do, you want to access your home network from 'outside' (i.e, when you are travelling or otherwise not 'on' your local network), or you wish to run some sort of server that others can easily access, you naturally want to associate a domain name with the IP address associated with you by your service provider. You can use services such as those provided by DynDNS for this; they will let you choose a memorable domain name (say, mygreatsite.dyndns.org) and map that to your current IP address.
This works well if the IP address given to your internet connection by your ISP never changes. Unfortunately, most will change at some time or another, and some change so often that keeping track of them is next to impossible. Naturally, as soon as this change occurs, the convenient link between the domain name (mygreatsite.dyndns.org in our example) and your actual IP address of the moment is broken. Not so convenient!
To solve this problem, we'd like to find some sort of program that would detect any changes in your current IP address and automatically update the DynDNS record (or the equivalent, if not using their service). Fortunately there exists exactly this, in the form of ddclient - a Perl client that handles the address checking and updating automatically.
Installing and using ddclient
Using apt-get
If you are using apt-get, installation is trivial:
apt-get install ddclient
During the installation process, you will be asked for some details of your network and your DynDNS (or whatever) account. These are:
- The dynamic DNS service you are using (i.e. DynDNS or someone else),
- The domain name you have chosen from them (i.e. mygreatsite.dyndns.org),
- The ethernet adapter you are using for your external connection (i.e. the one on which you want ddclient to monitor for IP address changes, normally eth0 or eth1),
- How frequently ddclient is to check for a changed IP address on the above network adapter (in seconds, minutes or whatever),
- Your DynDNS username and password (if using DynDNS, obviously).
Finally, you'll be asked if you want to run ddclient as a service at startup. You should answer yes.
Manual install
If you want the latest version, which has many more nice features than the current release in Debian Sarge (stable), follow the procedure below.
- Download the latest .tar.gz file from Sourceforge,
- Unpack it with tar zxvf ddclient-3.7.0.tar.gz. This will put everything in a new subdirectory, ddclient-3.7.0. Move to this new directory,
- cp ddclient /usr/sbin/
- mkdir /etc/ddclient
- cp sample-etc_ddclient.conf /etc/ddclient/ddclient.conf
- vi /etc/ddclient/ddclient.conf, and change hostnames, logins, and passwords appropriately
- Configure the script to run at startup by issuing the following commands:
- cp sample-etc_rc.d_init.d_ddclient /etc/init.d/ddclient
- update-rc.d ddclient defaults
- /etc/init.d/ddclient start
ddclient creates a configuration file in /etc/ddclient.conf. You can edit this file if you need to change any of the configuration details. If you are using a program such as monit to keep an eye on your machine, you'll find the process identifier (.pid) file at /var/run/ddclient.pid.
Usage
ddclient will run at startup and monitor the IP address of your network adapter at the interval you specified in your setup. If the IP address changes, it will contact DynDNS or other DNS provider and automatically update the record to keep your domain name pointing to your new IP address. You don't have to take any action to allow this to happen.
Helpfully, ddclient sends an email to the default user on the machine on which it is installed, whenever it performs an update or encounters a problem. Typical messages report a successful update or a problem (for example, it was unable to contact the DynDNS site for some reason).
All in all, ddclient is a very useful program that solves a tricky problem. I use it on both my firewall machines.