• Recent blogs

    How to install a DHCP server in CENTOS, FEDORA and RHEL


    DHCP (Dynamic Host Configuration Protocol) is a network protocol that enables a server to automatically assign an IP address and provide other related network configuration parameters to a client on a network, from a pre-defined IP pool.

    This means that each time a client (connected to the network) boots up, it gets a “dynamic” IP address, as opposed to “static” IP address that never changes. The IP address assigned by a DHCP server to DHCP client is on a “lease”, the lease time can vary depending on how long a client is likely to require the connection or DHCP configuration.

    In this tutorial, we will learn how to install and configure a DHCP server in CentOS/RHEL and Fedora.

    Testing Environment Setup

    We are going to use following testing environment for this setup.

    How Does DHCP Work?

    Let’s discuss how DHCP actually works:

    When a client computer (configured to use DHCP) and connected to a network is powered on, it forwards a DHCPDISCOVER message to the DHCP server.

    And after the DHCP server receives the DHCPDISCOVER request message, it replies with a DHCPOFFER message.

    Then the client receives the DHCPOFFER message, and it sends a DHCPREQUEST message to the server indicating, it is prepared to get the network configuration offered in the DHCPOFFER message.

    When the DHCP server receives the DHCPREQUEST message from the client, and sends the DHCPACK message showing that the client is now permitted to use the IP address assigned to it

    Step 1: Installing DHCP Server in CentOS

    1. Installing DHCP is quite easy, simply run the command below.

    2. Open the file /etc/sysconfig/dhcpd, add the name of the specific interface to the list of DHCPDARGS, for example if the interface is eth0 , then add:

    Save the file and exit.

    Step 2: Configuring DHCP Server in CentOS

    3. To setup a DHCP server, the first step is to create the dhcpd.conf configuration file, and the main DHCP configuration file is normally /etc/dhcp/dhcpd.conf (which is empty by default), it keeps all network information sent to clients.


    However,there is another sample configuration file /usr/share/doc/dhcp*/dhcpd.conf.sample, which is a good starting point for configuring a DHCP server And, there are two types of statements available which define in the DHCP configuration file, these are:

    • parameters – state how to carry out a task, whether to perform a task, or what network configuration options to send to the DHCP client.
    • declarations – specify the network topology, define the clients, offer addresses for the clients, or apply a group of parameters to a group of declarations.

    Therefore, start by copying the sample configuration file as the main configuration file like so:

    4. Now, open the main configuration file and define your DHCP server options:Start by setting the following global parameters which will apply to all the sub networks (do specify values that apply to your scenario) at the top of the file:

    5. Now, define a subnetwork; in this example, we will configure DHCP for LAN network (remember to use parameters that apply to your scenario):

    Step 3: Assign Static IP to DHCP Client

    You can assign a static IP address to a specific client computer on the network, simply define the section below in /etc/dhcp/dhcpd.conf file, where you must explicitly specify it’s MAC addresses and the fixed IP to be assigned:

    Save the file and close it.

    Find out or display the Linux MAC address using following command.

    6. Now start the DHCP service for the mean time and enable it to start automatically from the next system boot, using following commands:

    7. Next, do not forget to permit DHCP service (DHCPD daemon listens on port 67/UDP) as below:

    Step 4: Configuring DHCP Clients

    8. Now, you can configure your clients on the network to automatically receive IP addresses from the DHCP server. Login to the client machine and modify the Ethernet interface configuration file as follows [Do not take of the interface name/number]:

    Add the options below:

    Save the file and exit.

    9. You can also perform the settings using the GUI on a desktop computer, set the Method to Automatic (DHCP) as shown in the screenshot below (Ubuntu 16.04 desktop).

                           Set DHCP in Client Network

     10. Then restart network services as follows (you can possibly reboot the system):

    After all the codes executed and if all settings were correct, Now your clients should be receiving IP addresses automatically from the DHCP server.

    No comments