什么是DHCP:
DHCP动态主机配置协议,是一个应用层协议。当我们将客户主机IP地址设置为动态获取方式时,DHCP服务器就会根据DHCP协议给客户端分配ip,
使得客户机能利用ip上网。
DHCP工作原理:
第一步:客户端通过广播发送DHCP Discover 报文寻找服务器端
第二步:服务器端通过单播发送DHCP Offer 报文向客户端提供IP地址等网络信息
第三步:客户端通过广播发送DHCP Request 报文告知服务器端本地选择使用哪个IP地址
第四步:服务器通过单播发送DHCP Ack报文告知客户端IP地址是合法可用的
下面通过一个ensp实验诠释DHCP服务↓↓↓
LSW1
<Huawei>
<Huawei>un te m
<Huawei>sys
[Huawei]sys LSW1
[LSW1]vlan b
[LSW1]vlan batch 10 20
[LSW1]int e0/0/1
[LSW1-Ethernet0/0/1]port link-type access
[LSW1-Ethernet0/0/1]port default vlan 10
[LSW1-Ethernet0/0/1]un sh
Info: Interface Ethernet0/0/1 is not shutdown.
[LSW1-Ethernet0/0/1]int e0/0/2
[LSW1-Ethernet0/0/2]p l a
[LSW1-Ethernet0/0/2]p d v 20
[LSW1-Ethernet0/0/2]un sh
[LSW1-Ethernet0/0/2]int e0/0/3
[LSW1-Ethernet0/0/3]p l a
[LSW1-Ethernet0/0/3]p d v 10
[LSW1-Ethernet0/0/3]un sh
[LSW1-Ethernet0/0/3]int e0/0/4
[LSW1-Ethernet0/0/4]p l a
[LSW1-Ethernet0/0/4]p d v 20
[LSW1-Ethernet0/0/4]un sh
[LSW1-Ethernet0/0/4]int g0/0/1
[LSW1-GigabitEthernet0/0/1]p l t
[LSW1-GigabitEthernet0/0/1]p t a v a
[LSW1-GigabitEthernet0/0/1]un sh
R1
<Huawei>un te m
<Huawei>sys
[Huawei]sys R1
[R1]dhcp enable ##开启DHCP功能
[R1]int g0/0/1.10 ##进入子接口
[R1-GigabitEthernet0/0/1.10]dot1q termination vid 10
[R1-GigabitEthernet0/0/1.10]ip add 192.168.10.1 24
[R1-GigabitEthernet0/0/1.10]arp broadcast enable
[R1-GigabitEthernet0/0/1.10]dhcp select interface ##基于接口配置DHCP
[R1-GigabitEthernet0/0/1.10]dhcp server dns-list 2.2.2.2 8.8.8.8 ##配置dns
[R1-GigabitEthernet0/0/1.10]q
[R1]int g0/0/1.20
[R1-GigabitEthernet0/0/1.20]d t v 20
[R1-GigabitEthernet0/0/1.20]ip add 192.168.20.1 24
[R1-GigabitEthernet0/0/1.20]a b e
[R1-GigabitEthernet0/0/1.20]dhcp select interface
[R1-GigabitEthernet0/0/1.20]dhcp server dns-list 2.2.2.2 8.8.8.8
[R1-GigabitEthernet0/0/1.20]q
[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]ip add 12.0.0.1 24
[R1-GigabitEthernet0/0/0]un sh
[R1-GigabitEthernet0/0/0]q
[R1]ip route-static 0.0.0.0 0.0.0.0 12.0.0.2 ##设置静态路由
R2
<Huawei>un te m
<Huawei>sys
[Huawei]sys R2
[R2]dhcp en
[R2]dhcp enable
Info: The operation may take a few seconds. Please wait for a moment.done.
[R2]int g0/0/0
[R2-GigabitEthernet0/0/0]ip add 12.0.0.2 24
[R2-GigabitEthernet0/0/0]un sh
[R2-GigabitEthernet0/0/0]int g0/0/1
[R2-GigabitEthernet0/0/1]ip add 15.0.0.1 24
[R2-GigabitEthernet0/0/1]dhcp select global
[R2-GigabitEthernet0/0/1]un sh
[R2-GigabitEthernet0/0/1]q
[R2]ip pool dhcp15
Info:It's successful to create an IP address pool.
[R2-ip-pool-dhcp15]network 15.0.0.0 mask 24
[R2-ip-pool-dhcp15]gateway-list 15.0.0.1
[R2-ip-pool-dhcp15]dns-list 8.8.8.8 2.2.2.2
[R2-ip-pool-dhcp15]q
[R2]ip route-static 0.0.0.0 0.0.0.0 12.0.0.1
配置完后抓包检测是否开通