Home | History | Documents | Software | Feedback | Disclaimer

The Arda.Homeunix.Net DNS & DHCP Setup

Table of contents

  1. Introduction
  2. Preliminaries
  3. DNS
    1. Master DNS Server
      1. Configuration Files
      2. Zone Files
      3. Manually Updating Zone Files
      4. Running BIND Chrooted
      5. Startup Scripts
    2. Slave DNS Server
      1. Configuration Files
      2. Zone Files
      3. Running BIND Chrooted
      4. Startup Scripts
  4. DHCP
    1. Configuration Files
    2. Running DHCP Chrooted
    3. Startup Scripts
  5. Software Home Sites
  6. Further Reading

Introduction

This document describes how DNS and DHCP work on the Arda Network. I’ve managed to use many of the features of DNS and DHCP in my setup so this document should provide a fairly comprehensive guide as to how to get things working. Features you’ll find described here include:

This document does not presume to be a tutorial on how DNS or DHCP work. It does not even presume to teach how to use the particular software described. This document provides an example of a working DNS/DHCP setup. If you are new to DNS or DHCP, you will almost certainly need to reference additional resources to understand what will be presented here. Don’t panic, since DNS and DHCP are fundamental to the operation of IP networks, such resources are easy to come by.

Preliminaries

I chose to use the Internet Systems Consortium’s (ISC) implementations of DNS and DHCP for the Arda Network. Why you ask? Because they are both in wide use so I thought I would be able to find a lot of resources to assist me in setting up the software. It turned out that I was correct in this assumption. In particular, I relied on an excellent book from O'Reilly Press called ‘DNS and BIND’. This book provides much useful information; I highly recommend it.

The particular versions of software I use are:

Knowing the software versions is especially important. For BIND, configuration syntax has changed dramatically between versions so what you see described here can be reliably applied only to BIND 9.

In the DHCP configuration file, the option used to invoke dynamic updates with a DNS server is also sensitive to the particular version of DHCP you are using.

You will find an overview, including a very nice diagram, of the Arda Network here.

Why have I gone to the trouble to set up DNS and DHCP on my network you ask? Well, the simplest answer is because I wanted to. The more involved answer is in two parts. I find updating host files tedious and having DNS allows me to update two zone files on the master DNS server whenever something changes on my network. I also sometimes bring home a laptop from work and I wanted to be able to plug it into my home network to do things like transfer files to and from it. Since it uses DHCP at work, I thought I’d set things up that way at home too. I expect there are a lot of simpler ways to accomplish what I wanted but I don’t imagine they would be as interesting as the way I’ve done things.

One thing to keep in mind when reading this document is that DNS on the Arda Network is set up to serve machines on my local network only. I have not set up DNS to serve zone data to the outside world and, in fact, I have options in my DNS configuration files specifically to prevent the outside world from reading my zone data. If you want to serve zone data from your domain to the internet at large, you’ll have to do some things differently than what I describe here. If all you want to do is create a DNS cache (a server that caches the results of DNS queries but does not serve zone data), have a look at the DNS cache I’ve set up on Thebe using djbdns.

DNS

DNS on the Arda Network is handled by two machines, Europa and Io, that act as a master/slave pair. These two machines use automated zone transfers, secured using TSIG keys, to stay in sync. The master DNS server is also dynamically updated by the DHCP server. Dynamic updates are also secured using TSIG.

On both Europa and Io, all TSIG keys were generated using this command.

Keys were cut and pasted into configuration files as appropriate. In the configuration files listed below, when two keys in different files are referred to by the same name, it is because the same key is used in both files.

Two domains are described in my DNS setup, arda.homeunix.net and arda.homelinux.net. The first domain is your typical internet domain. All the machines on my home network are part of this domain. The second domain is a so-called virtual domain. It is used by Callisto, my mail server, so that I can route email addressed to this domain. No actual machines belong to the arda.homelinux.net domain. Although I include only one virtual domain in this document, I am not limited to one. I could have as many virtual domains set up as I want simply by adding the appropriate zone files and updating the named.conf files of my DNS servers.

Master DNS Server

Configuration Files

Because I’m using TSIG to secure such things as zone transfers and rndc, getting the permissions on the various configuration files right is very important. Here are the ownership and permissions of the various configuration files on Europa. Take note of the ownership and permissions of the rndc related files. They are set up this way so that named can read these files but only a process with root privileges can change them.

File Name Owner Permissions
/etc/namedb/etc/named.conf root:root 644
/etc/namedb/etc/rndc.key root:named 640
/etc/rndc.conf root:root 600
/etc/resolv.conf root:root 644

Here is my named.conf file.

Some things to note concerning my named.conf file include the following points.

Here is my rndc.conf file.

And here is my rndc.key file.

My /etc/resolv.conf file looks like this.

Zone Files

The nine zone files are located in /etc/namedb/master. The section describing running BIND in a chroot jail shows a listing of the directory.

There are two *.jnl files in the /etc/namedb/master directory. They are produced when dhcpd updates my zone files.

Here are what my zone files look like.

Zone File Contents
arda.homeunix.net.zone
$ORIGIN .
$TTL 86400      ; 1 day
arda.homeunix.net       IN SOA  europa.arda.homeunix.net. postmaster.arda.homeunix.net. (
                                20060705   ; serial
                                21600      ; refresh (6 hours)
                                3600       ; retry (1 hour)
                                604800     ; expire (1 week)
                                21600      ; minimum (6 hours)
                                )
                        NS      io.arda.homeunix.net.
                        NS      europa.arda.homeunix.net.
                        MX      10 callisto.arda.homeunix.net.
$ORIGIN arda.homeunix.net.
metis                   A       192.168.10.1
thebe                   A       10.10.0.1
io                      A       192.168.10.5
europa                  A       192.168.10.9
callisto                A       192.168.10.6
$TTL 14400      ; 4 hours
ganymede                A       192.168.10.28
                        TXT     "311cc5d6b2b528cc61e23c831e840a6bf4"
$TTL 86400      ; 1 day
mail                    CNAME   callisto
www                     CNAME   io
	
arda.homelinux.net.zone
$ORIGIN .
$TTL 86400      ; 1 day
arda.homelinux.net      IN SOA  europa.arda.homeunix.net. postmaster.arda.homeunix.net. (
                                20070706   ; serial
                                21600      ; refresh (6 hours)
                                3600       ; retry (1 hour)
                                604800     ; expire (1 week)
                                86400      ; minimum (1 day)
                                )
                        NS      io.arda.homeunix.net.
                        NS      europa.arda.homeunix.net.
                        MX      10 callisto.arda.homeunix.net.
	
10.168.192.in-addr.arpa
$ORIGIN .
$TTL 86400      ; 1 day
10.168.192.in-addr.arpa IN SOA  europa.arda.homeunix.net. postmaster.arda.homeunix.net. (
                                20060705   ; serial
                                21600      ; refresh (6 hours)
                                3600       ; retry (1 hour)
                                604800     ; expire (1 week)
                                21600      ; minimum (6 hours)
                                )
                        NS      io.arda.homeunix.net.
                        NS      europa.arda.homeunix.net.
$ORIGIN 10.168.192.in-addr.arpa.
1                       PTR     metis.arda.homeunix.net.
$TTL 14400      ; 4 hours
28                      PTR     ganymede.arda.homeunix.net.
$TTL 86400      ; 1 day
5                       PTR     io.arda.homeunix.net.
6                       PTR     callisto.arda.homeunix.net.
9                       PTR     europa.arda.homeunix.net.
	
0.10.10.in-addr.arpa
$ORIGIN .
$TTL 86400      ; 1 day
0.10.10.in-addr.arpa    IN SOA  europa.arda.homeunix.net. postmaster.arda.homeunix.net. (
                                20070705   ; serial
                                21600      ; refresh (6 hours)
                                3600       ; retry (1 hour)
                                604800     ; expire (1 week)
                                86400      ; minimum (1 day)
                                )
                        NS      io.arda.homeunix.net.
                        NS      europa.arda.homeunix.net.
