dns – Build dns maps from /etc/hosts


dns [ -rbW] [-H hosts-file] [config-file]


dns is used to prepare named(8) maps for a nameserving machine. It takes a small configuration file (or, alternatively, standard input) and uses it and the contents of your /etc/hosts file to build zone maps.

The dns program uses a dns configuration file that contains a list of interesting commands describing things you might want to have in your dns maps. It also picks apart /etc/hosts for the dns information of the various sites in your domain. By default, dns generates map files for your domain and your loopback domain and writes them into your current directory; if you specify the -b option, it will also generate named.boot in your current directory. If you specify the -W option, dns will generate the map files in your database (see below) directory. Finally, dns will attempt to signal named(8) of the changed dns database if you give the -r option.

If you don’t wish to build maps from /etc/hosts you can tell dns a different hosts file by the -H option.

The commands you can specify in the config-file are as follows:

domain domain-name
Build maps for the given domain name; these maps will be named localhost.zone for your loopback IN-ADDR.ARPA map, and domain-name.zone for your domain map. This command is required to generate dns maps.
network address
Build a IN-ADDR.ARPA map for your network (this map includes all entries in /etc/hosts that are in the given network.)
site machine-name
This is the authoritative site for the domain, as given in the SOA record in domain-name.zone. You must give a authoritative site to generate dns records.
contact name
If the contact for this domain is not root@site, set it here.
nameserver name
Declare the machine name as a nameserver for your domain. You must define at least one nameserver for the domain.
private-mail YES or NO
If set to NO, every machine in this domain gets MX records; if set to YES, mail directly to the machine is allowed.
postoffice name
Declare the machine name as a mail exchanger for your domain. This is useful if you don’t want people directly mailing to each machine in your domain.
roothost name
Use the machine name as the alias for your domain, so that attempts to telnet or ftp into your domain go to this machine instead of simply failing.
alias-domain name
Build an alias map to point this domain into your actual domain. This is useful if you have both a leased domain (.com,.org,.net) and a geographic domain, and wish to point stuff from one place into the other.
These define how /etc/hosts aliases are handled; dns generates dns records for every alias in /etc/hosts, but generates CNAME records if you’ve set alias-name and A records if you’ve set alias-ip.
database directory
If you’re using the -W command-line option, write the completed maps to the given directory. Note that the named.boot file will still be written to /etc no matter what directory you give. If you do not specify a database directory, the maps will be written (subject to -W) to the directory /var/namedb.
secondary domain addresses

Act as a secondary nameserver for domain, where its primary nameservers are at the given addresses. This is useful if you’re at one end of a slow or intermittent IP connection and don’t want to spend the time constantly fetching dns information for frequently queried sites.

If the secondary domain is instead a network address, generate an IN-ADDR.ARPA map for it.


Say I’ve got the domain tsfr.org that I’d like to do nameserving for. I’ve also inherited the domain evilparty.org, which I’m planning on using as an alias for tsfr.org, and I’m doing secondary nameservice for the www.pell.portland.or.us/~mastodon domain.

My /etc/hosts looks like this (note that these IP addresses WILL NOT WORK in real life, since they are actually reserved multicast addresses):

# /etc/hosts

# This file contains the ip addresses and names of your host
# and of other machines. The format is
#nnn.nnn.nnn.nnn    fully qualified name     hostname [ aliases ]
#            localhost               loopback            central.tsfr.org         foo news postoffice            right.tsfr.org           right            left.tsfr.org            left            gateway.tsfr.org         gateway www ftp usenet            remote.tsfr.org          remote

#            interesting.site.com            woo-woo-woo.www.pell.portland.or.us/~mastodon

and the configuration file tsfr.dns looks like this:

domain tsfr.org ; our domain
network 224.1.1 ; and our network

site gateway
contact henry
nameserver gateway
nameserver central
postoffice 10 postoffice
postoffice 20 gateway
postoffice 800 central

roothost gateway
alias-domain evilparty.org
database /var/namedb

secondary www.pell.portland.or.us/~mastodon

Running dns -b tsfr.dns generates the following files in the current directory: tsfr.org.zone,evilparty.org.alias (the alias map that’s mainly a PTR to tsfr.org), tsfr.org.rev (the IN-ADDR.ARPA map for our domain), localhost.zone (the IN-ADDR.ARPA map for the loopback interface), and named.boot, which looks like this:

; domain tsfr.org
; data file to boot a name server
; generated by dns on Mon May 6 00:50:15 1996

directory /var/namedb


; type      domain/zone             host/file   local-file

cache      .                        named.cache

primary    0.0.127.IN-ADDR.ARPA     localhost.zone
primary    1.1.224.IN-ADDR.ARPA     tsfr.org.rev
primary    tsfr.org                 tsfr.org.zone
primary    evilparty.org            evilparty.org.alias

; domains we do secondary nameservice for

secondary www.pell.portland.or.us/~mastodon     mastodon.biz.bak


Errors abort the program and return a non-zero exit status.


Written by David Parsons to simplify setting up new nameservers for the pell.portland.or.us, psgvb.com, and pell.com domains.


If named(8) is not running, the -r option will have no effect.

The serial number in SOA records is formed from the year since the epoch (1970 ), the julian day, and the number of minutes since midnight divided by two. If you quickly change maps with dns, the serial number will NOT update, thus leading to confused remote nameservers.

Source Code & Sample Data

Makefile, sample/tsfr.org.rev, dns.8, sample/localhost.zone, sample/named.boot, dns.c, sample/tsfr.org.zone, sample/hosts, and sample/evilparty.org.alias.