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 172.16.51.0 netmask 255.255.255.0 {
  option routers 172.16.51.1;
  option subnet-mask 255.255.255.0;
  option domain-search "pournader.com";
  option domain-name-servers 172.16.51.10;
  option time-offset -18000;
  range 172.166.51.11 172.16.51.100;
  }

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.