Contact for queries :


  UpComing Live WebEx Workshop Series

DHCP Server Configuration in Linux ( RHEL5/6)

One of the basics elements found on all networks is a Dynamic Host Configuration Protocol (DHCP) server, making it an important part of any network. DHCP makes network administration easy because you can make changes to a single point (the DHCP server) on your network and let those changes filter down to the rest of the network.

Before you can begin the installation or setup of a DHCP server, you need to verify that the server is configured with a static IP address. To verify this, you can look at the interface config file:

# cat /etc/sysconfig/network-scripts/ifcfg-eth1
NAME=”System eth1”

Before you configure your Server as DHCP server, please make sure that you server already had configurted with a static IP address, however, if you have been following along in all the labs. With your static IP in hand, you can begin the installation of the DHCP server.

Task 1: Installing a DHCP Server

Step 1. Start by installing the dhcp package:

# yum install -y dhcp

Step 2. Verify that the package is installed correctly:

# rpm -qa | grep dhcp

Step 3. With the package installed, make sure that the dhcpd service starts when the system boots as well:

# chkconfig dhcpd on

Step 4. Verify that the DHCP service starts on boot:

# chkconfig dhcpd –list
dhcpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

Task 2: Configuring the DHCP Server

To start the configuration, let’s look at the important files that handle the options for the DHCP service:

  • /etc/dhcp/dhcpd.conf Main config file for the DHCP service using IPv4 addresses
  • /etc/dhcp/dhcpd6.conf Main config file for the DHCP service using IPv6 addresses
  • /var/lib/dhcpd/dhcpd.leases IPv4 client lease file
  • /var/lib/dhcpd/dhcpd6.leases IPv6 client lease file

MIGRATION TIP : In RHEL5, the location of the main config file was /etc/dhcpd.conf. Now in RHEL6, the config file has been moved into a directory (/etc/dhcp) because there are additional config files for IPv6 addresses.

The main config file is usually empty aside from a comment or two. The good news is that the package does provide a sample config file for you to use. This sample file provides examples and comments on how you can configure options for your DHCP server.

To copy the sample file, use the following command:

# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhc/dhcpd.conf

If you are new to working with DHCP servers, this sample file will prove helpful in that the comments included in the file explain the different options. The following sample config file gives you the basics to get started. It is less cluttered than the sample, so it is easier to explain.

Here is the sample DHCP server config file:

# Global Options
ddns-update-style none;
# Subnet definition
subnet netmask {
# Parameters for the local subnet
option routers;
option subnet-mask;
option domain-name “”;
option domain-name-servers;
default-lease-time 21600;
max-lease-time 43200;
# Client IP range
range dynamic-bootp;

Let’s break down this file into sections. The first section contains two options for the DHCP server itself, also called global options:

REAL-WORLD TIP : If the server doesn’t contain an authoritative option and the client switches subnets,
it is not able to obtain a new IP address until its old lease has fully expired. There are also security benefits of sending a DHCPNAK to incorrectly configured clients.

The next section defines a subnet. Any options that you list in a subnet section are specific to the subnet for which you define them. If you want to set global options (such as authoritative), you need to define them outside the subnet section. In this section, the following options are used:

  • option routers    Defines the default gateway to the subnet
  • option subnet-mask Defines the subnet mask for the subnet
  • option domain-name Defines the name of the domain
  • option domainname-servers   Defines the DNS server for the subnet
  • ddns-update-style:none This means that the DHCP server won’t update client DNS records.
  • authoritative  This informs the client that the DHCP server contains legitimate information.
  • default-lease-time Specifies how long each client keeps its lease until a renewal is requested (in seconds)
  • max-lease-time  Specifies the maximum amount of time a client can keep a lease (in seconds)
  • range dynamic-bootp  Specifies the range of IP addresses that can be given out to clients

With a config file in place, you have everything you need for the DHCP server to function properly.

Although this section does not describe anywhere near all the options available for the DHCP service, this is a good start to getting a DHCP server up and running. For the exams, you can always reference the documentation if you forget the name of an option.

Although I hate pointing you to man pages, it is impossible to remember everything for every service. Knowing where to find information when you need it is critical on the exams and in the real world. Here are the three man pages you should know:

# man dhcpd.conf
# man dhcpd.leases
# man dhcp-options

If you want to have multiple subnets, you can just define a new subnet section with its own set of options. There is no limit to the number of sections you can have.

REAL-WORLD TIP : If you want to set up multiple subnets, you usually have multiple interfaces on the
server. If this is the case and you would like to service multiple subnets of clients, you need to adjust the /etc/sysconfig/dhcpd file. In this case, you need to edit the following daemon option:


Change this option to include all the interfaces for which you want to offer clients leases in different subnets. If you have two interfaces in two different subnets, for example, your option might look like this:

DHCPDARGS=”eth0 eth1”

The options we’ve covered so far are really all you need to set up your DHCP server to work. Even though the DHCP server is set to run, there is another example to consider. It is common in the real world to have to reserve an IP address for a particular client. If you don’t want to make the IP address of the client static, you can reserve it instead on the DHCP server. Reservations are common when dealing with printers on networks, but they can be used for clients, too. Here is how you define a reservation for a client.

In your /etc/dhcpd.conf file, do the following:

host client01 {
option host-name “”;
hardware ethernet 02:B4:7C:43:DD:FF;

Again, let’s look at each of these options and what they do. These three options are defined in a host subsection, just like you defined a subnet section earlier. With the config files in place, you are now ready to start the service.

The DHCP server offers a particularly nice feature built into the startup scripts; it can check the syntax of your config file for errors. This capability is nice because prior to actually starting the service, you can check to make sure nothing is set incorrectly.

Check the config file for any errors:

# service dhcpd configtest
Syntax: OK

If the DHCP service does find errors, it attempts to tell you where in the config file the error exists. Open your config file and remove the brace (}) that ends the subnet section. Save your config file and run the syntax check on your config file again:

# service dhcpd configtest
Internet Systems Consortium DHCP Server V3.0.5-RedHat
Copyright 2004-2006 Internet Systems Consortium.
All rights reserved.

For info, please visit line 18: unexpected end of file
Configuration file errors encountered — exiting

Here, the service points out that the } is missing from the config file by giving you the line where the issue occurs as well as a general description of what the problem is. Now replace the } again and restart the DHCP service:

# service dhcpd start
Starting dhcpd: [ OK ]
Verify that the service is running:

# service dhcpd status
dhcpd (pid 3366) is running…

Please refer below links for further knwoledge on DHCP

Securing DHCP server using  Firewall

Troubleshooting DHCP related issues

November 16, 2015

0 responses on "DHCP Server Configuration in Linux ( RHEL5/6)"

Leave a Message

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


IGURKUL I.T. Training Hub offering various Career Certification courses in Computer Networking, Unix, Linux, Cloud Computing and DevOps Technologies. With its rich experience in IT training service sector, iGURKUL has been able to set Industry best practices in IT Training for the past five years.

In Past five years, more than 5000 professionals have been trained by iGURKUL for System administration, Cloud Computing and DevOps Skill set through our Online Training portal And , each day , more than 10000 working professionals from all over the globe visiting our knowledge base for the best practices and Knowledge learning.

copyright protected - 2011 © igurkul I.T. solutions. All rights reserved.