Posted by tony on September 29, 2017

How to Install and Configure a DHCP Server on CentOS 7

In networked systems, Dynamic Host Configuration Protocol (DHCP) is pretty common. Despite being a mouthful of a term, the basic idea behind DHCP is pretty simple.


The DHCP server in a network maintains a list of possible IP addresses with it. As soon as a new device joins the network, it asks for an IP address with which to identify itself and let others identify it. This request is intercepted by the DHCP server and in response, it selects an IP address from the pool of available ones and assigns it to that device. At the same time, the new entrant is broadcast to the network, so that discovery and connectivity become possible.


The "Dynamic" in DHCP suggests that the IP address assigned to a new device will change each time it enters the network. This is in contrast to the concept of static IP address, where a machine is assigned a dedicated IP address which doesn't change. In other words, relying on an IP address in a DHCP environment is a bad idea.


Installing a DHCP server on CentOS 7


If you're a system administrator (or developer or power user), you might need to install and configure DHCP server on the host machine. We'll cover the configuration part later in this article, but for now let's focus on how to install DHCP server in the context of CentOS 7.


The first step, no surprises here, is to use the yum package manager to fetch and install the DHCP server. Fire up your favorite terminal client (or if you're already in a server environment, do nothing) and type the following command:


$ sudo yum install dhcp


If this seems alien, don't worry; here's a quick explanation. This simple command tells the 'yum' system installer (yes, it's a quirky name for an installer, but hey, the Linux world is full of quirks!) to search for the package called 'dhcp' and install it on your machine. The package manager then looks up the package among its standard list of repositories, and once found, proceeds to install it.


You might have to supply the root password (the one you use to log in to the system) next. After doing that, follow the simple instructions (mostly, confirming the download size) and dhcp server will be installed on your machine.


Note: (Very) slow yum installs


For some people who are new to the CentOS / RHEL / Fedora ecosystems, yum might seem painfully slow (well, it is painfully slow, in all honesty). After you type 'yum install dhcp' and hit Enter, it's not uncommon for the system to make you wait for several minutes before giving a response.


During this time, it might seem like you've done something wrong and the system is all frozen up. But relax, there's nothing of that sort going on. The yum package manager is just slow, and we need to live with that. Why yum is slow isn't in the scope of this article, but feel free to do your own research.


With this, the DHCP server is installed on your CentOS 7 machine. As per usual, it wasn't that hard to install stuff, right? Well, now comes the harder part: configuring DHCP.


Configuring DHCP Server on CentOS 7


For configuring DHCP server on CentOS 7, we need to modify a file that lives at /etc/dhcp/dhcpd.conf. Using your favorite text editor (again, the choices are limited when you're SSHed into a server, but we're assuming you know your way around), make the file look like this:


option domain-name "";

option domain-name-servers;

default-lease-time 600;

max-lease-time 7200;


subnet netmask {

    range dynamic-bootp;

    option broadcast-address;

    option routers;



Hmm, that might look intimidating to a few, so let's step through it line by line.


The first line specifies the domain name on which the DHCP server will be accessible. In the example, it is "", but in your case it will be your business domain. The next line tells us where to find the nameservers for this server. Here we can specify either domain name or IP address, but in the example, the nameserver is assumed to be living at



The next two lines are to deal with lease time, which is the time slot for which a device may own an IP. After that, the DHCP server invalidates the IP and returns it to the pool of available IPs. You can read more about lease times and other deep details in the DHCP protocol RFP: 


Finally, we come to the "authoritative" line, which tells the network that this DHCP server has the final say in resolution of IP addresses. For instance, if a device claims a particular IP address and there are multiple DHCP servers in a network, the one that is authoritative will have the last say in the matter.


The next block defines the subnet mask and broadcast address, which is pretty much standard for most networks.


With this, we've successfully configured the DHCP server we just installed on CentOS 7.


All that remains now is to fire up the server:


$ sudo systemctl start dhcp

$ sudo systemctl enable dhcp


With this, the DCHP service starts running on port 67 (UDP), which leads us to a final nuance.


Allowing DHCP service to go through firewall on CentOS 7


If there's a firewall configured on your machine, it won't allow the DHCP service to run. In this case, you need to add DHCP to the list of trusted services:


$ sudo firewall-cmd --add-service=dhcp --permanent

$ sudo firewall-cmd reload


This of course, assumes that you're using the provided firewalled tool, but it's easy to modify this example for your favorite firewall.


That was all! Now you've successfully set up a DHCP server on your machine.

Leave a Reply

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