$ORIGIN 0.10.10.in-addr.arpa.
1                       PTR     thebe.arda.homeunix.net.
	
localhost.zone
$TTL 1w
@        IN SOA europa.arda.homeunix.net. postmaster.arda.homeunix.net. (
                                        1       ; Serial
                                        6h      ; Refresh after 6 hours
                                        1h      ; Retry after 1 hour
                                        1w      ; Expire after 1 week
                                        1d )    ; Negative caching TTL of 1 day

                        IN      NS      europa.arda.homeunix.net.
                        IN      NS      io.arda.homeunix.net.

localhost.              IN      A       127.0.0.1	
	
localhost.rev
$TTL 1w
@        IN SOA europa.arda.homeunix.net. postmaster.arda.homeunix.net. (
                                        1       ; Serial
                                        6h      ; Refresh after 6 hours
                                        1h      ; Retry after 1 hour
                                        1w      ; Expire after 1 week
                                        1d )    ; Negative caching TTL of 1 day

                        IN      NS      europa.arda.homeunix.net.
                        IN      NS      io.arda.homeunix.net.

1                       IN      PTR     localhost.
	
named.broadcast
named.network
$TTL 1w
@       IN SOA europa.arda.homeunix.net. postmaster.arda.homeunix.net. (
                                        1       ; Serial
                                        6h      ; Refresh after 6 hours
                                        1h      ; Retry after 1 hour
                                        1w      ; Expire after 1 week
                                        1d )    ; Negative caching TTL of 1 day

                IN      NS      europa.arda.homeunix.net.
                IN      NS      io.arda.homeunix.net.	
	
named.bind
$TTL 1d
$ORIGIN bind.
@       CHAOS SOA europa.arda.homeunix.net. postmaster.arda.homeunix.net. (
                                        1       ; Serial
                                        6h      ; Refresh after 6 hours
                                        1h      ; Retry after 1 hour
                                        1w      ; Expire after 1 week
                                        1d )    ; Negative caching TTL of 1 day

                CHAOS   NS      localhost.

version.bind.   CHAOS   TXT     "BIND 9.3.2"
authors.bind.   CHAOS   TXT     "Are at home at the ISC."
	
named.root
; <<>> DiG 9.3.2 <<>> @a.root-servers.net . ns
; (1 server found)
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 63591
;; flags: qr aa rd; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 13

;; QUESTION SECTION:
;.                              IN      NS

;; ANSWER SECTION:
.                       518400  IN      NS      C.ROOT-SERVERS.NET.
.                       518400  IN      NS      G.ROOT-SERVERS.NET.
.                       518400  IN      NS      F.ROOT-SERVERS.NET.
.                       518400  IN      NS      B.ROOT-SERVERS.NET.
.                       518400  IN      NS      J.ROOT-SERVERS.NET.
.                       518400  IN      NS      K.ROOT-SERVERS.NET.
.                       518400  IN      NS      L.ROOT-SERVERS.NET.
.                       518400  IN      NS      M.ROOT-SERVERS.NET.
.                       518400  IN      NS      I.ROOT-SERVERS.NET.
.                       518400  IN      NS      E.ROOT-SERVERS.NET.
.                       518400  IN      NS      D.ROOT-SERVERS.NET.
.                       518400  IN      NS      A.ROOT-SERVERS.NET.
.                       518400  IN      NS      H.ROOT-SERVERS.NET.

