You are on page 1of 8

Configuring Linux DHCP Server

Edmund Ochieng’ Ochieng’


Bsc. Computer Science
March 2, 2010

Abstract
This article is a guide on how to configure an ISCs(Internet Service
Consortium’s) DHCP server which ships with or is available for most
Linux systems.

1
Contents
1 INTRODUCTION 3
1.1 What is DHCP? . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Planning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2 CONFIGURATION 3
2.1 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Starting the server . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 Subsequent DHCP start up . . . . . . . . . . . . . . . . . . . . . 7

3 TROULESHOOTING 7
3.1 The 169.254.0.0 address . . . . . . . . . . . . . . . . . . . . . . . 8
3.2 Other DHCP failures . . . . . . . . . . . . . . . . . . . . . . . . . 8

2
1 INTRODUCTION
1.1 What is DHCP?
The Dynamic Host Configuration Protocol-widely known as DHCP, is a net-
working protocol that is used to issue an IP address and other configuration to
active network hosts.

DHCP assumes a client-server architecture. The DHCP client broadcasts a


request for configuration. The server receives the request and responds with a
valid address from its configuration database.

In the absence of DHCP, all network clients have to be manually configured


individually. A process thats not only time-consuming but also error-prone
escpecially in huge networks.

1.2 Planning
Network planning is a critical process that should be carried out before setting
up a new network or expanding an existing one. It helps ensure that the ne-
towrk can sustain the task for which it was intended. A good network plan
should consider growth, technology change, migration and new application de-
ployments.

A well planned network is cheap to construct and maintain. It is enhances


efficient use of network resources.

2 CONFIGURATION
In this section, we shall indulge into the configuration of ISC’s DHCP server
which bundles with a majority of Linux operation systems.

2.1 Configuration
Prior to starting, we shall confirm that the dhcp application is installed in our
intended DHCP server by using the RPM query command. The machine would
return the DHCP version installed in a new line if any. This is shown below:
[stuart@desert ~]$ rpm -q dhcp
dhcp-3.0.5-21.el5
[stuart@desert ~]$
Then, we proceed to view the default dhcp configuration which normally sits
in the /etc/ directory using the cat command; which accepts the file to view as
a parameter.
[stuart@desert ~]$ cat /etc/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample
#[stuart@desert ~]$

3
At this stage, we copy the sample configuration file from the location given
above to the /etc/ directory. We can confirm it is copied by using the cat
command again.

[stuart@desert ~]$ sudo cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf


[stuart@desert ~]$ cat /etc/dhcpd.conf
ddns-update-style interim;
ignore client-updates;

subnet 192.168.0.0 netmask 255.255.255.0 {

# --- default gateway


option routers 192.168.0.1;
option subnet-mask 255.255.255.0;

option nis-domain "domain.org";


option domain-name "domain.org";
option domain-name-servers 192.168.1.1;

option time-offset -18000; # Eastern Standard Time


# option ntp-servers 192.168.1.1;
# option netbios-name-servers 192.168.1.1;
# --- Selects point-to-point node (default is hybrid). Don’t change this unless
# -- you understand Netbios very well
# option netbios-node-type 2;

range dynamic-bootp 192.168.0.128 192.168.0.254;


default-lease-time 21600;
max-lease-time 43200;

# we want the nameserver to appear at a fixed address


host ns {
next-server marvin.redhat.com;
hardware ethernet 12:34:56:78:AB:CD;
fixed-address 207.175.42.254;
}
}
[stuart@desert ~]$

It is in the best of practice to backup the default configuration file before


altering it. It comes in handy when one messes up their configuration and they
opt to start all over again. This can be done as shown below:

[stuart@desert ~]$ cd /etc/


[stuart@desert etc]$ sudo cp dhcpd.conf dhcpd.conf.default
[stuart@desert etc]$

4
Finally, open and edit the default configuration file to suit your requirements.
My final configuration is shown below. Explanations for the configuration are
given hereafter.
[stuart@sandstorm ~]$ cat /etc/dhcpd.conf
1 | ddns-update-style interim;
2 | ignore client-updates;
3 |
4 | subnet 192.168.1.0 netmask 255.255.255.224 {
5 |
6 | # --- default gateway
7 | option routers 192.168.1.1;
8 | option subnet-mask 255.255.255.128;
9 |
10|
11| option nis-domain "sandstorm.org";
12| option domain-name "sandstorm.org";
13| option domain-name-servers 192.168.1.1;
14|
15| option time-offset 10800; # East African Time
16| # option ntp-servers 192.168.1.1;
17| # option netbios-name-servers 192.168.1.1;
18| # --- Selects point-to-point node (default is hybrid). Don’t change this unless
19| # -- you understand Netbios very well
20| # option netbios-node-type 2;
21|
22| range dynamic-bootp 192.168.1.10 192.168.1.30;
23| default-lease-time 21600;
24| max-lease-time 43200;
25|
26| # we want the nameserver to appear at a fixed address
27| host HPlaptop {
28| next-server dune.sandstorm.org;
29| hardware ethernet 00:16:d4:c0:9e:b0;
30| fixed-address 192.168.1.9;
31| }
32| }

Line 4, defines the network or rather subnetwork which has an address


