DHCP principle and experimental configuration
- 1. Principle of DHCP
-
- 2. Advantages and distribution methods of DHCP
-
- 1. Advantages:
- 2. DHCP allocation method
- 3. Basic steps of the experiment
-
- 1.yum install dhcp
- Four. Experiment
- 1. Settings in the virtual machine
- 2. Configure in ensp
- 3. Configuration
- 4. Configure DHCP relay in ensp
1. Principle of DHCP
The first step: the client searches for the server in the network, the
client sends a DHCP Discover message by broadcasting to find the server. The
second step: the server responds to the client and the
server sends a unicast DHCP Offer
message to provide the client with an IP address, etc. Network information, select an unassigned IP from the IP address pool and assign it to the client.
Step 3: The client sends a service request to the server.
If multiple DHCP servers send DHCP-offer messages to the client, the client only Accept the first received DHCP-offer message and extract the IP address, and then the client sends a DHCP Request message via broadcast to inform the server to select the IP address locally.
Step 4: The server provides services to the client The
server sends a DHCP Ack message through unicast to inform the client that the IP address is legally available, and adds the lease information of the IP address in the option field
2. Advantages and distribution methods of DHCP
1. Advantages:
●Reduce the workload of the administrator
●Avoid the possibility of input errors
●Avoid IP address conflicts
●When changing the IP address segment, there is no need to reconfigure each user's IP address
●Improved the utilization of IP addresses
●Convenient client configuration
2. DHCP allocation method
●Automatic allocation: permanent use after being assigned to an IP address
●Manual allocation: designated by the DHCP server administrator]
●Dynamic allocation: releasing the IP after use for other clients to use
3. Basic steps of the experiment
1.yum install dhcp
[root@localhost yum.repos.d]# yum install -y dhcp
2. Find the DHCP configuration template, overwrite the file, and modify the configuration file
[root@localhost dhcp-4.2.5]# cd /etc/dhcp
[root@localhost dhcp]# cd /usr/share/doc/dhcp-4.2.5/
[root@localhost dhcp-4.2.5]# cp dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp:是否覆盖"/etc/dhcp/dhcpd.conf"? yes
3. Set global configuration parameters:
option domain-name "kkk.com"; #指定默认域名
option domain-name-servers 8.8.8.8;#指定DNS服务器地址
default-lease-time 600;#默认租约为600,单位为秒
max-lease-time 7200;#最大租约为7200,单位为秒
ddns-update-style none;#禁用DNS动态更新
4. Modify the subet network segment statement
subnet 192.168.80.0 netmask 255.255.255.0 {
#首先声明dhcp服务器网段以及子网掩码
range 192.168.80.10 192.168.80.20; #设置ip地址池
option routers 192.168.80.254; #指定默认网关
}
subnet 192.168.1.0 netmask 255.255.255.0 {
#其次声明其他网段以及子网
range 192.168.1.100 192.168.1.200; #设置ip地址池
option routers 192.168.1.254; #指定默认网关
}
……
5. Start the DHCP service:
[root@localhost dhcp]# systemctl start dhcpd
[root@localhost dhcp]# netstat -naup | grep 67
udp 0 0 0.0.0.0:67 0.0.0.0:* 43149/dhcpd
udp 0 0 0.0.0.0:67 0.0.0.0:* 1222/dnsmasq
6. Assign a fixed IP address to the single machine (modify the host host statement)
host hostname {
#指定需要分配固定IP地址的客户机名称
hardware ethernet xx:xx:xx:xx:xx:xx; #指定该主机的MAC地址
fixed-address 192.168.80.100; #指定保留给该主机的IP地址
}
7. Restart the service
[root@localhost dhcp]# systemctl restart dhcpd
[root@localhost dhcp]# systemctl restart dhcpd
[root@localhost dhcp]# systemctl restart dhcpd
Four. Experiment
1. Settings in the virtual machine
1. Modify the network adapter, select VMnet1, host mode
2. Enter the network editor, the DHCP setting of VMnet1 is unchecked
3. Modify the IP address of the machine VMnet1
4. Set the network card
2. Configure in ensp
1. This picture is listed in the ensp
2. Enter the cloud to perform the corresponding configuration
3. The configuration of the two-layer switch sw1:
4. The configuration of the three-layer switch sw2:
3. Configuration
1. Yum installs dhcp
2. Find the DHCP configuration template, overwrite the file, modify the configuration file
3. Set the global configuration parameters:
4. Modify the subet network segment statement:
5. Start the DHCP service:
4. Configure DHCP relay in ensp
1. Enter sw2 and turn on the relay function:
2. pc1 and pc2 set dhcp:
3. In ensp, pc1 and 2 automatically obtain ip:
5. Assign a fixed IP address to the single machine (modify the host host statement)
Enter the WIN10 virtual machine: