Saturday, May 9, 2015

Running DHCP Server in CentOS / RHEL 7

To install DHCP server: 
# yum install dhcp
DHCP config file is located at /etc/dhcp/ directory so if you want to take a quick look you can run: 
# cat /etc/dhcp/dhcpd.conf
:) Yep. It is almost full of empty by default! As it says the sample config file can be found in /usr/share/doc/dhcp*/dhcpd.conf.example so easily copy it over the above-mentioned location: 
# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
Now, it is a good a time to take a look: 
# less /etc/dhcp/dhcpd.conf
Very simple DHCP config file can be as small as:

  subnet netmask {
  option routers;
  option subnet-mask;
  option domain-search "";
  option domain-name-servers;
  option time-offset -18000;

Now dhcp daemon is ready to start. Let’s start dhcp service:
# systemctl start dhcpd.service 
To enable dhcpd to start at boot time:
# systemctl enable dhcpd
Note 0: The rpm package name is dhcp but the daemon is dhcpd. 

Note 1: DHCP service will only listen on interfaces for which it finds a subnet declaration in the /etc/dhcp/dhcpd.conf file (if the server has more than one interface)

Note 2: DHCP uses the /var/lib/dhcpd/dhcpd.leases file to store the lease database so if you want to show dhcp clients, open dhcpd.leases file. 

Note 3: Instead of changing a DHCP config file and then restarting the service, using omshell tool is an interactive way to connect to a dhcp server, query, and change the configurations of a DHCP server while the server is running.