Install and Configure DHCP Server on CentOS 7/6/5 Linux Systems

undefined

In this post, we will show you how to install and configure a dhcp server on Linux systems (RPM Family “Redhat /CentOS /Scientific Linux 7/6/5”). As a system administrator you will need to setup a dhcp server to assign IPs to all laptops/machines for employees to work inside your network.

DHCP ( Dynamic Host Configuration Protocol ) is a network protocol used for assigning IP address to network clients dynamically from predefined IP pool. It is useful for LAN network, but not generally used for production servers. This article will help you for Configuring DHCP Server on CentOS, Red Hat Systems.

Our installation and configuration will be in 3 main steps and 2 extra steps. So let’s start.

Step 1: Install the DHCP Server’s Package.

We will use yum package manager to install the DHCP package  on  our CentOS 7/6/5,  DHCP rpms are available under base repositories, so we don’t need to add extra repository. Only one command for the three release of CentOS/Redhat 7/6/5.

# yum -y install dhcp.x86_64

Step 2: Configure the DHCP Server.

DHCP creates an empty configuration file /etc/dhcp/dhcpd.conf. Also it provides a sample configuration file at /usr/share/doc/dhcp*/dhcpd.conf.sample, which is very useful for configuring the DHCP server.

So as a first part, copy content of sample configuration file to main configuration file. Sample configuration file may be changed as per version you have installed on your system, run the following command:

# cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf 
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y

Now, we will edit the dhcpd.conf with our network parameters.

# vim /etc/dhcp/dhcpd.conf

Now, we will change the following parameters. For simplicity, I separated them into three blocks:

2.1 – Parameter Configuration

First configure the basic options which is common to all supported networks.

  option domain-name "mimastech.com";
  option domain-name-servers 8.8.8.8, 8.8.4.4;
  default-lease-time 28800;
  max-lease-time 36000;
  authoritative;
  log-facility local7;

2.2 – IP Subnet Declaration

First edit dhcp configuration file and update subnet details as per your network. For this example we are configuring DHCP for 192.168.1.0/24 LAN network.

subnet 192.168.1.0 netmask 255.255.255.0 {
        option routers                  192.168.1.1;
        option subnet-mask              255.255.255.0;
        option domain-search            "mimastech.com";
        range   192.168.1.100   192.168.1.254;
}

2.3 -Assign Static IP Address to Host

In some cases we need to assign a fixed ip to an interface each time it requested from dhcp. We can also assign a fixed ip on basis of MAC address (hardware ethernet) of that interface. Setup host-name is optional to set up.

host vip {
   option host-name "vip.mimastech.com";
   hardware ethernet 00:13:1A:2B:AE:CD;
   fixed-address 192.168.1.99;
}

Step 3: Enable and Start DHCP Service

After making all above changes, let’s enable and start dhcp service using following commands as per your operating system version.

  • For CentOS/RHEL 7
# systemctl enable dhcpd 
# systemctl start dhcpd
  • For CentOS/RHEL 6/5
# chkconfig dhcpd on 
# service dhcpd start

Extra Steps:

Step 4: Setup Client System

At this stage we have a running dhcp server which is ready for accepting requests and assign them a proper ip. but to verify I have another CentOS machine running on same LAN. Now login to that client machine and edit Ethernet configuration file.

# vim /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
BOOTPROTO=dhcp
TYPE=Ethernet
ONBOOT=yes

Make sure BOOTPROTO is set to dhcp.

Let’s restart network services on client system. You will get that dhcp server assigned an ip address from defined subnet. If you have connected to client pc from remote login, Your session can be disconnect.

  • For CentOS/RHEL 7
# systemctl restart network
  • For CentOS/RHEL 6/5
# service network restart
Hints: 	
1. By default dhcp server is listening to the first NIC card which is eth0 "in most CentOS/Redhat Linux"
2. To change the dhcp server to listen to another NIC interface you need to edit /etc/sysconfig/dhcpd

Step 5: Updating  /etc/sysconfig/dhcpd File

As I said in the above hint, according to your internal LAN infrastructure, you may want the dhcp server to listen on another NIC interface. To do that, you need to set ethernet interface name as DHCPDARGS in /etc/sysconfig/dhcpd file. Edit this configuration file and update the ethernet name.

 DHCPDARGS=eth1

Here’s we changed the dhcp server to listen on connections coming to eth1. We must restart the dhcp service for our changes to take effect.

If You Appreciate What We Do Here On Mimastech, You Should Consider:

  1. Stay Connected to: Facebook | Twitter | Google+
  2. Support us via PayPal Donation
  3. Subscribe to our email newsletters.
  4. Tell other sysadmins / friends about Us - Share and Like our posts and services

We are thankful for your never ending support.

Leave a Reply

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