Monday, 27 December 2010

HOWTO: DHCP Server On Ubuntu

For a Debian flavoured version of this post see this article


A working LAN where clients can ping each other from static IP address's. For more information on configuring a Debian or Ubuntu server with a static IP address see this article.

Login as root;

sudo -i

Setting up DHCP is a fairly simple affair. We start by installing dhcp-server from the repositories;

apt-get install dhcp3-server

We need to tell it which interface to listen for client requests on;

vi /etc/default/dhcp3-server

Add your (space separated) interface(s) like so;


There is a lot of useful documentation in the default configuration file, however this tends to make things a bit cluttered. I prefer a minimalist config file so we will backup the default one for future reference;

mv /etc/dhcp3/dhcpd.conf /etc/dhcp3/dhcpd.conf.default

Now, we create a new config file;

vi /etc/dhcp3/dhcpd.conf

Add the following contents, modifying as applicable for your own network of course;
default-lease-time 600;
max-lease-time 7200;

subnet netmask {
option subnet-mask;
option broadcast-address;
option routers;
option smtp-server;
option domain-name "";
option domain-name-servers,;

host earth {
hardware ethernet 00:1f:d0:c0:3b:9d;

I have added a fixed address for the host "earth" identified by MAC address 00:1f:d0:c0:3b:9d. This is for illustrative purposes only and can be removed if it is not needed.

The above example assumes you have DNS servers running on the your network on hosts and If you want to use upstream DNS resolvers enter the addresses for your ISP DNS servers instead. Alternately you can use the servers provided by OpenDNS[1] or configure your own DNS server.

To apply the changes, restart the dhcp server daemon;

service dhcp3-server restart

Now you should refresh the IP address on a PC configured as a dhcp client and you should receive a shiny new DHCP lease.

Now that you have a DHCP server, why not improve it by adding DDNS (Dynamic DNS) updates so that your clients names are automagically added to your DNS Server?

[1] OpenDNS use error redirects (DNS Hijacking) as a way to generate income. If you are like me and don't like such shenanigans then I recommend that you configure your own DNS server.

1 comment:

Dogears said...

These instructions are very easy to read and work up to 11.04 which has changed the location and names of the dhcp files.

Please check documentation specific for 11.04 and greater for correct procedure.