Setting up Raspberry Pi as a DHCP, NTP, and DNS server

Installing the Name Server

The Bind9 (Berkeley Internet name service) package is responsible for name resolution. Bind9 is pretty easy to install with apt-get. You need to make sure your Rasp Pi has a large enough SD card (4GB or more, or preferably 16GB). Additionally, you should install the DNS-utils to provide useful commands, such as nslookup and dig. A check with nslookup shows that the Rasp Pi is still using the DSL server as its master, so I need to modify /etc/resolv.conf. You can find directories of free name server addresses online. For my location, I found name servers through sites such as http://www.freie-nameserver.de/ or http://www.ungefiltert-surfen.de/nameserver/de. I can then enter these name servers in the /etc/resolv.conf file (Listing 6).

Listing 6

Configuring resolv.conf

01 fritz@raspberrypi ~ $ sudo apt-get install bind9
02 fritz@raspberrypi ~ $ sudo apt-get install dnsutils
03 nslookup www.telekom.de
04 Server:         192.168.100.2
05 Address:        192.168.100.2#53
06 Non-authoritative answer:
07 Name:   www.telekom.de
08 Address: 217.150.151.99
09
10 fritz@raspberrypi ~ $ sudo vi /etc/resolv.conf
11 domain homenet.de
12 search homenet.de
13 nameserver 127.0.0.1
14 nameserver 194.187.164.20
15 nameserver 193.158.224.9
16 nameserver 80.239.175.131
17 nameserver 80.239.207.176
18 nameserver 212.211.132.4
19 nameserver 212.43.68.10
20 nameserver 81.209.130.140
21 nameserver 213.30.253.65
22 nameserver 141.2.1.3
23
24 fritz@raspberrypi ~ $ nslookup www.telekom.de
25 Server:         127.0.0.1
26 Address:        127.0.0.1#53
27 Non-authoritative answer:
28 Name:   www.telekom.de
29 Address: 217.150.151.99

The Local Zone

To understand the names of the devices on my own network, I need to add a local zone. First, I add the line listen-on port 53 {any;}; to /etc/bind/named.conf.options, and reference to the zone files in /etc/bind/named.conf.local. I then create the zone files with the names and IP addresses of all the devices on the home network (Listing 7), as well as the associated reverse zone file (Listing 8). The dots in lines like homenet.de. are important. If the dot is missing at the end, the system appends the domain name (homenet.de), and then the name no longer matches.

Listing 7

Zone File /etc/bind/zone.homenet.de

01 // Do any local configuration here
02 //
03 // Consider adding the 1918 zones here, if they are not used in your
04 // organization include "/etc/bind/zones.rfc1918";
05 //
06 //
07 zone "homenet.de"
08 {
09 type master ;
10 file "/etc/bind/zone.homenet.de" ;
11 } ;
12 //
13 zone "0.100.168.192.in-addr.arpa"
14 {
15 type master ;
16 notify no ;
17 file "/etc/bind/zone.0.100.168.192.in-addr.arpa" ;
18 } ;
19 References to the zone files are added to /etc/bind/named.local.
20 $TTL 2d
21 @               IN SOA          pi.homenet.de.    root.pi.homenet.de. (
22                                 2013080701      ; serial
23                                 3h              ; refresh
24                                 1h              ; retry
25                                 1w              ; expiry
26                                 1d )            ; minimum
27
28 homenet.de.     IN NS           pi.homenet.de.
29 vectra          IN A            192.168.100.1
30 fhserver        IN A            192.168.100.2
31 fritz-pc        IN A            192.168.100.50
32 fpc-wlan        IN A            192.168.100.51
33 andrey-laptop   IN A            192.168.100.52
34 andrey-lap-wire IN A            192.168.100.53
35 lena-laptop     IN A            192.168.100.54
36 lena-lap-lan    IN A            192.168.100.55
37 frlap-wlan      IN A            192.168.100.56
38 frlap-lan       IN A            192.168.100.57
39 andrey-pc       IN A            192.168.100.58
40 fritz-ipad      IN A            192.168.100.59
41 andrey-gpad     IN A            192.168.100.60
42 fritz-phone     IN A            192.168.100.61
43 andrey-phone    IN A            192.168.100.62
44 sony-tv         IN A            192.168.100.63
45 screenplay      IN A            192.168.100.64
46 pioneer-av      IN A            192.168.100.65
47 printserver     IN A            192.168.100.66
48 wlan-router     IN A            192.168.100.67
49 pioneer-bd      IN A            192.168.100.68
50 fritz-vmlinux   IN A            192.168.100.69
51 fritz-vm98      IN A            192.168.100.70
52 fritz-vmdos     IN A            192.168.100.71
53 noxon           IN A            192.168.100.72
54 pi              IN A            192.168.100.73