;; ADDITIONAL SECTION:
C.ROOT-SERVERS.NET.     3600000 IN      A       192.33.4.12
G.ROOT-SERVERS.NET.     3600000 IN      A       192.112.36.4
F.ROOT-SERVERS.NET.     3600000 IN      A       192.5.5.241
B.ROOT-SERVERS.NET.     3600000 IN      A       192.228.79.201
J.ROOT-SERVERS.NET.     3600000 IN      A       192.58.128.30
K.ROOT-SERVERS.NET.     3600000 IN      A       193.0.14.129
L.ROOT-SERVERS.NET.     3600000 IN      A       198.32.64.12
M.ROOT-SERVERS.NET.     3600000 IN      A       202.12.27.33
I.ROOT-SERVERS.NET.     3600000 IN      A       192.36.148.17
E.ROOT-SERVERS.NET.     3600000 IN      A       192.203.230.10
D.ROOT-SERVERS.NET.     3600000 IN      A       128.8.10.90
A.ROOT-SERVERS.NET.     3600000 IN      A       198.41.0.4
H.ROOT-SERVERS.NET.     3600000 IN      A       128.63.2.53

;; Query time: 99 msec
;; SERVER: 198.41.0.4#53(198.41.0.4)
;; WHEN: Thu Jul  6 08:00:26 2006
;; MSG SIZE  rcvd: 436
	

In the arda.homeunix.net.zone and 10.168.192.in-addr.arpa files, resource records for the host Ganymede were inserted by DHCP. Otherwise these files plus all other zone files were created by hand with one exception.

The named.root file was not created by hand but is instead the output of this dig query.

This command can be re-run periodically to ensure the list of root name servers is up to date. Root name servers don’t change very often so updating this file more than twice a year is probably overkill. Frequent updates also put undo load on the root name servers; they have enough to do as it is.

The arda.homelinux.net.zone file contains no A records. Its sole purpose is to identify the mail server, via the MX record, that mail addressed to the arda.homelinux.net domain should be sent to.

Manually Updating Zone Files

There are times when I’ve needed to manually update a zone file. Since Europa is the master name server, I always make the change on this machine and allow the normal zone transfer process to propogate the change to Io. Of course, because I have a slave name server and because I’m doing dynamic updates with DHCP, the process of making a change takes a few steps.

  1. Use rndc to stop BIND.
  2. Remove any .jnl files from the zone file directory.
  3. Edit the zone files as necessary. Make sure to increment the serial number of any file edited.
  4. Start BIND using its startup script.

If you need to edit zone files that are not subject to dynamic updates, then you don’t need to stop BIND. Edit the zone files remembering to increment their serial number and issue a reload command from rndc, simple as that. So long as you make your changes on a master name server, the reload command will take care of initiating any zone transfers that need to happen.

Running BIND Chrooted

