Skip to content
induslevel.com
Menu
  • Home
Menu
automatic-ip-assignment

How to Install Simple DHCP Server in Centos 7

Posted on September 21, 2021October 10, 2021 by Waqar Azeem

DHCP server is used for automatic assignment of IP addresses to devices in a network. This article outlines the minimum steps to be performed on CentOS to setup DHCP server.

Assuming that you have freshly installed a machine with CentOS 7 ISO image and machine has been assigned a static IP address. I have attached two disk to this virtual machine. Disk 1 will be used for operating system. Disk 2 will be used for setting up local CentOS repositories later on.

Based on the recommendation of CIS benchmarking standards, I have allocated space to file systems according to following scheme.

Disk 1 of 80GB
Filesystem                   Size
/			    20 GB
swap			    4  GB
/boot                       1  GB
/tmp                        8  GB
/home                       15 GB
/var                        15 GB
/var/log                    14 GB
/var/log/audit              8  GB

Disk 2 of 60GB
Filesystem                   Size
/var/www/		    60 GB

Install and enable EPEL repository which provides packages for testing of dhcp server as well as monitoring tools like htop.

yum install epel-release -y

Update the system via yum. This will take some time if you are using older ISO image.

yum update -y

Once update is complete, we can reboot the system however, I would make changes at this point to disable Selinux.

sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config

Reboot the system

reboot

Install few of the helper tools. These are optional but can help you in quickly finding files and command completion.

yum install bash-completion mlocate -y && updatedb
source /etc/profile.d/bash_completion.sh 

Install DHCP package via yum.

yum install dhcp.x86_64 -y

Enable the required firewall access for dhcp service.

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

Reload the firewall to allow the incoming dhcp traffic.

firewall-cmd --reload

You can check the allowed ports and services using following command.

firewall-cmd --list-all

Enable the dhcp service on startup.

systemctl enable dhcpd.service

Copy/paste the following lines to setup sample configuration for dhcp server. This configuration is allowing those clients to get IP address from this dhcp server whose mac addresses are allowed and are assigned static IP address i.e. whenever the device with listed mac address ask for IP, it will always get same IP.

cat > /etc/dhcp/dhcpd.conf <<EOF
#------------------------------------------------------
authoritative;
default-lease-time 600;
max-lease-time 7200;
option domain-name-servers 8.8.8.8, 8.8.4.4;
option domain-name "induslevel.com";
option ntp-servers lhr-ntp1.induslevel.com,lhr-ntp2.induslevel.com;


subnet 172.16.99.0 netmask 255.255.255.0 {
        option broadcast-address 172.16.99.255;
        option routers 172.16.99.1;
        filename "/pxelinux.0";
        pool {
                range 172.16.99.150 172.16.99.230;
        }
group {
        next-server lhr-pxe1.induslevel.com;
        host tclient110 {
                hardware ethernet    00:0c:29:d3:a1:d1;
                fixed-address        172.16.99.110;
                option host-name "tclient110.induslevel.local";
        }
        host tclient120 {
                hardware ethernet    00:21:cc:6c:2e:42;
                fixed-address        172.16.99.120;
                option host-name "tclient120.induslevel.local";
        }

}
}
deny unknown-clients;

EOF

Start the dhcp service and check the status.

systemctl start dhcpd.service && systemctl status dhcpd.service

Following is the brief description of statement used in dhcpd.conf.

StatementDescription
authoritativeThis indicate that the DHCP server should send DHCPNAK messages to mis-configured clients
default-lease-timeThe time variable is the length in seconds that will be assigned to a lease if the client requesting the lease does not ask for a specific expiration time
max-lease-timeThe time variable is the maximum time in seconds that will be assigned to a lease
option domain-name-serversDNS servers available to the client
option domain-nameThe domain name that the client should use when resolving DNS hostnames
option ntp-serversLists IP addresses/hostname indicating NTP servers available to the client
subnetA subnet declaration is required for each subnet, even if no addresses will be dynamically allocated on that subnet
option broadcast-addressThe broadcast address in use on the client’s subnet 
option routersIP addresses for routers on the client’s subnet i.e. default gateway of the client
filenameThe name of the initial boot file that is to be loaded by a client (used for booting from network)
poolPool used for defining range of IP
rangeThe range  statement specifies the IP addresses that may be allocated to clients within a defined scope
groupThe group  scope may include individual hosts, shared networks, subnets, or even other groups
next-serverIt specifies the host address of the server from which the initial boot file is to be loaded
hostThe host keyword signifies that any following statements are to be applied to a unique host machine on the network
hardware ethernetMAC address of the client
fixed-addressThis statement assigns one or more fixed IP addresses to a client
option host-nameThe client’s name
deny unknown-clientsThis flag tells dhcpd not to dynamically assign addresses to unknown clients. 

To check if the dhcp server is assigning IP correctly, you can use nagios check_dhcp plugin available in EPEL repo.

yum install nagios-plugins-dhcp.x86_64 -y

If the dhcp server has IP address 172.16.99.254, then use following command.

/usr/lib64/nagios/plugins/check_dhcp -i ens192 -m 00:0c:29:d3:a1:d1 -s 172.16.99.254

In next article, we will configure tftp server which will provide initial booting files to network connected computer for unattended operating system installation and hardening.

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • More
  • Click to print (Opens in new window) Print
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Telegram (Opens in new window) Telegram
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to email a link to a friend (Opens in new window) Email

Related Articles

1 thought on “How to Install Simple DHCP Server in Centos 7”

  1. Tahir says:
    September 21, 2021 at 8:31 am

    Great job.

    Reply

Share your thoughtsCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Warning
Warning
Warning.

Recent Posts

  • Easiest Way to Setup WordPress and OpenConnect VPN Server using Ansible
  • How to use port 443 for SSH and OpenConnect VPN on Linux using HAProxy
  • How to Backup ZFS Snapshots to AWS Glacier
  • How to Install and Setup OpenConnect VPN Server on CentOS 7
  • How to Compile Kitty SSH Client from Source Code

Recent Comments

  1. Waqar Azeem on How to Install and Setup Kubernetes Cluster with Flannel CNI in CentOS 7
  2. Owais Khaleeq on How to Install and Setup Kubernetes Cluster with Flannel CNI in CentOS 7
  3. Muhammad Rizwan Latif on How To Setup 3-Node DynaTrace Managed Cluster on Centos/Redhat 7
  4. Waqar Azeem on How To Setup 3-Node DynaTrace Managed Cluster on Centos/Redhat 7
  5. Tahir on How to Install Simple DHCP Server in Centos 7

Archives

  • August 2024
  • February 2024
  • January 2024
  • July 2023
  • October 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021

Categories

  • Uncategorized
© 2025 INDUS LEVEL | Powered by Minimalist Blog WordPress Theme