Deploy Your Own Bind9 based DDNS Server

This post is based on my previous blog post, Updating DNS Entries (with nsupdate or alternative implementations) – Run Your Own DDNS, and on Cédric Félizard's post "Your Own Dynamic DNS".

Running your own DynDNS (DDNS) server is easy when you have your own domain registered and an own Linux server up and running. A .de domain, for example, costs only about 6 EUR per year if you register at an inexpensive domain hoster in Germany. Let's say you have registered Now you can use a subdomain such as to contain all your dynamic IPs. An individual host could then be named something like The advantage of using a subdomain instead of itself is that you can refer the authority for this subdomain to your own server while the upper zone can still be managed by the DNS hoster. The following sections will describe how to set this up in detail.

Start by installing the DNS server BIND9 on your Debian/Ubuntu server via apt-get update && apt-get install bind9.

Next, set up /etc/bind/named.conf.local with your local zone.

// ---***--- Own DynDNS
include "/etc/bind/ddns-keys.conf";
zone "" IN {
        type master;
        file "/var/lib/bind/";
        // for Apple OS X 10.8 "dynamic global hostname":
        //allow-update { key; };
        update-policy {
                grant * selfsub A AAAA TXT;
                //grant * self A AAAA TXT;
                //grant name A AAAA TXT;
                //grant subdomain;
        notify no;


$TTL 10 ; 10 seconds             IN SOA (
                                2014080101      ; serial
                                120             ; refresh (2 minutes)
                                120             ; retry (2 minutes)
                                2419200         ; expire(4 weeks)
                                120             ; minimum (2 minutes)

$TTL 30 ; 30 seconds
ipv4                    A
ipv4v6                  A
                        AAAA    2001:0db8::2
ipv6                    AAAA    2001:0db8::2

ns1                     A
ns2                     AAAA    2001:0db8::2

Fill /etc/bind/ddns-keys.conf with all the keys you want to support. Generate them with dnssec-keygen -a HMAC-SHA512 -b 512 -n HOST (to be found in the .key file):

key "" {
    algorithm HMAC-SHA512;
    secret "5f2It/b/7wF0QmnFQ2DiTVIF6Z/cN8a8dxyIf149my61ihkgNHqn4KjG eTlbYQ7CKVskV4lmV1R0M1xAPj4Ipg==";

Double check and reload BIND:

named-checkzone /var/lib/bind/
/etc/init.d/bind9 reload

Debug with

tail -f /var/log/syslog

If your DDNS server was running for some time and receiving dynamic updates, you will have a /var/lib/bind/ file along with the /var/lib/bind/ file. So change the zone file with care only after syncing in the journal file's changes. On Bind 9.9+ you can do this with rndc sync -clean, see here. A complete shutdown and restart of Bind should also have the same effect.


To check the whole chain of DNS entries, do:

  1. Ask for the nameserver for using dig ns
  2. Use one of the returned nameservers ( and ask it to tell you about the name servers for the zone dig ns.
  3. Use one of the returned nameservers ( and ask it to tell you about the zone dig soa.
  4. Ask that server for your dynamic domain name using dig a.
  5. Check if the server allows/refuses to do a zone transfer from different machines: dig axfr

Also disable DNS-Rebind protection for the domain if you use a Fritz!Box router (found here):


FRITZ!Box suppresses DNS answers that point to IP addresses in your home network (DNS-Rebind-Protection). Provide a list of domain names here to be excluded from this protection.

(You find this setting at Heimnetz/Netzwerk -> Netzwerkeinstellungen.)

If you ever need to flush the cached entries of your BIND9 server, run rndc flush.

If you're interested in checking the times your responses are being cached and the performance of your DNS server, you may want to take a look at this forum post.
for i in {1..30}; do echo $FQDN; done | xargs -I^ -P10 dig ^ | grep time | awk /time/'{sum+=$4} END { print "Average query = ",sum/NR,"ms"}'

On my Raspberry Pi running Bind9, an initial query (uncached entry) takes 244 ms. A subsequent cached answer takes 11 ms. On a different virtual server with a little more processing power, the time to resolve the address was 38 ms initially and 5 ms for subsequent cached responses. It seems like the processing power of the RPi is not that good for a fast DNS server.

Here is a table of my speed tests to resolve A RRs of different FQDNs:

Name Server FQDN Client Connection Initial time Subsequent time Ping time
RPi 50/10 Mbit 192 ms 34 ms 32.9 ms
RPi Gigabit 244 ms 11 ms 4.97 ms
vServer 50/10 Mbit 60 ms 27 ms 25.2 ms
vServer Gigabit 38 ms 5 ms 4.72 ms
RPi 50/10 Mbit 91 ms 35 ms 32.1 ms
vServer 50/10 Mbit 49 ms 27 ms 24.9 ms
RPi 50/10 Mbit 62 ms 36 ms 31.5 ms
vServer 50/10 Mbit 47 ms 26 ms 23.0 ms Gigabit 12 ms 12 ms 11.9 ms
RPi Gigabit 266 ms 12 ms 9.38 ms
vServer Gigabit 11 ms 5 ms 4.01 ms Gigabit 12 ms 12 ms 11.8 ms
RPi Gigabit 57 ms 11 ms 9.50 ms
vServer Gigabit 17 ms 5 ms 4.05 ms
RPi Gigabit 873 ms 11 ms 9.50 ms ipv4.[...] 50/10 Mbit 97 ms 34 ms 32.3 ms
RPi ipv4.[...] 50/10 Mbit 35 ms 35 ms 32.8 ms
vServer ipv4.[...] 50/10 Mbit 27 ms 27 ms 22.7 ms

The ping time is the avg of four ping rounds to the DNS server in question. The Server connection speed of the RPi and of the vServer was 100 Mbit in all tests.

The last three test entries contain a query for a domain being administered by the RPi&vServer. Thus the advantage of Google's disappears.

Upating the entries

This can be done with nsupdate or with my Python based wrapper for nsupdate: See my previous blog post, Updating DNS Entries, for more details.

The above software is Python based. If you want to do update entries for low performance hardware such as routers running OpenWrt, you don't want to use Python but directly use nsupdate in a shell script. For more details, read the article DIY Dynamic DNS with OpenWrt & BIND and check out this startup script.

On your client you need the key files (.key and .private) generated in the dnssec-keygen step above.

Running your own What's My IP HTTP service

If you want a laptop or a device connected to the net via a consumer provider with changing IPs to update the DNS entries to their current external IP, you need to find out about that external IP first. To do so, there are a couple of services running on the web but you can also run your own.

I wrote a minimal Python-based server for this purpose, it's called WhatsMyIP and you can find it on Github.
Setting it up is described in the blog post Arch Linux – Deploying a Pure Python Web App. The script, which was introduced in the section above, makes use of my deployment of that web app.

Setting up a secondary DNS on Arch Linux

BIND in Arch Linux' Wiki

pacman -S bind dnsutils

Add the following zone to /etc/named.conf:

// uncomment
listen-on-v6 { any; };

// you might want to allow recursion for your network:
allow-recursion {; 2001:a38::/32; };

// add the slave-zone:
zone "" IN {
        type slave;
        masters {; };
        file "";

Check your configuration with


Start BIND9 with:

systemctl start named

Check that everything works as expected using systemctl status named, less /var/log/named.log, and by testing if the server responds to DNS requests. If everything works as expected, let BIND9 be started automatically on system boot:

systemctl enable named

Alternatives to Bind / Dynamic DNS server For The Home Network

Just for the sake of completeness, here are some other possibilities that I found on the web. I prefer Bind though:

Also check my older blog post Updating DNS Entries (with nsupdate or alternative implementations) – Run Your Own DDNS.