On Europa, not only do I run BIND with reduced privileges, but it also runs in a chroot jail. Here is how I did it.

  1. The first thing to do was to decide where to put everything. I decided to create the directory /etc/namedb which would become BIND’s root.

  2. I needed to add a number of directories and files to namedb. Here is what things looked like after I was done.

      drwxr-xr-x    6 root     root         4096 Jan 19 20:13 /etc/namedb/
      drwxr-xr-x    2 root     root         4096 Jan 19 20:21 /etc/namedb/dev/
      crw-rw-rw-    1 root     root       1,   3 Jan 19 20:00 /etc/namedb/dev/null
      crw-r--r--    1 root     root       1,   8 Jan 19 20:21 /etc/namedb/dev/random
      drwxr-xr-x    2 root     root         4096 Jan 19 19:59 /etc/namedb/etc/
      -rw-r--r--    1 root     root         1267 Jan 19 19:54 /etc/namedb/etc/localtime
      -rw-r--r--    1 root     root         1592 Jul  5 16:38 /etc/namedb/etc/named.conf
      -rw-r-----    1 root     named         344 Jan 19 19:55 /etc/namedb/etc/rndc.key
      drwxr-xr-x    2 named    named        4096 Jan 19 19:56 /etc/namedb/master/
      -rw-r--r--    1 root     root          412 Jul  5 17:00 /etc/namedb/master/0.10.10.in-addr.arpa
      -rw-r--r--    1 named    named         803 Jul  5 16:56 /etc/namedb/master/10.168.192.in-addr.arpa
      -rw-r--r--    1 named    named        1460 Jul  5 16:56 /etc/namedb/master/10.168.192.in-addr.arpa.jnl
      -rw-r--r--    1 root     root          781 Jul  5 17:35 /etc/namedb/master/arda.homelinux.net.zone
      -rw-r--r--    1 named    named         797 Jul  5 16:57 /etc/namedb/master/arda.homeunix.net.zone
      -rw-r--r--    1 named    named        1460 Jul  5 16:57 /etc/namedb/master/arda.homeunix.net.zone.jnl
      -rw-r--r--    1 root     root          620 Jul  5 16:46 /etc/namedb/master/localhost.rev
      -rw-r--r--    1 root     root          619 Jul  5 16:46 /etc/namedb/master/localhost.zone
      -rw-r--r--    1 root     root          592 Jul  5 16:47 /etc/namedb/master/named.bind
      -rw-r--r--    1 root     root          551 Jul  5 16:48 /etc/namedb/master/named.broadcast
      -rw-r--r--    1 root     root          551 Jul  5 16:48 /etc/namedb/master/named.network
      -rw-r--r--    1 root     root         1516 Jul  6 08:00 /etc/namedb/master/named.root
      drwxr-xr-x    3 root     root         4096 Jan 19 20:14 /etc/namedb/var/
      drwxr-xr-x    2 named    named        4096 Jan 19 20:24 /etc/namedb/var/run/
      

    • The var/run directory is where BIND’s pid file will go.
    • Create the dev/null special file using the command 'mknod /etc/namedb/dev/null c 1 3'.
    • Create the dev/random special file using the command 'mknod /etc/namedb/dev/random c 1 8'.
    • When creating the special files with mknod, it’s a good idea to check the corresponding files in the /dev directory to make sure the major and minor numbers are correct. You want to use whatever the files in the /dev directory use.
    • The etc/localtime file is copied from /etc. This file ensures BIND uses the correct timezone in its log messages.
    • The arda.homeunix.net.zone and 10.168.192.in-addr.arpa zone files must be writable by the user named because they are dynamically updated by dhcpd. The two *.jnl files are owned by named when they are created by dhcpd.

  3. Before I started using log channels in named.conf, I needed to give BIND a way to send messages to syslog from within the chroot jail. To accomplish this, I modified one line in the file /etc/sysconfig/syslog.
      SYSLOGD_OPTIONS="-m 0"
          became
      SYSLOGD_OPTIONS="-m 0 -a /etc/namedb/dev/log"

    Stopping and starting syslog will cause a new syslog socket to appear in the /etc/namedb/dev directory. Since I use log channels now, I don’t do this step anymore.

  4. The last thing to do is modify BIND’s startup parameters to tell it to run in the jail. I did this by adding the following line to the /etc/sysconfig/named file.
      ROOTDIR="/etc/namedb"

Startup Scripts

I run BIND under the user and group 'named'. Here is what my /etc/rc.d/init.d/named startup script looks like. I needed to modify it so that it would look for binaries in /usr/local/sbin instead of /usr/sbin and to look for rndc.conf in /etc and not in the chroot jail.

Slave DNS Server

DNS configuration on Io follows closely that for Europa. The biggest differences come from the fact that Io is a slave name server and BIND on Europa must accommodate dynamic updates while it doesn’t on Io.

Configuration Files

Here are the ownership and permissions of the various configuration files.

File Name Owner Permissions
/var/named/etc/namedb/named.conf root:wheel 644
/var/named/etc/namedb/rndc.key root:bind 640
/var/named/etc/namedb/rndc.conf root:wheel 600
/etc/resolv.conf root:wheel 644

Here is my named.conf file.

This file looks a lot like my named.conf file on Europa but there are some differences.

Here is my rndc.conf file.

And here is my rndc.key file.

My /etc/resolv.conf file looks like this.

Zone Files

On Io, zone files live in the directories /etc/namedb/master and /etc/namedb/slave. The section that describes running BIND chrooted shows you what these directories look like.

