Install and Configure DHCP on CentOS 7

By | December 22, 2014

In this post we will see how to Install and Configure DHCP on CentOS 7.  In short, a DHCP server provides IP addresses, to the clients in a network. The DHCP server offers IP address to the clients from a predefined pool of addresses. It may also be configured to reserve a specific IP address against the MAC address of a specific system/server, so that every time the system requests for an IP address, the DHCP server assigns the reserved IP address only. Apart from this, the DHCP server also provides the information to the clients regarding the gateway for external communication as well as the DNS server, which will do the name resolution. For more Information on DHCP, please click on this LINK.

Lets Install the dhcp package and setup a basic DHCP server.

[root@localhost ~]# yum install dhcp -y

Next, we will navigate inside the main DHCP configuration directory ‘/etc/dhcp‘ and modify the file ‘dhcpd.conf‘. Below is an example of how the file looks.

####Our basic DHCP example configuration
####Our Domain
option domain-name "example.org";
####The DNS servers for name resolution
option domain-name-servers 172.16.1.124;
####Our IP Lease time
default-lease-time 600;
max-lease-time 7200;
####Use this to enble / disable dynamic dns updates globally.
ddns-update-style none;
#### This DHCP server is the official DHCP server for the local network.
authoritative;
#### Use this to send dhcp log messages to a different log file (you also
#### have to hack syslog.conf to complete the redirection).
log-facility local7;
#### Our Subnet, IP address Pool and gateway/router
subnet 172.16.1.0 netmask 255.255.255.0 {
 range dynamic-bootp 172.16.1.10 172.16.1.253;
 option broadcast-address 172.16.1.255;
 option routers 172.16.1.254;
}
#### Lets reserve an IP address for an internal machine
#### make sure the IP used here is not defined in the IP POOL above
host vip {
 hardware ethernet 08:00:07:26:c0:a5;
 fixed-address 172.16.1.5;
}

Please note that my internal network address is 172.16.1.0/24. So my specifications in this file are pertaining to it. You will have put the information based on your own network. Now lets start the dhcp service

[root@localhost ~]# systemctl start dhcpd.service && systemctl enable dhcpd.service

Thats it…!!! Our BASIC DHCP server is ready. If any errors are present the configuration file, dhcp will fail to start.  It may happen if there are any typographical errors. In that case we have to recheck the ‘dhcpd.conf‘ and start the service again.

Every time this DHCP server leases out an IP address to any client, it will update the lease file. The lease file can be viewed with the following command.

[root@localhost ~]# less /var/lib/dhcpd/dhcpd.leases

 

Leave a Reply

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

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