Never Ending Security

It starts all here

Installation and configuration of Linux DHCP Server

For a cable modem or a DSL connection, the service provider dynamically assigns the IP address to your PC. When you install a DSL or a home cable router between your home network and your modem, your PC will get its IP address from the home router during boot up. A Linux system can be set up as a DHCP server and used in place of the router.

DHCP is not installed by default on your Linux system. It has to be installed by gaining root privileges:

$ su –

You will be prompted for the root password and you can install DHCP by the command:

# yum install dhcp

Once all the dependencies are satisfied, the installation will complete.


You will need root privileges for enabling, starting, stopping or restarting the dhcpd service:

# systemctl enable dhcpd.service

Once enabled, the dhcpd services can be started, stopped and restarted with:

# systemctl start dhcpd.service
# systemctl stop dhcpd.service
# systemctl restart dhcpd.service

or with the use of the following commands if systemctl command is not available:

# service dhcpd start
# service dhcpd stop
# service dhcpd restart

To determine whether dhcpd is running on your system, you can seek its status:

# systemctl status dhcpd.service

Another way of knowing if dhcpd is running is to use the ‘service‘ command:

# service dhcpd status

Note that dhcpd has to be configured to start automatically on next reboot.


Depending on the version of the Linux installation you are currently running, the configuration file may reside either in /etc/dhcpd or/etc/dhcpd3 directories.

When you install the DHCP package, a skeleton configuration file and a sample configuration file are created. Both are quite extensive, and the skeleton configuration file has most of its commands deactivated with # at the beginning. The sample configuration file can be found in the location /usr/share/doc/dhcp*/dhcpd.conf.sample.

When the dhcpd.conf file is created, a subnet section is generated for each of the interfaces present on your Linux system; this is very important. Following is a small part of the dhcp.conf file:

ddns-update-style interimignore client-updates

subnet netmask {

# The range of IP addresses the server

# will issue to DHCP enabled PC clients

# booting up on the network


# Set the amount of time in seconds that

# a client may keep the IP address

default-lease-time 86400;

max-lease-time 86400;

# Set the default gateway to be used by

# the PC clients

option routers;

# Don’t forward DHCP requests from this

# NIC interface to any other NIC

# interfaces

option ip-forwarding off;

# Set the broadcast address and subnet mask

# to be used by the DHCP clients

option broadcast-address;

option subnet-mask;

# Set the NTP server to be used by the

# DHCP clients

option ntp-servers;

# Set the DNS server to be used by the

# DHCP clients

option domain-name-servers;

# If you specify a WINS server for your Windows clients,

# you need to include the following option in the dhcpd.conf file:

option netbios-name-servers;

# You can also assign specific IP addresses based on the clients’

# ethernet MAC address as follows (Host’s name is “laser-printer”:

host laser-printer {

hardware ethernet 08:00:2b:4c:59:23;





# List an unused interface here


subnet netmask {


The IP addresses will need to be changed to meet the ranges suitable to your network. There are other option statements that can be used to configure the DHCP. As you can see, some of the resources such as printers, which need fixed IP addresses, are given the specific IP address based on the NIC MAC address of the device.

For more information, you may read the relevant man pages:

# man dhcp-options


When a PC with DHCP configuration boots, it requests for the IP address from the DHCP server. For this, it sends a standard DHCP request packet to the DHCP server with a source IP address of A route has to be added to this address so that the DHCP server knows on which interface it has to send the reply. This is done by adding the route information to the/etc/sysconfig/network-scripts/route-eth0 file, assuming the route is to be added to the eth0 interface:


# File /etc/sysconfig/network-scripts/route-eth0
# dev eth0

After defining the interface for the DHCP routing, it has to be further ensured that your DHCP server listens only to that interface and to no other. For this the /etc/sysconfig/dhcpd file has to be edited and the preferred interface added to the DHCPDARGS variable. If the interface is to be eth0 following are the changes that need to be made:

# File: /etc/sysconfig/dhcpd



Using the netstat command along with the -au option will show the list of interfaces listening on the bootp or DHCP UDP port:

# netstat -au  | grep bootp

will result in the following:

udp     0         0         *:*

Additionally, a check on the /var/log/messages file will show the defined interfaces used from the time the dhcpd daemon was started:

Feb  24 17:22:44 Linux-64 dhcpd: Listening on LPF/eth0/00:e0:18:5c:d8:41/
Feb  24 17:22:44 Linux-64 dhcpd: Sending on  LPF/eth0/00:e0:18:5c:d8:41/

This confirms the DHCP Service has been installed with success and operating correctly


Leave a Reply

Please log in using one of these methods to post your comment: Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s