Thursday, June 9, 2011

Dynamic Free DNS

I used to use everydns.net which was later acquired by DynDNS.  Sadly, once acquired they started migrating users from the free service to their paid subscription service which as far as I can tell all it provides
is the ability to point foobar.com to a dynamic IP, as well as modifying your DNS records (A, CNAME, MX, etc ).

Once alternative is zoneedit.com but my domain seems to be tied into a weird flux having used them in the past that I couldn't use their service as an alternative, so I ended up setting up a custom solution that is probably overkill for most users, but it might be interesting information.

So, I need to point my domain to have 2 name-servers that manages my zone.

I only care about 1 zone really, in my test case I just pointed my 2nd name server to the default my registrar uses.  So, if my primary DNS is down, I'll probably get the standard this page is registered and is owned by foobar.com.

The main issue is that I need to point a registrar to a dynamic IP.  So I setup no-ip service to auto update.  I pointed my Domain registrar to a no-ip address and go figure it accepted it.

So now I can point it to my own IP that can potentially change and dns resolution will go to the proper address.

Now, naturally you need to expose port 53, and you need to run a DNS server of your choice I went for bind.

Now, I can have an CNAME record in my dns that points to say foobar.no-ip.com but all that would give me is a redirect, and I wanted to have my own domain after all.

I need to setup at least one A record that maps to my public IP.  This is easily done, and usually looks something along these lines:

www           IN        A       4.4.4.4

with 4.4.4.4 being your public IP.  The problem that arises is that even though no-ip autoupdates to point outside requests to my DNS, unless I updated bind to point to the right address then there is no point.

My hacky solution was to write this python script that takes a list of bind files to update.

It'll read my dns zone file, search for any IPs not matching my LAN subnet, and update all those records with the current IP address.  Once it finishes, it'll reload bind to make it read the new updated config.

current code is in:  https://github.com/safaci2000/dns_utils though like I said its hacky.

It establishes if an IP is local or not by comparing the first octet.  I need to add some logic that actually checks if the IP is public or not.

So..once this all done I have a domain that points to foobar.no-ip.com for its dns host.

foobar-ip.com points to my machine as long as it's online.  Then I have an hourly updated python script that will update and reload my DNS records.  There is the issue that if my DNS server goes down, nobody
can access my machine.  This normally wouldn't be an issue (for me) since my DNS all points to the local machine, but I am hosting my email with google.  So if my dns server goes down, in theory I could
be losing mail.  I was thinking of just getting a VPS and setting this up a secondary machine, but if I get
to the point of paying $20/mo for a machine to run a DNS zone, then I might as well just pay dyndns my monthly fee.  Then again, a full VPS would be more useful to me and could have some more potential features then just a simple dns updater which is essentially recreated here.

Thoughts, comments?