第一步:客户端通过广播发送DHCP Discover 报文寻找服务器端
第二步:服务器端通过单播发送DHCP Offer 报文向客户端提供IP地址等网络信息
第三步:客户端通过广播DHCP Request 报文告知服务器端本地选择使用哪个IP地址
第四步:服务器通过DHCP Ack报文告知客户端IP地址是合法可用的
system-view
[Huawei]sysname SW1
[SW1]vlan bat 10 20 '//连续添加vlan'
[SW1]interface Ethernet 0/0/1 '//进入接口'
[SW1-Ethernet0/0/1]port link-type access '//设置接口模式'
[SW1-Ethernet0/0/1]port default vlan 10 '//划分vlan'
[SW1-Ethernet0/0/1]undo shutdown
[SW1-Ethernet0/0/1]interface Ethernet 0/0/2
[SW1-Ethernet0/0/2]port link-type access
[SW1-Ethernet0/0/2]port default vlan 20
[SW1-Ethernet0/0/2]undo shutdown
[SW1-Ethernet0/0/2]interface Ethernet 0/0/3
[SW1-Ethernet0/0/3]port link-type access
[SW1-Ethernet0/0/3]port default vlan 10
[SW1-Ethernet0/0/3]undo shutdown
[SW1-Ethernet0/0/3]interface Ethernet 0/0/4
[SW1-Ethernet0/0/4]port link-type access
[SW1-Ethernet0/0/4]port default vlan 20
[SW1-Ethernet0/0/4]undo shutdown
[SW1-Ethernet0/0/4]quit
[SW1]interface GigabitEthernet 0/0/1 '//进入接口'
[SW1-GigabitEthernet0/0/1]port link-type trunk '//设置接口模式'
[SW1-GigabitEthernet0/0/1]port trunk allow-pass vlan all '//设置允许通过的vlan'
[SW1-GigabitEthernet0/0/1]undo shutdown
system-view
[Huawei]sysname R1
[R1]dhcp enable
[R1]interface GigabitEthernet 0/0/1.1 '//进入接口'
[R1-GigabitEthernet0/0/1.1]dot1q termination vid 10 '//选择封装类型并设置vlan归属'
[R1-GigabitEthernet0/0/1.1]ip address 192.168.10.1 24
[R1-GigabitEthernet0/0/1.1]arp broadcast enable '//开启arp广播'
[R1-GigabitEthernet0/0/1.1]dhcp select relay '//选择转发设置DHCP'
[R1-GigabitEthernet0/0/1.1]dhcp relay server-ip 13.0.0.2 '//选择DHCP路由器地址'
[R1-GigabitEthernet0/0/1.1]undo shutdown
[R1-GigabitEthernet0/0/1.1]interface GigabitEthernet 0/0/1.2
[R1-GigabitEthernet0/0/1.2]dot1q termination vid 20
[R1-GigabitEthernet0/0/1.2]ip address 192.168.20.1 24
[R1-GigabitEthernet0/0/1.2]arp broadcast enable
[R1-GigabitEthernet0/0/1.2]dhcp select relay '//选择转发设置DHCP'
[R1-GigabitEthernet0/0/1.2]dhcp relay server-ip 13.0.0.2 '//选择DHCP路由器地址'
[R1-GigabitEthernet0/0/1.2]undo shutdown
[R1-GigabitEthernet0/0/1.2]q
[R1]interface GigabitEthernet 0/0/0
[R1-GigabitEthernet0/0/0]ip add 12.0.0.1 24
[R1-GigabitEthernet0/0/0]undo shutdown
[R1-GigabitEthernet0/0/0]quit
[R1]interface GigabitEthernet 0/0/2
[R1-GigabitEthernet0/0/2]ip add 13.0.0.1 24
[R1-GigabitEthernet0/0/2]undo shutdown
[R1-GigabitEthernet0/0/2]quit
[R1]ip route-static 15.0.0.0 24 12.0.0.2 '//添加静态路由'
system-view
[Huawei]sysname R2
[R2]dhcp enable
[R2]interface GigabitEthernet0/0/0
[R2-GigabitEthernet0/0/0]ip add 12.0.0.2 24
[R2-GigabitEthernet0/0/0]undo shutdown
[R2-GigabitEthernet0/0/0]interface GigabitEthernet0/0/1
[R2-GigabitEthernet0/0/1]ip add 15.0.0.1 24
[R2-GigabitEthernet0/0/1]undo shutdown
[R2-GigabitEthernet0/0/1]quit
[R2]ip route-static 192.168.10.0 24 12.0.0.1 '//添加静态路由'
[R2]ip route-static 192.168.20.0 24 12.0.0.1
[R2]ip route-static 13.0.0.0 12.0.0.1
[R2]ip pool v11 '//进入ip地址池'
[R2-ip-pool-v11]gateway-list 15.0.0.1 '//设置网关'
[R2-ip-pool-v11]network 15.0.0.0 mask 24 '//设置网段和子网掩码'
[R2-ip-pool-v11]quit
[R2]interface GigabitEthernet0/0/1
[R2-GigabitEthernet0/0/1] dhcp select reply '//选择转发设置DHCP'
[R2-GigabitEthernet0/0/1] dhcp relay server-ip 13.0.0.2 '//选择DHCP路由器地址'
system-view
[Huawei]sysname R3
[R3]dhcp enable
[R3]interface GigabitEthernet0/0/2
[R3-GigabitEthernet0/0/2]ip address 13.0.0.2 24
[R3-GigabitEthernet0/0/2]undo shutdown
[R3-GigabitEthernet0/0/2]quit
[R3]ip pool v15
[R3-ip-pool-v15]gateway-list 15.0.0.1
[R3-ip-pool-v15]network 15.0.0.0 mask 24
[R3]ip pool v10
[R3-ip-pool-v10]gateway-list 192.168.10.1
[R3-ip-pool-v10]network 192.168.10.0 mask 24
[R3]ip pool v20
[R3-ip-pool-v20]gateway-list 192.168.20.1
[R3-ip-pool-v15]network 192.168.20.0 mask 24
[R3]interface GigabitEthernet0/0/2
[R3-GigabitEthernet0/0/2]dhcp select global
接口模式
步骤1:
[R1]dhcp enable '//###全局配置模式开启DHCP功能'
步骤2:
[R1]interface GigabitEthernet0/0/0.10 '//###进入子接口'
[R1-GigabitEthernet0/0/0.10] dhcp select interface '//###基于基于接口配置DHCP'
[R1-GigabitEthernet0/0/0.10] dhcp server excluded-ip-address 192.168.10.200 192.168.10.210 '//##192.168.10.200到192.168.10.210不分配地址'
[R1-GigabitEthernet0/0/0.10] dhcp server static-bind ip-address 192.168.20.9 mac-address 28d2-4469-5a55
'//#### 绑定 IP 192.168.20.9 固定分配给MAC 为28d2-4469-5a55的机器,需池中IP'
[R1-GigabitEthernet0/0/0.10]dhcp server dns-list 8.8.8.8 '//###配置DNS'
全局配置模式
步骤1:
[R1]dhcp enable '//###全局配置模式开启DHCP功能'
步骤2:
[R1] ip pool v20
[R1-ip-pool-v20] gateway-list 192.168.20.1
[R1-ip-pool-v20] network 192.168.20.0 mask 255.255.255.0
[R1-ip-pool-v20] dns-list 114.114.114.114
[R1-ip-pool-v20] excluded-ip-address 192.168.10.200 192.168.10.210 '//##192.168.10.200到192.168.10.210不分配地址'
[R1-ip-pool-v20] static-bind ip-address 192.168.20.9 mac-address 28d2-4469-5a55
'//#### 绑定 IP 192.168.20.9 固定分配给MAC 为28d2-4469-5a55的机器,需池中IP'
[R1-ip-pool-v20] lease day 10 '//####租期10天 '
步骤3:
[R1]int g0/0/0.20
[R1-GigabitEthernet0/0/0.20] dhcp select global '//选择全局模式分配DHCP'