Configuring DHCP on Linux

Hello All

Today we are going to Configure both DHCP Server and DHCP Client. DHCP Server is used to provide Dynamic IP Addresses to Client PCs requesting the Service, DHCP provides it from a Pool of IP Addresses defined on the Server machine. so Lets get Started

Installing DHCP Server

Installation of DHCP Server is Simple, Just use Synaptic Manager or Add/Remove depending on your Distro or you can use command line

#yum install dhcp


apt-get install dhcp

Configuring DHCP Server:

1. To configure DHCP Server, you have to create a configuration file /var/dhcpd.conf and add required statements, An easy way to do it is to copy an existing Sample and modify it.

2. To do this go to /usr/share/doc/dhcp-4.2.0/ and copy the file dhcpd.conf.sample to /etc/ and rename it to dhcpd.conf.

3. Now Open the file with any of your Favorite Test editor, the configuration file is pretty self explanatory, you just make changes according to your need, e.g.

subnet netmask {
  option routers;

4. A little more complex example with Domain Name Server and also define the lease time

subnet netmask {
  option routers;
  option domain-name-servers;
  option subnet-mask;
  default-lease-time 21600;
  max-lease-time 432000;

5. You can also assign Static IP Address to a host e.g.

host waqar-laptop {
  hardware ethernet 00:50:8b:75:la:a3;

6. Once you are done with making changes, start the DHCP Service

#service dhcpd start
#chkconfig dhcpd on

7. If it fail to start, go ahead and create the lease database file for DHCP Server by using the command

#touch /var/lib/dhcp/dhcpd.leases

Configuring DHCP Client

1. By default your client will obtain IP from the DHCP Server, If this is not the case, you can run command the following command to obtain the IP

#dhclient (to obtain new IP)

#dhclient -r (to renew your IP)

2. In case if you wanna do it manually, edit /etc/sysconfig/network file and make sure that NETWORKING entry is set to YES, like


3. Then make sure that the file /etc/sysconfig/network-scripts/ifconfig-eth0 file contains the entries


4. Now restart the network service to reflect your changes

#service network restart

5. To check which IPs are assign to which system run the following command

#arp -a

There you have it, If you have any thoughts and questions, please leave it in the comment section.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s