If you need remote access to a computer whose IP changes dynamically, ddclient may be the tool for you. Check out this previous article for how to set up ddclient using a free service like DynDNS. Once set up, you will be able to connect to your box using a pretty name like mybox123.dyndns.org, rather than having to keep track of the changing IP. I should mention that there are many other free DNS services besides dyndns.com, and that many home routers can take care of Dynamic DNS for you (i.e., you can set it up on the router, rather than on your computer).
Today, however, we have a more complicated task. This article will teach you how to:
- make ddclient update multiple host names
- make ddclient update the IP of multiple interface (e.g., your ethernet and your wireless lan)
- set up ddclient so that it updates correctly regardless of whether you are on a wired or wireless connection
- make ddclient use either your interface address (may be local, e.g. 192.168.1.15) or the address that is visible from the internet.
First, let me explain my use case. At home, I have a router that forwards SSH connections to my laptop, which is behind a NAT. Here, I want remote connections to use the router’s address (i.e., the web-visible address, not the address that my laptop’s interface gets). In the lab, I am also behind a NAT, but the NAT server is outside of my control, and I cannot set up forwarding. Here, I want connections from other lab machines (which are behind the same NAT) to use my laptop’s local interface address, rather than the web-visible address of the NAT server. At both locations, I get a dynamic IP, and I may use either a wired or a wireless connection.
This means that I need two domain names: (these are example names; don’t even think about it)
- mybox.dyndns.com, which gets updated with my web-visible address (i.e., the one I would see by going to checkip.dyndns.com), and
- myboxinternal.dyndns.com which gets updated with my local address (i.e., the one I would see if I ran
To make things more complicated, this needs to work regardless of whether I am using the ethernet or the wireless connection. After some googling, I was pleasantly surprised to find out that ddclient can do this. Here is my config file, with explanations following.
# updates internet ip on either wireless or wired
# updates interface (maybe local) ip on either wireless or wired
use=cmd, cmd=find-local-ip, \
I am using a little-known feature that allows ddclient to update multiple IPs / hosts. For mybox.homelinux.org, I
use=web, which means that ddclient will take my IP from checkip.dyndns.com. This works regardless of whether I am on the wired or wireless connection, which is exactly what I want. For myboxinternal.dyndns.org, I
use=cmd, cmd=find-local-ip, where
find-local-ip is a simple script that looks like this:
Ddclient will search the output of
ifconfig eth0; ifconfig wlan0 and select the first string that looks like an IP. This is necessary because with
use=if, you can only specify one interface. Note that I could not just use
cmd=ifconfig, because then ddclient might pick the 127.0.0.1 of the local loopback interface.
You can modify the above to suit your needs. For example, if you have two wired interfaces with different IPs, you may want to update two host names, one per interface. Remember to run
ddclient -v to verify that your config file does what you want.