How does Centos8 configure a DHCP server

System environment

Centos8

Install DHCP

The address of the DHCP server is 192.168.43.254/24, and the default gateway is 192.168.43.2/24. The DHCP server will automatically assign IP addresses to other devices in the network 192.168.43.0/24.

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;
authoritative;
subnet 192.168.43.0 netmask 255.255.255.0 {
  range 192.168.43.101 192.168.43.200;
  option routers 192.168.43.2;
  option subnet-mask 255.255.255.0;
  option domain-name-servers 192.168.43.2;

}

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 192.168.43.0/24 network.

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

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/multi-user.target.wants/dhcpd.service → /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
success
[root@localhost ~]# firewall-cmd --reload
success

Client test

Got the address on the client:

Check whether 192.168.43.254 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 = 192.168.43.254

You can see that the dhcp server identifier is 192.168.43.254.

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 192.168.43.150:

host server {
  hardware ethernet 00:0c:29:99:ee:d9;
  fixed-address 192.168.43.150;
}

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.

summary

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