Beginner’s guide for creating DHCP server
Hello Linux-fanatics, in this tutorial we will be creating DHCP server for our IT environment. It is an important service & is used in almost all organization with large number of users & also in homes with less number of users. So, actually what is it ?
It stands for Dynamic Host Configuration Protocol & it’s a network protocol that is used to automatically assign IP addresses to clients in an environment, from a predefined range of IP addresses. It save lots of time for sysadmin/network admin, as we don’t have to manually configure network in hundreds of machine, its all done automatically. It is wise to assign IPs automatically to normal clients but for critical servers, one should avoid using it & provide static IPs instead.
Now that we have an understanding, we will creating DHCP server on RHEL\CentOS machines.
(Recommended Read: Monitoring network bandwidth with iftop command)
To install DHCP, run the following command
That’s it. Installation is done & we will move on to configuration part
For configuring dhcp-server, there is a sample file (/usr/share/doc/dhcp-4.2.5/dhcpd.conf.example) that we will use. We will copy the file to ‘/etc/dhcp/dhcpd.conf’ which is the default location for the configuration file,
Next, open ’dhcpd.conf’ & edit the file, firstly we will add our domain details,
then we will specify the subnet & range of IP addresses to be used,
and save, exit the file. Our configuration for server are now complete, we will now restart our service to implement changes made to the configuration file.
Note:- For CentOS/RHEL 6, we have to make an additional change. We need to define which network interface will be used by dhcp. It will be defined in ‘/etc/sysconfig/dhcpd’, open the file
and add the following line to the file,
finally save the file & exit.
In order to test if our server is working or not, we will configure our client to receive IP address automatically. This is done by making changes in ‘/etc/sysconfig/network-scripts/ifcfg-eth1’
and we only have to change ‘BOOOTPROTO‘ to ‘dhcp‘ ,
finally restart network services on client machine & we should now have an IP address assigned to it automatically.
Reserving an IP address
We can also reserve an IP address for a particular machine i.e. suppose a testing machine is required to have same IP, we will reserve an IP address for it. To reserve an IP address, open configuration file ‘dhcpd.conf’ & add the following lines to it,
As you must have noticed, we will require Hardware or MAC address of the machine which we can easily get using ‘ifconfig -a’. Restart the service & the mentioned IP address will now be reserved for the Testing-machine.
That’s it guys, this was our article on creating DHCP server. Your queries & feedback is always welcomed. Please use our comment box below. Thank You.