Little Service

The versatile Raspberry Pi can serve many roles on a home network. We'll show you how to set up the Pi to provide some important network services.

The tiny US$ 35 Raspberry Pi computer [1] is gaining attention around the world as an education tool and a plaything for hobbyists. But, many users are discovering that the Rasp Pi can do real, practical things for a small network. After all, the Raspberry Pi is a real Linux computer, complete with an Ethernet port and USB ports.

The system is admittedly light on resources – with only 512MB memory and file storage on an SD card, but for simple tasks that aren't too resource-intensive, the Pi performs well. The fact that the Pi runs with very low power usage and hardly takes up any space are actually benefits in some scenarios, especially on home networks with little space and low demand.

This article describes how to set up the Raspberry Pi to perform a few common network services, including:

IP address allocation with DHCP

Time Service with NTP

Name service with Bind9

DHCP service is often performed by a home router or through the ISP's own DHCP server. However, DSL routers are sometimes overwhelmed with the task of managing a medium-sized home network, and they sometimes don't support a full range of DHCP services, such as assignment of fixed IP addresses.

Assigning IP addresses with a Raspberry Pi might seem like an improbable solution, but, in some cases, you might find it actually performs better than leaving this task to your home router. And anyway, at a minimum, you get some experience configuring network services, and you'll learn more about your Pi along the way.

A DNS server might seem even more improbable, because you have most likely gotten by just fine up until now without using a Raspberry Pi for name resolution, but this little exercise in network configuration shows the Pi at its best: a versatile tool that lets you experiment and explore without a lot of complication or risk. (See the box titled "Home DNS" for a look at some possible benefits.)

Home DNS

Name resolution on your own server is more than three times faster than resolution by external DNS servers, mainly because repeat requests can be answered from the internal cache instead of querying DNS servers on the Internet. To demonstrate this, consider the following experiment.

Multiple queries through Google's name servers required the following time profile:

Of course, all of this takes place for a single name resolution within milliseconds and is therefore not of practical importance for a home network. However, it does illustrate the potential benefits of an internal name server. Another benefit of a home DNS server is that it gives you one central point for managing host names on your network.

In this case, note that the local network occupies a private, non-routable address range (192.168.100…), which is mapped to the Internet address space through Network Address Translation (NAT). The use of DNS with NAT complicates this solution if you want the DNS server to be accessible from beyond the network.

You might be wondering how this DNS server will map names to IP addresses if the IP addresses are dynamically assigned through DHCP. Of course, dynamic DNS is available for mapping permanent host names to temporary IP addresses. For the purposes of this simple configuration, I will configure the DHCP server to assign a fixed address to the client based on the MAC address.

Static IP Address

The Rasp Pi needs a static IP address to work as a DHCP server. You can start by determining which address the DSL router has assigned to the Rasp Pi (Listing 1).You can use the route command to determine the default gateway (the address of the DSL router; see Listing 2 for example).

All the network addresses look like this: 192.168.100.x (or a.b.c.x, if the output was a.b.c.d). The DSL router address must not be assigned to any other device. I'll configure the Rasp Pi to use 192.168.100.2 as a permanent address by configuring a static address in /etc/network/interfaces (Listing 3).

Configuring NTP on the Rasp Pi

In the Raspbian image, which you can download from the Internet, NTP is already installed. However, if you want to use the Pi as a time server, you might want to change the different servers to the NTP pool defined in the config file. You need to edit the /etc/ntp.conf file and add servers to the NTP pool (see Listing 4).

You will find more information online [2]. In Listing 4, I have commented out the Debian time servers and added more servers in my home country to the NTP server pool.

I still need to negotiate a minor obstacle. If the IP address is retrieved via DHCP (which was the case until I convert to the static IP address), the time server configuration is not read from the /etc/ntp.conf file but from /var/lib/ntp/ntp.conf.dhcp. Things will stay this way as long as this file exists in the /var directory.

The time server registered in this file was the one assigned by the DHCP server, typically the address of the DSL server. First, make sure the static IP address is active (after changing /etc/network/interfaces, reboot your Rasp Pi – sudo init 6). Then, delete /var/lib/ntp/ntp.conf.dhcp, and again reboot your Rasp Pi. After a couple minutes, you can use the following:

ntpq -p

to check the configuration of the time server. The resulting output is shown in Listing 5.

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 locale, 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).

Buy Linux Magazine

Related content

Admins have waited all of five years for the 10th major release of the Bind name server, which appeared at the end of March this year. The latest release is a complete rewrite of the DNS server, with a modular design and new configuration tools, but is it ready for business?