Generate Bind Reverse Zone File Using A Simple Python Script

When I had to create a reverse DNS zone file for my Bind name server I wanted it to be as flexible as possible and thus created a Python script that generates the Bind zone file. This makes renumbering the network really easy.

The script is available as a gist on Github:

To create the zone file, customize the configuration section in the script. Then run it and the output to stdout should be sent to the zone file:

./ > /etc/bind/

The default output (of the example config settings) would look like this:

; Zone file built with the Python Tool
;  This is a Python script that helps you create reverse DNS zone files for the Bind Name Server.
;  I published it in my blog post .
$TTL 1h     ; Default TTL
@   IN      SOA (
    20120311133636  ; serial
        1h      ; slave refresh interval
        15m      ; slave retry interval
        1w      ; slave copy expire time
        1h      ; NXDOMAIN cache time
; domain name servers
@   IN      NS
; IPv6 PTR entries    IN    PTR    IN    PTR


  • The script above could also be implemented using dnslib. (Example usage of this library:
  • It was inspired by the online tool Build BIND rDNS Zone.
  • The command line tool ipv6calc can also get you the reverse nibbles notation of an IPv6 address:
    ipv6calc --out 2001:0db8:85a3:0000:0000:8a2e:0370:7334