192.168.1.0 and a netmask of 255.255.255.224. This restricts the size of the
network to 32 hosts-making 192.168.1.31 the broadcast address.

Line 7 defines the IP address to be used as the gateway of the network defined
above whereas Line 8 issues its netmaks address.

Line 12 defines the name of the domain that the hosts shall be assigned when
they recieve an reply from the DHCP server.

Line 15 gives the time offset from GMT which the server uses to manage
and log address leases. 10800 is an equivalent of 3 hours given in seconds (that

5
is, 3 x 60 x 60).

Line 18 gives the range of IP addresses to be issued dynamically. Here being


from 192.168.1.10 to 192.168.1.30, both boundaries included.

Line 23 & 24 define the default and maximum lease times(that is, length
of time it can use the same configuration) in seconds which are 6 hours and 12
hours respectively.

Keep in mind that all lines that commence with the hash or pound(#) sign
are comments.

2.2 Starting the server


Once we are done with the configurations, we need to start the DHCP server
daemon. However, there are a few things we need to do before starting the
DHCP server daemon,
First we need to ensure that the network interface card through which the
DHCP daemon shall serve is started and in the same network as those to be
issued by the DHCP server. In our case, the DHCP server will serve through
eth0.

[stuart@desert ~]$ /sbin/ifconfig eth0


eth0 Link encap:Ethernet HWaddr 00:19:66:C2:5B:61
inet addr:192.168.1.1 Bcast:192.168.1.31 Mask:255.255.255.224
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Interrupt:233

[stuart@desert ~]$

Once this is confirmed, we can start the DHCP daemon as shown below from
the command line.

[stuart@desert ~]$ sudo /sbin/service dhcpd start


Starting dhcpd: [ OK ]
[stuart@desert ~]$

If in doubt that the dhcp server is running, the command below may be used
which displays its process number-also known as PID, start time among others.

[stuart@desert ~]$ sudo /sbin/service dhcpd status


dhcpd (pid 4552) is running...
[stuart@desert ~]$

Or alternatively,

6
[stuart@desert ~]$ ps -aux | grep dhcp
Warning: bad syntax, perhaps a bogus ’-’? See /usr/share/doc/procps-3.2.7/FAQ
root 4552 0.0 0.1 7460 1260 ? Ss 20:44 0:00 /usr/sbin/dhcpd
stuart 4565 0.0 0.0 61160 728 pts/2 R+ 20:47 0:00 grep dhcp
[stuart@desert ~]$

Take note of the process IDs of the DHCP process in the two commands
executions above.

To view the which IP addresses has been given to a host, the following com-
mand can be executed on the terminal that acts as the DHCP server.

[stuart@desert ~]$ cat /var/lib/dhcpd/dhcpd.leases


# All times in this file are in UTC (GMT), not your local timezone. This is
# not a bug, so please don’t ask about it. There is no portable way to
# store leases in the local timezone, so please don’t request this as a
# feature. If this is inconvenient or confusing to you, we sincerely
# apologize. Seriously, though - don’t ask.
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-V3.0.5-RedHat

lease 192.168.1.9 {
starts 2 2010/03/02 17:56:17;
ends 2 2010/03/02 23:56:17;
binding state active;
next binding state free;
hardware ethernet 00:16:d4:c0:9e:b0;
}
[stuart@desert ~]$

As mentioned earlier, the DHCP server daemon uses its time in GMT. My
laptop was issues an IP address at 20:56:17 hours on March 2, 2010 which is
written as 2010/03/02 17:56:17.

2.3 Subsequent DHCP start up


To ensure that the DHCP server starts at boot up, process runs at

[stuart@desert ~]$ sudo /sbin/chkconfig --level 345 dhcpd on


[stuart@desert ~]$ /sbin/chkconfig --list dhcpd
dhcpd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
[stuart@desert ~]$

3 TROULESHOOTING
Most commmon DHCP problems arise from the DHCP clients rather than the
server. So, in the event that this occurs don’t change tour configuration yet,
unless the DHCP process in the server can’t start.

7
3.1 The 169.254.0.0 address
Microsoft windows DHCP clients assign themselves an address in the 169.24.0.0
network in the event that the DHCP server is unavailable or unreachable to
them. This will be until the server is accessible again. A condition normally
referred to as Automatic Private IP Addressing(APIPO). Here are some steps
to troubleshoot a DHCP client:

• Ensure that the DHCP process is running as described above.

• Ensure that no firewall block the BOOTP protocol used by DHCP. The
server recieves requests on UDP port 67 and return a reply to the client
on port 68.

• Ensure there is network connectivity between the server and a DHCP


client. Using ping to see if the server is accessible by the DHCP client
on issuing a static IP to the intended client from the same range that the
DHCP server would have issued.

3.2 Other DHCP failures


Most problems that result in initial DHCP process failure, are due to:

• Incorrect setting in /etc/dhcpd.conf. An example, is defining a range of


addresses to be issued via DHCP that are in a different network as the
defined network.

• Firewall that block BOOTP protocol on UDP ports 67 and 68.

• Routers that fail to forward DHCP configuration to client residing on a


seperate network.

Always check /var/log/messages for DHCP errors. You can also run tcpdump
on the NIC through which the DHCP process shall server its configuration.