如图12-15所示,Host通过Switch_1接入网络,Switch_2作为DHCP Server为Host动态分配IP地址,Gateway为企业出口网关。管理员希望Host使用动态分配的地址,不允许私自配置静态IP地址,如果私自指定IP地址将无法访问网络。
采用如下的思路配置IPSG功能,实现上述需求。
在Switch_2上配置DHCP Server功能(假设地址池为10.1.1.0/24),为Host动态分配IP地址。
在Switch_1上配置DHCP Snooping功能,保证Host从合法的DHCP Server获取IP地址,同时生成DHCP Snooping动态绑定表,记录Host的IP地址、MAC地址、VLAN、接口的绑定关系。
在Switch_1连接Host的VLAN上使能IPSG功能,防止Host通过私自配置IP地址的方式访问网络。
在Switch_2上配置DHCP Server功能
[Switch_2] vlan batch 10
[Switch_2] interface gigabitethernet 1/0/1
[Switch_2-GigabitEthernet1/0/1] port link-type trunk
[Switch_2-GigabitEthernet1/0/1] port trunk allow-pass vlan 10
[Switch_2-GigabitEthernet1/0/1] quit
[Switch_2] dhcp enable
[Switch_2] ip pool 10
[Switch_2-ip-pool-10] network 10.1.1.0 mask 24
[Switch_2-ip-pool-10] gateway-list 10.1.1.1
[Switch_2-ip-pool-10] quit
[Switch_2] interface vlanif 10
[Switch_2-Vlanif10] ip address 10.1.1.1 255.255.255.0
[Switch_2-Vlanif10] dhcp select global
[Switch_2-Vlanif10] quit
在Switch_1上配置DHCP Snooping功能
# 配置各接口所属VLAN。
[Switch_1] vlan batch 10
[Switch_1] interface gigabitethernet 1/0/1
[Switch_1-GigabitEthernet1/0/1] port link-type access[
Switch_1-GigabitEthernet1/0/1] port default vlan 10
[Switch_1-GigabitEthernet1/0/1] quit
[Switch_1] interface gigabitethernet 1/0/2
[Switch_1-GigabitEthernet1/0/2] port link-type access
[Switch_1-GigabitEthernet1/0/2] port default vlan 10
[Switch_1-GigabitEthernet1/0/2] quit
[Switch_1] interface gigabitethernet 1/0/3
[Switch_1-GigabitEthernet1/0/3] port link-type trunk
[Switch_1-GigabitEthernet1/0/3] port trunk allow-pass vlan 10
[Switch_1-GigabitEthernet1/0/3] quit
# 使能DHCP Snooping功能,并将连接DHCP Server的GE1/0/3接口配置为信任接口。
[Switch_1] dhcp enable
[Switch_1] dhcp snooping enable
[Switch_1] vlan 10
[Switch_1-vlan10] dhcp snooping enable
[Switch_1-vlan10] dhcp snooping trusted interface gigabitethernet 1/0/3
在Switch_1的VLAN10上使能IPSG功能
[Switch_1-vlan10] ip source check user-bind enable
[Switch_1-vlan10] quit
验证配置结果
Host上线后,在Switch_1上执行display dhcp snooping user-bind all命令,可以查看Host的动态绑定表信息。
[Switch_1] display dhcp snooping user-bind allDHCP Dynamic Bind-table: Flags:O - outer vlan ,I - inner vlan ,P - Vlan-mapping IP Address MAC Address VSI/VLAN(O/I/P) InterfaceLease -------------------------------------------------------------------------------- 10.1.1.254 0001-0001-0001--/10/--GE1/0/12014.08.17-07:31 10.1.1.253 0002-0002-0002--/10/--GE1/0/22014.08.17-07:34 -------------------------------------------------------------------------------- print count:2 total count:2
Host使用DHCP服务器动态分配的IP地址可以正常访问网络,将Host更改为与动态获得的IP地址不一样的静态IP地址后无法访问网络。
Switch_1的配置文件
# sysname Switch_1 # vlan batch 10 # dhcp enable # dhcp snooping enable # vlan 10 dhcp snooping enable dhcp snooping trusted interface GigabitEthernet1/0/3 ip source check user-bind enable # interface GigabitEthernet1/0/1 port link-type access port default vlan 10 # interface GigabitEthernet1/0/2 port link-type access port default vlan 10 # interface GigabitEthernet1/0/3 port link-type trunk port trunk allow-pass vlan 10 # return
Switch_2的配置文件
# sysname Switch_2 # vlan batch 10 # dhcp enable # ip pool 10 gateway-list 10.1.1.1 network 10.1.1.0 mask 255.255.255.0 # interface Vlanif10 ip address 10.1.1.1 255.255.255.0 dhcp select global # interface GigabitEthernet1/0/1 port link-type trunk port trunk allow-pass vlan 10 # return