Listing 8

The "Reverse" Zone File

01 $TTL 2d
02 @               IN SOA          pi.homenet.de.    root.pi.homenet.de. (
03                                 2013080703      ; serial
04                                 3h              ; refresh
05                                 1h              ; retry
06                                 1w              ; expiry
07                                 1d )            ; minimum
08
09 100.168.192.in-addr.arpa.       IN NS           pi.homenet.de.
10 1.100.168.192.in-addr.arpa.     IN PTR          vectra.homenet.de.
11 2.100.168.192.in-addr.arpa.     IN PTR          fhserver.homenet.de.
12 50.100.168.192.in-addr.arpa.    IN PTR          fritz-pc.homenet.de.
13 51.100.168.192.in-addr.arpa.    IN PTR          fpc-wlan.homenet.de.
14 52.100.168.192.in-addr.arpa.    IN PTR          andrey-laptop.homenet.de.
15 53.100.168.192.in-addr.arpa.    IN PTR          andrey-lap-wire.homenet.de.
16 54.100.168.192.in-addr.arpa.    IN PTR          lena-laptop.homenet.de.
17 55.100.168.192.in-addr.arpa.    IN PTR          lena-lap-lan.homenet.de.
18 56.100.168.192.in-addr.arpa.    IN PTR          frlap-wlan.homenet.de.
19 57.100.168.192.in-addr.arpa.    IN PTR          frlap-lan.homenet.de.
20 58.100.168.192.in-addr.arpa.    IN PTR          andrey-pc.homenet.de.
21 59.100.168.192.in-addr.arpa.    IN PTR          fritz-ipad.homenet.de.
22 60.100.168.192.in-addr.arpa.    IN PTR          andrey-gpad.homenet.de.
23 61.100.168.192.in-addr.arpa.    IN PTR          fritz-phone.homenet.de.
24 62.100.168.192.in-addr.arpa.    IN PTR          andrey-phone.homenet.de.
25 63.100.168.192.in-addr.arpa.    IN PTR          sony-tv.homenet.de.
26 64.100.168.192.in-addr.arpa.    IN PTR          screenplay.homenet.de.
27 65.100.168.192.in-addr.arpa.    IN PTR          pioneer-av.homenet.de.
28 66.100.168.192.in-addr.arpa.    IN PTR          printserver.homenet.de.
29 67.100.168.192.in-addr.arpa.    IN PTR          wlan-router.homenet.de.
30 68.100.168.192.in-addr.arpa.    IN PTR          pioneer-bd.homenet.de.
31 69.100.168.192.in-addr.arpa.    IN PTR          fritz-vmlinux.homenet.de.
32 70.100.168.192.in-addr.arpa.    IN PTR          fritz-vm98.homenet.de.
33 71.100.168.192.in-addr.arpa.    IN PTR          fritz-vmdos.homenet.de.
34 72.100.168.192.in-addr.arpa.    IN PTR          noxon.homenet.de.
35 73.100.168.192.in-addr.arpa.    IN PTR          pi.homenet.de.

If you are interested in more details of BIND configuration, the content of the files presented here, and the importance of each entry, I recommend the DNS & BIND Cookbook [3]. If you want to completely immerse yourself in the functionality of the domain name service, I recommend DNS & BIND [4].

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content