txt2bind: a tool for generating bind config files out of a simple txt file


txt2bind is a GPLv3 licensed python-2.6.4 script that transforms newline separated hostname-ip pairs into the appropriate bind configuration .conf and zone files (both forward and reverse). It can run as a small daemon, monitoring the input txt file every SLEEP secs. When the input txt file changes, it re-builds the config files and calls restart_bind_hook() which runs RESTART_BIND_COMMAND to notify the dns server about the changes.



Usage Scenario

The input format of txt2bind is ideal as an intermediate form as it can be easily generated automatically by scripts or irc bots.
The following setup is being used successfully in PWMN wireless community to easily maintain the dns entries on-the-fly from within the community's IRC channel.
Human -> IRC -> DNS IRC bot -> txt file -> txt2bind -> bind configuration

Commmand line arguments

Usage: ./txt2bind.py [-t < DNS_TXT_PATH>] [-c < NAMED.CONF_PATH>] 
                     [-z < ZONE_DIR_PATH>] [-r <BIND_RESTART_COMMAND>] [-d] [-f]
                     [--once] [--stdin] [-v] [-help] 

-t < DNS_TXT_PATH>         Read  txt file which contains the 
                            ip addr - hostname pairs separated by newlines
-c < NAMED.CONF_PATH>      Path of the named.conf bind conf file
-z < ZONE_DIR_PATH>        Path of the directory where the bind zone files
                            are to be placed
-r < BIND_RESTART_COMMAND> The command line hook command to restart bind. It
                            runs only when the input txt timestamp changes.
-d                        Dry Run. Don't write on any files. Instead print
                            on stdout.
-f                        Force generation of full named.conf data, 
                            including some default options.
--once                    Run it only once, don't iterate for ever.
--stdin                   Get input from standard input instead of a file.
-v                        Verbose print.
--help                    Prints out this help message


Example of input txt file (default name: dns.txt) with hostname - ip address pairs:
ftp.neoplan.pwmn services.neoplan.pwmn
irc.neoplan.pwmn services.neoplan.pwmn


  • Simple hostname-ip pairs. Hostname on the Left side and IP address on the right side. Human readable and maintainable !
  • Automatically create the reverse zone files for reverse dns lookup (ip -> name). For example the followin entry in the txt file:
    will not only create the neoplan.pwmn.zone file, but also the 14.140.10.zone for reverse lookup. So querying the dns server as: nslookup will return ap.neoplan.pwmn.
  • Supports aliases. Example:
    ftp.neoplan.pwmn services.neoplan.pwmn
    creates the alias ftp.neoplan.pwmn to services.neoplan.pwmn
  • Supports domains in the txt file. You just need a leading dot (".").
    Example: The following entry in the txt file
    creates the following entry in services.pwmn.zone
    services.pwmn IN A
  • Easily configurable hook for keeping Bind up-to-date whenever the input txt file changes. Currently the default action is to just re-start Bind server.

Getting Started

  • txt2bind does NOT generate the options{...} section of the named.conf file. This is on purpose. txt2bind should generate a "named.conf.txt2bind" file that is included by named.conf . In this way, txt2bind lets you have other configuration as well maintained manually.
  • You can FORCE (-f) the generation of the full named.conf.txt2bind which will include some default options.
  • These options: -c /etc/named.conf -f , and the simple dns.txt txt file of the example should give you working versions of the config files. This way bind should start normally.
  • Edit the values in DEFAULT CONFIGURATION section to suit your needs, or alternatively use the appropriate switches -if available (-help for a short description).
  • Switches override the defaults.
  • Dummy example: You can use the following to get started. -d is for dry-run (don't change any files), --once is for not looping, --stdin is for getting the input from the standard input.
    echo "ap.neoplan.pwmn" | ./txt2bind.py -d --once --stdin
    This will return the following:
    |  txt2bind  online (powered by pwmn) |
    dns txt           :test.txt
    named.conf        :/etc/named.conf.txt2bind
    zone dir          :/var/named/
    bind restart cmd  :/etc/rc.d/rc.bind restart
    dry-run           :True
    force named       :False
    once              :True
    stdin             :True
    verbose           :False
    1 Processing... 
    zone "neoplan.pwmn" IN {
    	type master;
    	file "neoplan.pwmn.zone";
    zone "1.140.10.in-addr.arpa" IN {
    	type master;
    	file "1.140.10.zone";
    $TTL 3D
    @ IN SOA ns.pwmn. admin.pwmn.(
    	1305668854	;Serial: year,month,day,h,m,s
    	8H		;Refresh
    	2H		;Retry
    	4W		;Expire
    	1D)		;Minimum TTL
    @ NS ns.pwmn.
    ap.neoplan.pwmn. IN A
    $TTL 3D
    @ IN SOA ns.pwmn. admin.pwmn.(
    	1305668854	;Serial: year,month,day,h,m,s
    	8H		;Refresh
    	2H		;Retry
    	4W		;Expire
    	1D)		;Minimum TTL
    @ NS ns.pwmn. PTR ap.neoplan.pwmn.


This script is not meant to be used in large scale networks and it is not a replacement for proper DNS management software. It only supports some very basic features of bind (and it might not even implement them properly). It was designed to be used in small scale networks (e.g. wireless community networks) where DNS entries change frequently and are hard-to-manage due to the hard-to-maintain and human-unfriendly bind configuration files.
Back up your bind configuration and zone files before using this program!!! The authors provide absolutely no warranty for using this software!