Linux DHCP Server

Dynamic Host Configuration Protocol (DHCP) is a network protocol that automatically assigns TCP/IP information to client machines. Each DHCP client connects to the centrally located DHCP server, which returns the network configuration (including the IP address, gateway, and DNS servers) of that client.

How DHCP works ?

linux dhcp how work


01. Installing DHCP :
yum -y install dhcp

The configuration file is /etc/dhcp/dhcpd.conf and it may be empty.
The sample configuration file can be found at /usr/share/doc/dhcp-<version>/dhcpd.conf.sample. You should use this file to help you configure /etc/dhcp/dhcpd.conf.

DHCP also uses the file /var/lib/dhcpd/dhcpd.leases to store the client lease database.

02. Run DHCP service :
systemctl enable dhcpd
systemctl start dhcpd
systemctl status dhcpd

It may NOT work unless we edit the configuration file correctly , Don’t worry , just continue .

03. Open Firewall Port :
firewall-cmd --permanent --add-service=dhcp
firewall-cmd --reload
04. Define a subnet :

Edit the configuration file to provide DHCP service for specific IP subnet or range, for example :

To define a subnet of with netmask of , append the following :

subnet netmask {


Then you should define the allowed range from this subnet (example from 50 to 150 IP) :

subnet netmask {

range ;


You can add options as you need,

If you add option inside subnet definition , it will affect only this subnet.
If you define options outside subnet definitions , it will affect all subnet definitions.

the syntax is :

option  option-name  argument;

To define gateway or router IP :

option routers;

To define DNS servers :

option domain-name-servers;

To define domain search :

option domain-search “”;

You may search for more options as you need, for example to setup a PXE server , you will setup DHCP with more options, read this

Any configuration line inside a subnet definition must end with ” ; .

Example :

vim /etc/dhcp/dhcpd.conf
subnet netmask {
        option routers        ;
        option subnet-mask    ;
        option domain-search              "";
        option domain-name-servers;
        option time-offset              -18000;     # Eastern Standard Time

Now Restart dhcpd service , and test it.

systemctl restart dhcpd

For more examples:

vim /usr/share/doc/dhcp*/dhcpd.conf.example

where * represent the package version.

That is it, i hope it was simple, thanks for joining me.
Enjoy !.





Comments are closed.