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)
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
3. Experimental environment preparation-configure the IP address of the DHCP server nmtui command
[root@localhost ~]# nmtui
4. Preparation of the experimental environment-configure the IP address of the DHCP client
[root@localhost ~]# nmtui
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
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
3. Restart the dhcpd service program:
[root@localhost ~]# systemctl restart dhcpd.service
4. Add to startup items:
[root@localhost ~]# systemctl enable dhcpd.service
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
Method 2:
Use the command on the terminal to close and open the network card
[root@localhost ~]# ifdown ens33
[root@localhost ~]# ifup ens33
2. Obtain an IP address
[root@localhost ~]# ifconfig
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.
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 .
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.