How does Centos8 configure a DHCP server

System environment


Install DHCP

The address of the DHCP server is, and the default gateway is The DHCP server will automatically assign IP addresses to other devices in the network

The following is the address information of the DHCP server:

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens160 

To install the DHCP service:

[root@localhost ~]# dnf -y install dhcp-server

Configure DHCP service

The main configuration file of DHCP server is / etc / DHCP / DHCP pd.conf. By default, there are only comments in the file. You can refer to the / usr / share / Doc / DHCP server / dhcpd.conf.example file to modify the configuration.

The configuration information is provided directly below. Paste the configuration information into the dhcpd.conf file and modify the address and other information:

[root@localhost ~]# cat /etc/dhcp/dhcpd.conf 
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp-server/dhcpd.conf.example
#   see dhcpd.conf(5) man page
default-lease-time 600;
max-lease-time 7200;
ddns-update-style none;
subnet netmask {
  option routers;
  option subnet-mask;
  option domain-name-servers;


Default leave time reserves an IP address for a specific device for 10 minutes (600 seconds)

Max leave time can retain IP addresses for up to 2 hours (7200 seconds).

The subnet section defines the DHCP configuration of the network.

The range section defines the assignable IP addresses, ranging from to

The routes section defines the address of the default gateway.

The subnet mask section defines the subnet mask that will be assigned to each host.

The domain name servers section defines the DNS server address that will be assigned to each host. After configuration, you can use the following command Start dhcp service:

[root@localhost ~]# systemctl enable dhcpd && systemctl start dhcpd
Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/dhcpd.service.

Check whether the service is running:

[root@localhost ~]# systemctl status dhcpd

Configure firewall

If you enable the firewall, you need to release the dhcp service in the firewall.

[root@localhost ~]# firewall-cmd --permanent --add-service=dhcp
[root@localhost ~]# firewall-cmd --reload

Client test

Got the address on the client:

Check whether is the address assigned by this DHCP server on the client:

[root@localhost ~]# nmcli connection show ens33 |grep -i 'dhcp4.option\[4\]'
DHCP4.OPTION[4]:                        dhcp_server_identifier =

You can see that the dhcp server identifier is

Set reserved IP

First, you need to know the network card address of the server that needs to set the reserved ip address. At the client, use ip link to view the mac address of the network card:

[root@localhost ~]# ip link 

Next, on the DHCP server, edit the / etc / DHCP / dhcp.conf configuration file and add the following content. The bound address is

host server {
  hardware ethernet 00:0c:29:99:ee:d9;

Restart dhcp service:

[root@localhost dhcp]# systemctl restart dhcpd

Next, on the client, restart the network service to see if you have obtained the fixed address.

You can see that the address has been obtained.


In this question, you learned how to configure a DHCP server on Centos8. We saw that the host automatically obtains the IP address from the DHCP server, and also saw how to bind the IP address to a specific computer using the MAC address.

Posted on Fri, 03 Dec 2021 01:01:22 -0500 by horizontal