RaspberryPi as DHCP Server

Configuring the Raspberry Pi as a DHCP Server under Raspbian Wheezy
(© Kenneth A Spencer)

1. Introduction

The Dynamic Host Configuration Protocol (DHCP) enables any of the computers on your local area
network (LAN) to be given a network configuration automatically as soon as the boot process on the
machine gets underway. Most routers are capable of this function.
This function can also be carried out by a server computer, although almost any of your computers can
fulfil the rôle. The other computers which are configured to take advantage of this service are called
DHCP Clients, and need to have their networking setup configured to use DHCP.

These instructions apply to the Raspbian Wheezy distribution for the Raspberry Pi – other distributions
differ in their detailed implementations.

The information which can be passed from your DHCP Server to its clients includes:
– a suitable IP Address, either permanently or leased for a defined period;
– the address of your router (aka gateway);
– an address of one or more Domain Name Servers (DNS) within or outwith your LAN or both.
Note that there are two versions of IP addresses in current use. In this document we refer exclusively to
version 4 addresses which comprise four octets separated by a full stop e.g.

2. Installation

To install the Debian DHCP Server login as root and type the following command:
apt-get install isc-dhcp-server
The DHCP Server software will be obtained and installed. You may receive an error when the DHCP
Server first attempts to run, but this will be resolved after configuration is completed.

3. Configuration

The configuration file for the Debian DHCP server is /etc/dhcp/dhcpd.conf. This file will
require editing so as to reflect your LAN setup. Start the editing process with nano as follows:
nano /etc/dhcp/dhcpd.conf

You must insert into the file settings appropriate to your network. We have divided the settings into
sections. Locate the lines given, and comment out the existing settings by placing a hash symbol (“#”) at
the start of the line. Then retype the lines using the text given.

Your local Domain Name:
option domain-name “your_domain.your_lan”
An example would be my_domain.local.

Domain Name Server(s):
option domain-name-servers,,
Enter the IP Addresses of one or more DNS servers. Do not use the addresses given above, rather use
the correct options for your own LAN! If you have a DNS service for machines on your LAN, enter the
server IP address. Your remote DNS Server will be supplied by your ISP, or you can use public DNS
Services such as Google’s, which are at and
Note that if you do not have a local DNS service, you will need to enter the names of all computers and
their IP addresses into each of your computer’s /etc/hosts file instead.
Subnet, Net Mask, and Router Addresses
subnet netmask
{ range;
option routers;
} ;
The subnet and netmask are IP values required for assisting communications across your LAN.
Your numbers will almost certainly be different:
– subnet: you can obtain the IP Address of a computer on your LAN using the Linux ifconfig
command. Take the Inet Addr value and replace its final octet with a zero to get your subnet;
– netmask: the value given above should be fine for your netmask;
– range: this is the range of IP Addresses (from – to) for serving to clients by this DHCP Service.
If you have more than one DHCP Server on your LAN ensure that their ranges do not overlap;
– option routers: this provides the IP Address of your router (aka gateway). You can obtain the
router IP Address using the route -n command and take the top entry in the gateway column.

Save your changes to the file with [Ctrl]+O and exit nano with [Ctrl]+X.

Restart the DCHP Service so that it will load your new settings:
service isc-dhcp-server stop
service isc-dhcp-server start
A message such as
[ ok ] Starting ISC DHCP SERVER dhcpd
with no error reported indicates that all is well.

4. Advanced configuration

Assigning a fixed address
To assign a fixed address, e.g. to a particular machine, e.g. “node100″, add the
following lines to the DHCP configuration file:
host node100
{ hardware ethernet A6:B6:C6:D6:E6:F6;
} ;
The number A6:B6:C6:D6:E6:F6 is the so-called MAC Address of the Ethernet interface (network
adapter) of the machine which you wish to name node100. It provides a hardware reference on the
client for the server to use in network communications.
You can find the MAC Address(es) of the Ethernet interface(s) on any computer using the ifconfig
command. The MAC Address is on the same line as the Ethernet Interface Number (e.g. Eth0) and is
labelled “HWaddr”. (In Windows, the command is ipconfig.)
Note: if you wish to have your DHCP Server award a fixed IP Address it should be one outside the
DHCP normally assigned range of IP Addresses.

5. Which DHCP Server Served your IP Address?

As it is not unusual to have more than one DHCP Server on a LAN (you probably already have your
router setup as a DHCP Server) you can see where your current machine’s IP Address lease has come
from using the command:
cat /etc/var/lib/dchp/dhclient.eth0.leases.

[Note: you may use this document freely. However, please ensure that you leave the Author name on
the first and last pages, and that you pass on the document only in its entirety.]

End of document: © Kenneth A Spencer, v20130327

There are 1 comments for this article
  1. Colin Wray at 21:19

    I did this on Raspian jessie running hostapd hotspot on wlan0, and found I had to set INTERFACES=”wlan0″ in file /etc/default/isc-dhcp-server before it would work.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>