Notes on dhcp3-server

For simple connection sharing from my Debian Etch box, I fetched the dhcp3-server package (the dhcp3 client is what’s used by default on Etch, so it seemed to make sense to pick the server package provided by the same maintainer). Context: my PC has a wired ethernet connection to the outside world, and a WiFi PCI card that allows the laptop to connect in ad-hoc mode.

Setup seems a bit daunting at first, because the man page for dhcpd.conf gives you a lot of information. There’s a wealth of examples in /etc/dhcp3/dhcpd.conf, too, which is great, but may not make things easy on first sight. So here’s the simplest thing you can do (I hope it helps to have a clear short example – from there on it actually becomes easier to see what else you can do – the man page is a wonderfully comprehensive resource):

option domain-name-servers,;
subnet netmask {
option routers;

On the first line, this specifies what DNS your DHCP clients are suggested to use, which can be a comma separated list – in a simple case, you’d specify your ISP’s DNS addresses (the zeroes I put in above are not really useful ;)). Then, you specify on which subnet your DHCP server should give out addresses (this is the subnet on which in my case the WiFi card is configured). Finally, “range” specifies which addresses it may assign (from 2 to 10 in this example) and “option routers” specifies what is in other places often called the gateway address (in my case, just the address of the desktop machine).

Something most people who run a DHCP server won’t run into, is that dhcpd needs restarting after a hibernate (or suspend) and resume cycle. As a home user, I don’t leave my desktop up over night. For now, I just open a console and type “sudo /etc/init.d/dhcp3-server restart” but I’ll figure out how to automate it sometime soon. I found a report of this issue on Launchpad, and I’ll look at the suspend/resume scripts they came up with to fix it.

Cooler things you could do with dhcp3-server include checking MAC addresses, so you only hand out IP addresses to known PCs. I didn’t bother to do that, because I use the maclist features of shorewall (which is a firewall configuration tool). So although anyone could in principle get an IP address from my server, the iptables rules don’t allow handling packets from any unknown PCs.


2 Responses to “Notes on dhcp3-server”

  1. 1 yungchin 4 March 2008 at 23:17

    Following up on the suspend/resume problem: I had a look at the current dhcp3-server package for Ubuntu: see here.

    That contains a fix, but apparently Ubuntu Hardy uses another package to handle suspend/resume than Debian Etch does by default: the scripts that were added to stop and start dhcpd are placed under /etc/acpi/suspend.d and resume.d – neither of these directories exist on my system…

    So I looked at the man pages for hibernate and hibernate.conf and figured out I needed to add OnSuspend and OnResume lines to /etc/hibernate/common.conf – but still no luck. For some reason, on resume dhcpd complains that the network interface isn’t up yet – even when I give dhcpd a very late starting point of “99” (the WiFi is brought down as specified in the same file common.conf with a DownInterfaces line but you can’t specify a 0-99 number for it’s priority).

    To be continued…

  2. 2 yungchin 5 March 2008 at 8:10

    * bangs head on desk *

    I misread man hibernate.conf: priority “99” is of course a high priority, which means the server gets started very early – before the network interface is up….

    So now I set it to “00” and it all works nicely. To be precise, the lines in /etc/hibernate/common.conf now read

    OnSuspend 99 invoke-rc.d –quiet dhcp3-server stop
    OnResume 00 invoke-rc.d –quiet dhcp3-server start

    Alternatively, you could probably use post-up and pre-down rules in /etc/network/interfaces.

Comments are currently closed.

%d bloggers like this: