My Router Doesn’t Support Dynamic DNS, No Problem!

Well I just recently hooked up a DSL connection via a DSL modem that was also a router. For regular home users this DSL modem/router is probably good enough but for more complex setups it is useless. In this particular setup we had a custom built firewall. This firewall had a built in dynamic DNS service for ISP’s that rotate IP addresses. The problem however, is that the firewall was behind the DSL modem’s NAT. So it was reporting a private 192.168 number to Dyndns.

We couldn’t turn off NAT on the DSL modem unless we purchased a block of static IPs. The DSL modem, being home orientated, didn’t allow for dynamic DNS.

Fortunately dyndns offers a service to detect your public IP address. They also have an API to change your IP for dynamic DNS. Knowing this I quickly did a search on my favorite perl code repository, CPAN. Sure enough someone made a module that sends updated IP info to dyndns.

Updating DynDNS with Perl

 
The first thing you will want to do is download the module, Net::DNS::DynDNS. On a Linux box it is super easy.

cpan
install Net::DNS::DynDNS

On windows you will need to compile it with dmake and mingw since there are no ppm for Active Perl.

Then create a file called, dyndns.pl, replacing username, password, and yourdomain.selfip with your own values.

#!/usr/bin/perl
use Net::DNS::DynDNS;
print Net::DNS::DynDNS->new('username', 'password')->update('yourdomain.selfip.com');

You can then update your IP by simply doing

perl dyndns.pl

To setup automatic updating we can use our favorite scheduler, cron.

crontab -e

Then add the following line, pointing to where you saved dyndns.pl

1 * * * * /usr/bin/perl /home/youruser/crons/dyndns.pl

This will update every hour which is plenty for my needs. Feel free to change it to fit yours.


Was this information useful?


5 Responses to "My Router Doesn't Support Dynamic DNS, No Problem!"
  1. Jade Robbins on October 24th, 2008

    Ahh yes love dyndns :D

  2. Tyghe on November 7th, 2008

    So I’m assuming that this script checks your ip before it tries to do the update. DynDns will disable your hostname if you try to update more than like 1 time per ~20 days or something.

    I found this out when I did this and the stupid client I used just tries to update regardless if your ip is already correct or not.

  3. Mark Sanborn on November 7th, 2008

    Tyghe,

    Good point.

    I actually got banned after using this script after a few hours. I rewrote it so that it only updates if the IP actually changes.

    If you want it I can upload it up here.

  4. sz on November 10th, 2008

    can’t you just use the one provided by dyndns? you are guaranteed not to be banned as they say.

  5. Mark Sanborn on November 10th, 2008

    sz,

    Good point, for Windows machines please use their updater. They also have recommended third-party Linux clients, but I didn’t see any that I liked.