Wednesday, November 21, 2007

ddclient - get your IP address from behind NAT, without configuring your router

As previously mentioned, I had downloaded ddclient and was trying to make it work, but was getting errors because of NAT on my router.

My router's not specifically mentioned as one of the Linksys routers ddclient supports, and I played briefly with trying to set ddclient's options to log into my router, with no success. I wasn't patient enough to try every ddclient router option and see if any worked. Time to try a different option...

I can get my IP address in a webpage easily enough, using

apt-get install curl (since it wasn't installed already on my Debian box)

curl -s

This gives a fine, fine page showing my IP address with all the headers. Chop it down to size with head and tail:
curl -s head -c -16 tail -c 13
(Notice here, I decided not to use the cut command, which would introduce a subtle bug if my IP address changed).

You can feed ddclient an IP address like so:

ddclient ip=
So, we can use good ol' page 4-4 of "Unix In A Nutshell" to do command substitution. We use the `` quotes to shove the IP address into the ddclient command:

ddclient -ip=`curl -s head -c -16 tail -c 13` -v
Notice that this still will give an error in both the Debian-okayed version of ddclient and ddclient version 3.7.3, but not a fatal one, as we can see with the -v (for verbose) flag. Success!

Feedback welcome, certainly. If you're putting this in as a cron job, don't run it crazily often. It's not like your IP address changes twice a minute. Thanks to the generous folks at DynDNS for providing such a useful tool, and thanks to the good people of ZoneEdit for the Dynamic DNS page that got me started on this path.


Anonymous Anonymous said...

Not necessary.

Just edit /etc/ddclient.conf and change the line starting with "use" to:

use=web, web=dyndns

5:17 PM  
Blogger Todd D. said...

Cool. I think I have the default of dnspark in there.

Are you using Zoneedit?

5:28 PM  

Post a Comment

<< Home