I found an excuse to play around with powerdns, I am using it as a shadow master for slashzero.com. Getting it to work as a master to my easydns slave was easy enough, so I was about to call it a day when I realized that my dyndns client for my home ip wouldn’t work anymore. After looking around and reading that there wasn’t a good way to do dynamic dns updates other than the pdns pipe backend, and not thinking I could mix and match the pipe backend with the bind backend for the same domain, I hacked the following together.

On my home linux box:

#!/bin/bash

MYIP=$(dig +short myip.opendns.com @resolver1.opendns.com)

ssh user@www.example.com "echo $MYIP > /tmp/dynhost.ip"

And on the server:

#!/usr/bin/perl

use strict;

my $date=`date +%s`;

my $oldip=`dig +short dynhost.example.com`;
my $newip=`cat /tmp/dynhost.ip`;

chomp $date;

if ( $oldip != $newip) {
        my @template=`cat /etc/bind/pri/zone.template`;
        open (ZONEFILE, '>/etc/bind/pri/example.com.zone') or die "Couldn't open file for write";
        foreach my $line (@template) {
                $line =~ s/SERIAL/$date/g;
                $line =~ s/NEWIP/$newip/g;
                print ZONEFILE $line or die;
        }
        close (ZONEFILE);
}

You’ll have to setup a template zone file to run the regex against.

Now there are probably better ways to do it but thats what I came up with quickly. Of course you need ssh keys setup, and configure pdns to rescan the zone file every once in a while. Now I’ll add these to cron and see if it actually works.

Share