Here are the nine zone files on Io.

Zone File Contents
bak.arda.homelinux.net.zone copied from Europa via automated zone transfer
bak.arda.homeunix.net.zone copied from Europa via automated zone transfer
bak.10.168.192.in-addr.arpa copied from Europa via automated zone transfer
bak.0.10.10.in-addr.arpa copied from Europa via automated zone transfer
localhost.zone
$TTL 1w
@        IN SOA europa.arda.homeunix.net. postmaster.arda.homeunix.net. (
                                        1       ; Serial
                                        6h      ; Refresh after 6 hours
                                        1h      ; Retry after 1 hour
                                        1w      ; Expire after 1 week
                                        1d )    ; Negative caching TTL of 1 day

                        IN      NS      europa.arda.homeunix.net.
                        IN      NS      io.arda.homeunix.net.

localhost.              IN      A       127.0.0.1
	
localhost.rev
$TTL 1w
@        IN SOA europa.arda.homeunix.net. postmaster.arda.homeunix.net. (
                                        1       ; Serial
                                        6h      ; Refresh after 6 hours
                                        1h      ; Retry after 1 hour
                                        1w      ; Expire after 1 week
                                        1d )    ; Negative caching TTL of 1 day

                        IN      NS      europa.arda.homeunix.net.
                        IN      NS      io.arda.homeunix.net.

1                       IN      PTR     localhost.
	
named.broadcast
named.network
$TTL 1w
@       IN SOA europa.arda.homeunix.net. postmaster.arda.homeunix.net. (
                                        1       ; Serial
                                        6h      ; Refresh after 6 hours
                                        1h      ; Retry after 1 hour
                                        1w      ; Expire after 1 week
                                        1d )    ; Negative caching TTL of 1 day

                        IN      NS      europa.arda.homeunix.net.
                        IN      NS      io.arda.homeunix.net.
	
named.bind
$TTL 1w
$ORIGIN bind.
@       CHAOS SOA europa.arda.homeunix.net. postmaster.arda.homeunix.net. (
                                        1       ; Serial
                                        6h      ; Refresh after 6 hours
                                        1h      ; Retry after 1 hour
                                        1w      ; Expire after 1 week
                                        1d )    ; Negative caching TTL of 1 day

                        CHAOS   NS      localhost.

version.bind.           CHAOS   TXT     "BIND 9.3.1"
authors.bind.           CHAOS   TXT     "Are at home at the ISC."	
	
named.root
; <<>> DiG 9.3.1 <<>> @a.root-servers.net . ns
; (1 server found)
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41586
;; flags: qr aa rd; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 13

;; QUESTION SECTION:
;.                              IN      NS

;; ANSWER SECTION:
.                       518400  IN      NS      F.ROOT-SERVERS.NET.
.                       518400  IN      NS      B.ROOT-SERVERS.NET.
.                       518400  IN      NS      J.ROOT-SERVERS.NET.
.                       518400  IN      NS      K.ROOT-SERVERS.NET.
.                       518400  IN      NS      L.ROOT-SERVERS.NET.
.                       518400  IN      NS      M.ROOT-SERVERS.NET.
.                       518400  IN      NS      I.ROOT-SERVERS.NET.
.                       518400  IN      NS      E.ROOT-SERVERS.NET.
.                       518400  IN      NS      D.ROOT-SERVERS.NET.
.                       518400  IN      NS      A.ROOT-SERVERS.NET.
.                       518400  IN      NS      H.ROOT-SERVERS.NET.
.                       518400  IN      NS      C.ROOT-SERVERS.NET.
.                       518400  IN      NS      G.ROOT-SERVERS.NET.

