Setting up a Bind 9 DNS Name Server
Bind (Berkeley Internet Domain software) is the most commonly used name server. It's necessary to patch bind to prevent your users from being redirected to Verisign's advertising site when they make a typing mistake. See also linuxsetup59.html for details about setting up DNS in small subnets.
Step 1: Apply anti-Verisign patch and build the software.
tar -xzvf bind-9.2.2.tar.gz cd bind-9.2.2 patch -p1 < ../patch.9.2.2-P1 configure make make install |
Step 2: Create Zone files.
- Obtain named.root by anonymous ftp from ftp.rs.internic.net
- Rename named.root to db.cache
- Create zonefiles according to Chapter 4 in
DNS and BIND (O'Reilly Press). Note that the filenames for
the db files specified in /etc/named.conf
must correspond to the filenames of the zonefiles. The zonefiles must be
customized for each server. You should have at least two servers.
As an example, here are the zone files we use on our server:
Do not use these files without modification. These files must be modified to match your hostnames.- Create db.127.0.0 (for the localhost)
- Create db.mittlenkampf (For forward name resolution)
- Create db.11.111.111 (For reverse name resolution)
- Create db.22.222.222 if you have a second subnet.
- Add the line
above the SOA line in each zonefile to specify the time-to-live. This is the 'TTL directive' which is necessary for bind version 9. It is needed even if the TTL is specified in the SOA.$TTL 21600
- Make sure the forward and reverse files correspond with each other, or you will have weird DNS problems.
- Check to make sure the hostmaster alias specified in your SOA is a real person who is listed in the /etc/aliases file.
- Make a backup copy of the db files, in case named trashes them (which it will do if you are not authoritative for the domain).
Step 3: Configure Bind.
You should always set up at least two name servers, and designate one as the
master.
Do not use these files without modification.
These files must be modified to match your hostnames.
- Create /etc/named.conf for the master server. Note that the path for the db files ( var/named/ ) is specified in the named.conf file. The format for version 9 is different from that shown in the book. In this example, the access control list (acl) is disabled.
- Change the pid-file location to /var/named/named.pid. This is necessary because named is not being run as root and can't access /var/run.
- Create named.conf for the slave server(s).
- Create user 'named' and group 'named'. In /etc/passwd:
In /etc/group :named:x:44:44:Nameserver Daemon:/var/named:/bin/nologin
named:x:44:named
- Create a /var/named/ directory, owned by
named.named and put
the db files there. They should also be owned by
named.named.
Make sure /var/named/ has the following permissions:
drwxr-xr-x 2 named root 4096 Apr 1 14:42 named
- Set the options in named.conf as needed for security.
The "allow-transfer" option prevents third parties from performing zone transfers and thereby gaining information about your network.options { directory "/var/named"; pid-file "/var/named/named.pid"; allow-query { "any"; }; allow-transfer { 63.127.146.192/26; 65.198.102.64/26;}; allow-recursion { 63.127.146.192/26; 65.198.102.64/26;}; };
The "allow-recursion" option prevents third parties from leeching your bandwidth by using your server instead of their own server to do their DNS. With this line, only the specified networks are allowed to perform recursive queries, i.e. queries about names for which the server is not authoritative. Answering recursive queries also makes your server vulnerable to cache poisoning.
You should also disallow dynamic updates. The main effect of dynamic updates is to mess up your zone files. See www.cert.org/archive/pdf/dns.pdf for more suggestions on securing your DNS server.zone "brclbangers.org" { type master; file "db.brclbangers"; allow-update { none; }; allow-transfer { 63.127.146.192/26; 65.198.102.64/26; }; allow-query { "any"; }; notify yes; };
Alternatively, use an access control list:
The above combination will allow only the living-dead (and clients therein) to perform recursive queries.acl "living-dead" { 63.127.146.192/26; 65.198.102.64/26; }; options { ... allow-recursion { living-dead; }; };
Step 4: Change the System Startup Scripts.
- Modify /etc/rc.d/named to reflect the correct path
for named. Also remove the '-g' option,
which is not supported in ver. 9, if it's present. Make sure the
named script is still executable
and owned by root.
-rwxr----- 1 root root 906 Apr 1 14:34 named
- Modify /etc/rc.config and change START_BIND to "yes" (This only applies to SuSE Linux).
- Monitor for errors using the command
tail -f /var/log/messages and
try starting named by typing
"/etc/rc.d/named start".
The logfile should say something like this (this is a log from a slave server):
This is different from the logs produced by the old bind:named: starting BIND 9.1.1 -u named named: using 1 CPU named: loading configuration from '/etc/named.conf' named: the default for the 'auth-nxdomain' option is now 'no' named: no IPv6 interfaces found named: listening on IPv4 interface lo, 127.0.0.1#53 named: listening on IPv4 interface eth0, 11.111.111.195#53 named: running named: refresh_callback: zone 222.222.22.in-addr.arpa/IN: \ non-authoritative answer from 111.1.1.111#53
Make sure the correct bind is running. With bind 9, if any error is found, bind will not start up.named: starting. named 8.2.3-T5B ... 8-8.2.3/bin/named named: hint zone "" (IN) loaded (serial 0) named: master zone "mittlenkampf.org" (IN) loaded (serial 1) named: master zone "0.0.127.in-addr.arpa" (IN) loaded (serial 1) named: slave zone "111.111.11.in-addr.arpa" (IN) loaded (serial 1) named: slave zone "222.222.22.in-addr.arpa" (IN) loaded (serial 1) named: listening on [127.0.0.1].53 (lo) named: listening on [11.111.111.195].53 (eth0) named: Forwarding source address is [0.0.0.0].1783 named: group = named named: user = named named: Ready to answer queries.
Step 5: Check its operation for a few days before announcing the new service.
- Check with nslookup to make sure the server can answer forward, reverse, and external queries.
- Shut down named by typing /etc/rc.d/named stop.
It should say:
named: shutting down named: no longer listening on 127.0.0.1#53 named: no longer listening on 11.111.111.195#53 named: exiting
- Check the db files against their backups using diff. If there were no errors, the files should be only slightly changed. Named may change the files depending on the settings in named.conf. It is a good idea to re-check the files each time you restart named whenver a change occurs in your registration status.
- Go to the website of the company from which you purchased your domain name and register your DNS server with them.
- Next, contact the ISP that issued you the network address space and get them to register your name servers. Each domain must be registered with its parent. This is the often most difficult step, because many ISPs have trouble setting up DNS properly. Both of these steps are necessary for correct forward and reverse lookups.
- Change /etc/dhcpd.conf for your Windows and Mac users and tell your Unix users to change their /etc/resolv.conf to point to the new name server. Users who are getting their IPs using DHCP should be told to leave their entries for DNS servers blank. The nameserver should have itself listed in its /etc/resolv.conf file.
- Run the servers for a couple of days as slaves to make sure everything works perfectly before making them authoritative.
- Then, go to the Website of your domain name registrar and change the authoritative server to point to your primary server, and make your ISP's name server the secondary name server. Once you are certain your nameserver is working properly, all your users are using it, and the changes have propagated throughout the Net, then go to the Website again and substitute your secondary for the ISP's server. Finally, after a couple more days, contact your ISP and let them know that your server is now the authoritative one, and that they can remove their zone files. Don't add or delete any DNS entries from the time you start running a server until the ISP's server is actually dropped by INTERNIC (do a 'whois' lookup).
- Sign up for the bind-users mailing list, so you are informed if the named.root file from INTERNIC is changed.
- If you are running an OS that meddles with your resolv.conf file (such as SuSE Linux), edit /etc/rc.config to prevent it from being changed.
Problems
- Bind v.8 seems to die at random times. Solution: switch to v.9.
- Host hostname works but ping hostname gives
hostname not found message.
Solution: add
to /etc/resolv.conf on the nameserver, where 111.111.111.11 is the hostname of the server running bind. This is necessary even though the book says not to do this.nameserver 111.111.111.11
Maintenance
- If you change the zonefiles, be sure to increment the serial number so your slave servers will obtain the updated information.
- You should have bind running on at least two computers. If your nameserver goes down for a long enough time, it may take several hours after you restore them before people can reach you. If you are in a location where the electricity is frequently off for long periods, it may be better to let the ISP handle your DNS.
- Make certain to update both the forward and reverse zonefiles whenever you change anything.
- Don't make more than one master server or you will have to keep them synchronized.
Testing for lame delegation
- Check to make sure your delegation is not lame by running dnswalk. Having a lame delegation doesn't seem to hurt anything, but preventing your network from showing up in other administrators' logs as "lame" is reason enough to fix the problem.
- Find out what your nameserver is presenting to the public with
the command
In this example, only the MX records are checked.dig @ mynameserver.myisp.com mx mydomain.org
Back