Install & Configure DHCP server in Centos 5.X

What is DHCP?

DHCP is an acronym that stands for “Dynamic Host Configuration Protocol”. DHCP’s purpose is to enable individual computers on an IP network to automatically obtain their network configurations from a server, instead of requiring each PC’s network configuration to be completed manually. The overall purpose of this is to reduce the work necessary to administer a large IP network. DHCP runs over UDP, utilizing ports 67 and 68.

How do I setup DHCP on a RHEL clone like White Box Enterprise Linux (WBEL), CentOS, or TaoLinux?

1. Do the above mentioned minimal install, if required.

2. After updating your linux install, install the programs required for the DHCP server with this command:

yum install dhcp

Important Files:
To configure a DHCP server we will modify the configuration file /etc/dhcpd.conf. DHCP also uses the file /var/lib/dhcp/dhcpd.leases to store the client lease database.

Help for DHCP
Help is available from the following man pages:

man dhcp-eval
man dhcpd.conf
man dhcpd.leases
man dhcpd
man dhcrelay

3. Next we need to configure the DHCP server. First we need to know some information that we are going to assign. We need to know:

a. The range of IP addresses we want to assign to our computers. I normally use the 192.168.x.x networks for my internal LANs. In our example, we will use as our network (that is the network that starts with and ends with We will save IPs to for servers and static addresses. We will pick the addresses to to assign to computers via DHCP.

b. The IP address of the DNS server(s) we will use for name lookups for our clients that we assign with DHCP. In my case, I will use the DNS server that I have setup on IP address (You can use your ISP’s DNS server if you don’t have one … see the ISP’s site for details. You can also build your own internal DNS server on this machine or another internal machine by following this guide.

c. The Default Gateway of the computers that we are going to serve. In our example, this will be the IP address, which has been setup as the default gateway for our internal network.

d. The length of the lease (default and maximum). This is very subjective. If you have more PCs than IP addresses to give out, you want this to be a short time (600 seconds). If you have more IPs to give out than PCs (most likely the case), you can use a larger number. Microsoft defaults to 3 days (259200 seconds) with their DHCP servers. RedHat recommends 12 hours (43200 seconds). I will go with the RedHat default of 43200 seconds for default length and 86400 seconds for maximum length.

e. If we have a WINS server setup on the network (microsoft or samba only), we would need to know it’s IP address. I have one, it is (on the same machine as my DNS server).

f. We need a domain name to give out as well. If you are using real IP addresses, you can use a real domain name as well … in our case, we are using an internal network (192.168.0.x) behind a single IP address from an ISP, so we will use the fictitious domain name home.local. If you are using an internal IP network, don’t use a real external domain name, or you may not be able to talk to real PCs on that external network.

The DHCP Server configuration file (/etc/dhcpd.conf)

1. Now we have our information, so let’s configure the server by creating a text file named /etc/dhcpd.conf. The first line in the file must be the DNS update scheme. There are 2 choices, but only one that works reliably … so we will use that one smile.gif. Here is the first line:
ddns-update-style interim;

2. The second line is whether to allow the DHCP to update client info to a Dynamic DNS server. In our example, we are not going to try and update a Dynamic DNS via our DHCP server, so we will not allow client updates. Here is our line 2:
ignore client-updates;

3. The next section of our file will be the subnet section … we will define the network, and input the info we gathered above (see section 3 {a-f} above). Here is the subnet section:
subnet netmask {
option routers; #Default Gateway
option subnet-mask;
option domain-name “home.local”;
option domain-name-servers;
option netbios-name-servers; #WINS Server
range dynamic-bootp; #DHCP Range to assign
default-lease-time 43200;
max-lease-time 86400;

NOTE: Change your IP as per your network.

4. Put all that together and we have the /etc/dhcpd.conf file. Here is a text file containing our example information.

example dhcpd.conf

5. If you have more than one ethernet adapter, you must specify which one to listen on in the file /etc/sysconfig/dhcpd. To listen on eth0, you would use the line:

6. To start the dhcp server now for testing, issue the command:

/etc/init.d/dhcpd start

To make the dhcp server restart at boot time, issue the commands:

chkconfig –level 2345 dhcpd on
chkconfig –level 016 dhcpd off

Then check to make sure it is correct with the command:

chkconfig –list dhcpd

the output should be

dhcpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

7. If you are using a software firewall like iptables, you will need to allow all tcp and udp traffic into ports 67 and 68 into this machine.

8. Here are some good references:

DHCP Server Setup (some paths are different, but still good info)

RHEL – Configuring a DHCP Server <–Excellent Reference!

Using DHCP on Linux/FreeBSD <–Info on Dynamic DNS and DHCP

TCP/IP Network Administration – DHCP


make[2]: nasm: Command not found
[root@localhost syslinux-4.02]# yum search nasm
================================================================================================ Matched: nasm ================================================================================================
nasm.i386 : A portable x86 assembler which uses Intel-like syntax.
nasm-doc.i386 : Documentation for NASM.
nasm-rdoff.i386 : Tools for the RDOFF binary format, sometimes used with NASM.

[root@localhost syslinux-4.02]# yum install nasm.i386 nasm-doc.i386 nasm-rdoff.i386

Post a comment or leave a trackback: Trackback URL.


  • I like the helpful information you supply in your articles.
    I will bookmark your weblog and test again right here frequently.
    I am relatively sure I’ll be told plenty of new stuff proper right here!
    Good luck for the following!

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 )

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

%d bloggers like this: