Blog IndexPosts by TagHome

Automatic reverse DNS zonefile generation

Posted <2017-08-16 Wed 16:25> by Aaron S. Jackson.

My home network is a bit excessive, which is just the way I like it. The server (escher) which hosts this website also handles the authoritative DNS for my domains, as well as recursive DNS for the local networks. All of the machines on the network have an entry under Machines which don't need a public address have a private address (and access the internet through NAT) and their hostname in this zonefile is appended with ".nat". For example: Since escher is the primary DNS server for the machines on the network, there is also a reverse DNS zonefile. After a while of trying to keep these two files up to date, I gave up and wrote this script:

serial=$(date +%Y%m%d%H)
cat  > <<EOF
\$TTL 60
@       IN      SOA (
        $serial ;; serial
        1200    ;; refresh
        120     ;; retry
        1209600 ;; expire
        60      ;; neg

@   IN NS

grep 192.168.1 \
    | awk '{ split($4,ip,".");
             printf("%-3s IN PTR %-30s ;; %s\n", ip[4], $1"", comment[2])
           }' \

The entries in typically look like this:

skippy.nat       IN  A  ;; asj HP 712/60
... <snip> ...
surface.nat      IN  A  ;; tld Surface
... <snip> ...
dhcp-1-64.nat    IN  A   ;; dhcp
dhcp-1-63.nat    IN  A   ;; dhcp
dhcp-1-62.nat    IN  A   ;; dhcp

And so, the script will generate the reverse zone:

144 IN PTR         ;;  asj HP 712/60
... <snip> ...
100 IN PTR        ;;  tld Surface
... <snip> ...
64  IN PTR      ;;  dhcp
63  IN PTR      ;;  dhcp
62  IN PTR      ;;  dhcp

While on the topic of reverse DNS, I might as well have a small rant about Zen and their refusal to delegate reverse DNS for their customers' subnets. Zen route to us a public 29 subnet, which is great for remotely accessing specific machines remotely. While it is not possible to correctly delegate reverse DNS for subnets which aren't Class A, B or C, it is still possible.

There are two ways of doing this, and Andrews & Arnold ISP (being the excellent ISP they are) give you the option to do so. The first is to delegate each full address to another name server. I do this for the AAISP data SIM which is in my laptop. To get this working, you simply add a PTR record for @, pointing to the correct hostname.

The second approach, which is preferable if you have more than one address, is to add a CNAME record for each address pointing to a single zone. In that zone, following an agreed format, you can define a PTR record pointing to the hostname. This works because reverse DNS will follow the same rules of normal lookup, following name server delegations and CNAMES. See RFC 2317 for more information.

Why Zen won't do this is beyond me, and quite annoying, since I have to log into their slow website and update each record separately if I make a change to those records under the zone.

Wanting to leave a comment?

Comments and feedback are welcome by email (

Related posts:

Tags: networking

Blog IndexPosts by TagHome

Copyright 2007-2022 Aaron S. Jackson (compiled: Sun 2 Jan 00:24:11 GMT 2022)