Linux (CentOS7) DHCP server configuration

DHCP server configuration

Experimental environment (this experiment is implemented with VmwareWorkstation software)

Host type operating system IP address
DHCP server CentOS7 192.168.11.38
DHCP client CentOS7 DHCP automatically obtains an address

1. Experimental environment preparation-configure the virtual machine network type (both hosts must be configured to be the same)
Insert picture description here
2. Note: the virtual machine software VmwareWorkstation has enabled the virtual machine DHCP service by default, and must be closed before performing the DHCP experiment
Insert picture description here

3. Experimental environment preparation-configure the IP address of the DHCP server nmtui command

[root@localhost ~]# nmtui

Insert picture description here
4. Preparation of the experimental environment-configure the IP address of the DHCP client

[root@localhost ~]# nmtui

Insert picture description here
Start experiment:


1. Server 1. Install the dhcpd service program
First, configure the yum source, and then install dhcp.
(1) Configure yum source reference link https://blog.csdn.net/m0_53521757/article/details/112546446
(2)

[root@localhost ~]# yum -y install dhcp 

Insert picture description here

2. Edit the configuration file /etc/dhcp/dhcpd.conf and add the following content

default-lease-time 21600;
max-lease-time 43200;
subnet 192.168.11.0 netmask 255.255.255.0 { range 192.168.11.2 192.168.11.100; option routers 192.168.11.1; } // The meaning of the content: the default lease time is 21 600 seconds Maximum lease time 43200 seconds IP address range 192.168.11.1~192.168.11.100 subnet mask 255.255.255.0 //









[root@localhost ~]# vim /etc/dhcp/dhcpd.conf

Insert picture description here
3. Restart the dhcpd service program:

[root@localhost ~]# systemctl restart dhcpd.service 

4. Add to startup items:

[root@localhost ~]# systemctl enable dhcpd.service 

Insert picture description here
Complete code: (server)

[root@localhost ~]# nmtui
[root@localhost ~]# yum -y install dhcp
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf//给该配置文件添加内容
[root@localhost ~]# systemctl restart dhcpd.service 
[root@localhost ~]# systemctl enable dhcpd.service 

2. Client
Restart the network card device on the DHCP client to automatically obtain the IP address
. 1. Restart the network card:
Method 1
Re-enable the network card in the network settings
Insert picture description here
Method 2:
Use the command on the terminal to close and open the network card

[root@localhost ~]# ifdown ens33
[root@localhost ~]# ifup ens33

Insert picture description here
2. Obtain an IP address

[root@localhost ~]# ifconfig

Insert picture description here
We can see that the IP address of segment 11 has been obtained.

Complete code: (Client)
Use method 2 to restart the network card

[root@localhost ~]# nmtui
//使用方法2重启网卡:
[root@localhost ~]# ifdown ens33
[root@localhost ~]# ifup ens33
[root@localhost ~]# ifconfig

Three, possible error problems:

The dhcpd service failed to start.
Insert picture description here
In other cases where the configuration is correct, it is likely that the file /etc/dhcp/dhcpd.conf is configured incorrectly, so check the file again, and then start the dhcpd service program. If no problems are displayed, the startup is successful .
Insert picture description here
Today's sharing is here. If you have any questions, private messages and comments are fine, and the blogger will definitely reply. I hope everyone will point out my shortcomings and we will work together.

Guess you like

Origin blog.csdn.net/m0_53521757/article/details/112622749