;; ADDITIONAL SECTION:
F.ROOT-SERVERS.NET.     3600000 IN      A       192.5.5.241
B.ROOT-SERVERS.NET.     3600000 IN      A       192.228.79.201
J.ROOT-SERVERS.NET.     3600000 IN      A       192.58.128.30
K.ROOT-SERVERS.NET.     3600000 IN      A       193.0.14.129
L.ROOT-SERVERS.NET.     3600000 IN      A       198.32.64.12
M.ROOT-SERVERS.NET.     3600000 IN      A       202.12.27.33
I.ROOT-SERVERS.NET.     3600000 IN      A       192.36.148.17
E.ROOT-SERVERS.NET.     3600000 IN      A       192.203.230.10
D.ROOT-SERVERS.NET.     3600000 IN      A       128.8.10.90
A.ROOT-SERVERS.NET.     3600000 IN      A       198.41.0.4
H.ROOT-SERVERS.NET.     3600000 IN      A       128.63.2.53
C.ROOT-SERVERS.NET.     3600000 IN      A       192.33.4.12
G.ROOT-SERVERS.NET.     3600000 IN      A       192.112.36.4

;; Query time: 86 msec
;; SERVER: 198.41.0.4#53(198.41.0.4)
;; WHEN: Mon May 15 00:01:43 2006
;; MSG SIZE  rcvd: 436
	

The zone files arda.homelinux.net.zone, arda.homeunix.net.zone, 10.168.192.in-addr.arpa, and 0.10.10.in-addr.arpa on Europa are copied to their corresponding 'bak.' files on Io so I won’t list them again here.

The localhost.zone, named.broadcast, named.network, and named.bind files were simply copied from Europa without modification.

FreeBSD provides the make-localhost script for creating the reverse localhost zone file. I didn’t use this script as I copied the localhost.rev file from Europa along with everything else.

As with Europa, the named.root file is the output of a dig command listing all the root name servers.

Running BIND Chrooted

As on Europa, on Io I run BIND with reduced privileges and in a chroot jail. There’s really nothing to doing this on FreeBSD as the startup script supplied with the OS does everything for you the first time you start the named process. In my case, all I needed to do was edit the existing named.conf file, copy zone files from Europa, and create the rndc.key, rndc.conf files and that’s it. The directory FreeBSD uses for its jail is /var/named. Here is what it looked like after I was done adding files and after the first zone transfer from Europa.

All the files and devices needed to run BIND in the jail automagically appear when named starts. Look at the section that describes running BIND in a chroot jail on Europa for an explanation of what these files and devices do.

Startup Scripts

To run BIND on system boot, put this line into /etc/rc.conf.

If you really want BIND’s chroot jail to reside in a different directory, you can add this line to /etc/rc.conf as well.

If you decide to do this, remember to copy the directory structure found in /var/named to your preferred chroot otherwise all that wonderful automation I talked about won’t work.

Did I mention that FreeBSD also configures BIND to run with reduced privileges as the user bind? There is no need for you to create the required user or set extra arguments for named yourself. Not bad, huh?

DHCP

When I built the DHCP package on Europa, I used a tarball instead on an rpm because I wanted to apply a patch which allows DHCP to run with reduced privileges and to be chrooted. You’ll find a link to this patch in the Software Home Sites section at the end of this document. It is called 'dhcp-3.0+paranoia.patch'. In order to use the features of this patch, you need to pass some options to configure when building DHCP so read the comments at the beginning of the file. Here are the options I used when building DHCP.

Configuration Files

Here is my dhcpd.conf file.

The dhcpd.conf file supplies all the information that will be given to DHCP clients and also controls dynamic updates with DNS servers. There are several points to note with this file.

Running DHCP Chrooted

