top of page
Recent Posts

How to Install a DHCP Server in Red Hat Enterprise Linux 7

Writer's picture: Munshi Hafizul HaqueMunshi Hafizul Haque

Updated: Oct 3, 2021

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.


There are a lot of use cases for the DHCP service. Let install and configure the DHCP services:

Step1: To Install DHCP server packages

# yum -y install dhcp

Step2: Copy the sample configuration file to /etc/dhcp directory DHCP server

# rpm -qd dhcp
/usr/share/doc/dhcp-4.2.5/dhcpd.conf.example
/usr/share/doc/dhcp-4.2.5/dhcpd6.conf.example
/usr/share/doc/dhcp-4.2.5/ldap/README.ldap
/usr/share/doc/dhcp-4.2.5/ldap/dhcp.schema
/usr/share/doc/dhcp-4.2.5/ldap/dhcpd-conf-to-ldap
/usr/share/man/man1/omshell.1.gz
/usr/share/man/man5/dhcpd.conf.5.gz
/usr/share/man/man5/dhcpd.leases.5.gz
/usr/share/man/man8/dhcpd.8.gz
/usr/share/man/man8/dhcrelay.8.gz
# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf 

Step3: To edit the /etc/dhcp/dhcpd.conf configuration file

# cat /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#

authoritative;
ddns-update-style interim;
default-lease-time 14400;
max-lease-time 14400;

# Specify Default Gateway
	option routers                  192.168.122.1;
	option broadcast-address        192.168.122.255;
	option subnet-mask              255.255.255.0;
# Specify DNS server ip and additional DNS server IP address
	option domain-name-servers      192.168.122.254;
# Specify Domain Name
	option domain-name              "lab.munshibari.biz";
       option domain-search "ocp4.lab.munshibari.biz","lab.munshibari.biz";

# Configuring subnet and IP address range
	subnet 192.168.122.0 netmask 255.255.255.0 {
     	pool {
        	range 192.168.122.111 192.168.122.119;
# Static entries for servers
	 host bootstrap1 { hardware ethernet 52:54:00:95:32:cc; option host-name "bootstrap1.ocp4.lab.munshibari.biz"; fixed-address 192.168.122.115; }

# this will not give out addresses to hosts not listed above static entries
	#	deny unknown-clients;

# this will give out addresses to hosts not listed above static entries
		allow unknown-clients;

# this is PXE specific  
		filename "pxelinux.0";  
		next-server 192.168.122.254;
     	}
}
The man dhcpd.conf: command will help you to understand more on dhcpd.conf file that contains configuration information for dhcpd service.

Step4: To start the dhcpd service and make it start automatically on system reboot

# systemctl restart dhcpd
# systemctl is-active dhcpd
active

# systemctl enable dhcpd
# systemctl is-enabled dhcpd
enabled

Troubleshooting:

1. If Firewalld service is running in the system, we need to open the firewall port in the system to accept the incoming request at the DHCP server.

# firewall-cmd --add-service=dhcp --permanent
# firewall-cmd --reload

2. If SELinux service is enabled with enforcing mode, and any issues in restarting the DHCP service due to file context.

# restorecon -v /etc/dhcp/dhcpd.conf
And man dhcpd.leases or tailf /var/lib/dhcpd/dhcpd.leases command to verify the DHCP client lease database.

Hope this post will help.

Comments


Log In to Connect With Members
View and follow other members, leave comments & more.

JazakAllah© 2020. All Rights Reserved

keep growing your community bigger, Keep your IT knowledge up-to-date.

  • LinkedIn
bottom of page