Kemp’s Blog

A technical blog about technical things

Simple DHCP Server Setup

In this post I will discuss a simple way to set up a DHCP server for a small network. By “small network” in this case I mean examples such as a home network with a few machines on, or a group of Gumstix devices communicating with a PC over BNEP PAN connections. If you’ve read my previous posts then you’ll know that the latter is my main interest, and that anything I say here is based on my use of Ubuntu. Originally, I was going to talk about the use of gadmin-dhcpd from the Gadmin set of tools, but in the end I decided that manual configuration isn’t actually hard enough to warrant a graphical tool (for my purposes at least).

So with the niceties over with, let’s get going. First you need to install dhcp3-server if you haven’t already:

sudo apt-get install dhcp3-server

This should create files at /etc/default/dhcp3-server and /etc/dhcp3/dhcpd.conf. We will look at each of these in turn.

Open up /etc/default/dhcp3-server in your favourite editor (in this case Emacs):

sudo emacs /etc/default/dhcp3-server

This file controls the interfaces on which the server will listen for requests. The final line will currently read something like INTERFACES="". Your list of interfaces should be space-separated identifiers. In the case here of a small Gumstix network (assuming you have set up bridging previously, either manually or via Blueman), you want to change the line to read INTERFACES=“pan0”. Your bridge may be pan1 or some other number, use the ifconfig command to find it. That is all the configuration needed in that file, so close it now.

The next file to edit is /etc/dhcp3/dhcpd.conf, which controls the configuration of what addresses are assigned, what range they are assigned from, etc. Open this file as above:

sudo emacs /etc/dhcp3/dhcpd.conf

This file is likely to have more content than the previous, but don’t worry about that for now. Any options you specify in a moment will override existing global options. Let’s consider again the case of the Gumstix network. In my case the subnet in use is 192.168.2.0/24, and a PC is acting as the DHCP server at 192.168.2.1. There is only one more thing you need to decide for the simplest case – what range of addresses to use. In this example we will use 192.168.2.100 to 192.168.2.200. To allow this, the following should be added to the end of the configuration file:

subnet 192.168.2.0 netmask 255.255.255.0 {
interface pan0;
range 192.168.2.100 192.168.2.200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option routers 192.168.2.1;
}

You may also add lines between the braces to control the lease time, address of DNS servers, etc. These aren’t necessary for our example, but maybe you have a more complex system:

default-lease-time 600;
max-lease-time 7200;
option domain-name-servers 192.168.2.10, 192.168.2.11;
option domain-name "somedomain.example";

In addition to assigning a block of IP addresses on request, you may also specify that certain devices should always be assigned a particular address. For instance, maybe one Gumstix device is used to resolve DNS requests:

host dns-stix {
hardware ethernet AB:CD:EF:12:34:56:78;
fixed-address 192.168.2.10;
}

Again, this may only be useful in more complex systems, but the capability is there.

Once all your configuration is complete, restart the DHCP server software and relax in the glow of auto-assigned IP addresses:

sudo /etc/init.d/dhcp3-server restart

I hope this has given you what you need to explore the options in more detail. The following pages may be useful for more information:

I noticed on another blog that suspend/hibernate requires the DHCP server to be restarted on resume, this probably won’t be a problem for most of you and I don’t know if this occurs in current versions, just a heads up in case you need to know.