Like BIND, I run DHCP with reduced privileges and in a chroot jail. The process to do this is similar to what I did for BIND but there are a few differences. Here is how I set up DHCP to run from the directory /etc/dhcpdb.

  1. The first thing to do was to create the user and group dhcpd would run as. Unlike BIND, I needed to do this manually. I chose the entirely predictable name 'dhcpd' for both user and group.

  2. I needed to add a number of directories and files to /etc/dhcpdb. Here is what things looked like after I was done.

      drwxr-xr-x    2 root     root         1024 Jul 17 10:12 /etc/dhcpdb/dev/
      crw-rw-rw-    1 root     root       1,   3 Jul 17 22:06 /etc/dhcpdb/dev/null
      crw-r--r--    1 root     root       1,   8 Jul 17 22:07 /etc/dhcpdb/dev/random
      drwxr-xr-x    2 root     root         1024 Jul 17 15:32 /etc/dhcpdb/etc/
      -rw-r--r--    1 root     root         1218 Jul 17 15:32 /etc/dhcpdb/etc/localtime
      drwxr-xr-x    4 root     root         1024 Jul 17 10:02 /etc/dhcpdb/var/
      drwxr-xr-x    2 dhcpd    dhcpd        1024 Jul 17 15:40 /etc/dhcpdb/var/run/
      drwxr-xr-x    3 root     root         1024 Jul 17 10:09 /etc/dhcpdb/var/state/
      drwxr-x---    2 dhcpd    dhcpd        1024 Jul 18 11:31 /etc/dhcpdb/var/state/dhcp/
      

    • The var/run directory is where DHCP’s pid file will go.
    • The var/state/dhcp directory is where the lease files will go.
    • Create the dev/null special file using the command 'mknod /etc/dhcpdb/dev/null c 1 3'.
    • Create the dev/random special file using the command 'mknod /etc/dhcpdb/dev/random c 1 8'.
    • As with BIND, the major and minor numbers for null and random are the same as the corresponding files found in /dev. I don’t know whether these files are actually necessary to run DHCP chrooted. dhcpd doesn’t complain when started without these special files present. I’ve put them in the jail more for insurance than anything else.
    • The etc/localtime file is copied from /etc. This file ensures DHCP uses the correct timezone when sending messages to syslog.
    • The var/run directory is owned by dhcpd:dhcpd. This is because the pid file is written after dhcpd has dropped privileges.

  3. I needed to give DHCP a way to send messages to syslog from within the chroot jail. To accomplish this, I modified one line in the file /etc/sysconfig/syslog.
      SYSLOGD_OPTIONS="-m 0"
          became
      SYSLOGD_OPTIONS="-m 0 -a /etc/dhcpdb/dev/log"

    Stopping and starting syslog will cause a new syslog socket to appear in the /etc/dhcpdb/dev directory.

  4. You’ll notice that dhcpd’s configuration file isn’t in the jail. It is located in /etc. Here is a listing of the file.
      -rw-------    1 root     root         1225 Jul 17 10:51 /etc/dhcpd.conf
      
    The dhcp-3.0+paranoia patch tells dhcpd to read dhcpd.conf before dropping privileges and invoking the chroot jail which is why the file is owned by root and is located outside the jail. I’ve set the permissions on this file to be restrictive because it contains the TSIG key used to dynamically update BIND. Having file permissions and ownership set up this particular way prevents the daemon from being able to modify the configuration file while still being able to read it at start up. Only a process with root privileges (presumably a sysadmin logged in as root) is able to modify the file.

Startup Scripts

Not only do I specify DHCP’s user, group, and chroot jail at startup, I also specify the particular interface DHCP listens on for requests. Here is my /etc/rc.d/init.d/dhcpd startup script. I modified this file, rather messily, to deal with DHCP running chrooted.

Software Home Sites

BIND
DHCP
http://www.isc.org/
dhcp-3.0+paranoia.patch
http://www.episec.com/people/edelkind/patches/

Further Reading

Bind9.net - An excellent source of DNS and DHCP information http://www.bind9.net/
DNS Group Webstart Page - Lots of links to DNS information http://www.the-paynes.com/DNS/
DNS Setup and Troubleshooting - Covers BIND version 8 http://www.troubleshooters.com/linux/dns.htm
Building and Running BIND 9 http://www.unixwiz.net/techtips/bind9-chroot.html
Secure BIND Template http://www.cymru.com/Documents/secure-bind-template.html

Copyright © 2003-2006 Andrew St. Jean Last update Jul. 06, 2006
Apache Webserver FreeBSD