Switch#show ip dhcp snooping
//显示当前DHCP监听的各选项和各端口的配置情况
Switch#show ip dhcp snooping binding
//显示当前的DHCP监听绑定表
Switch#show ip dhcp snooping database
//显示DHCP监听绑定数据库的相关信息
Switch#show ip dhcp snooping statistics
//显示DHCP监听的工作统计
Switch#clear ip dhcp snooping binding
//清除DHCP监听绑定表;
//注意:本命令无法对单一条目进行清除,只能清除所有条目
Switch#clear ip dhcp snooping database statistics
//清空DHCP监听绑定数据库的计数器
Switch#clear ip dhcp snooping statistics
//清空DHCP监听的工作统计计数器
六、DHCP Snooping的实例
1、单交换机(DHCP服务器和DHCP客户端位于同一VLAN)
环境:Windows2003 DHCP服务器和客户端都位于vlan 10;服务器接在fa0/1,客户端接在fa0/2
2960交换机相关配置:
ip dhcp snooping vlan 10
ip dhcp snooping
!
interface FastEthernet0/1
description : Connect to Win2003 DHCP Server
switchport access vlan 10
switchport mode access
spanning-tree portfast
ip dhcp snooping trust
!
interface FastEthernet0/2
description : Connect to DHCP Client
switchport access vlan 10
switchport mode access
spanning-tree portfast
ip dhcp snooping limit rate 15
说明:本例中交换机对于客户端的DHCP 请求报文将插入选项82 信息;也可以通过配置no ip dhcp
snooping information option命令选择不插入选项82信息。两种情况都可以。
客户端端口推荐配置spanning-tree portfast命令,使得该端口不参与生成数计算,节省端口启动时间,
防止可能因为端口启动时间过长导致客户端得不到IP地址。
开启DHCP监听特性的vlan并不需要该vlan的三层接口被创建。
2、单交换机(DHCP服务器和DHCP客户端位于同一VLAN)
环境:Cisco IOS DHCP服务器(2821路由器)和PC客户端都位于vlan 10;路由器接在交换机的fa0/1,
客户端接在fa0/2
Windows2003
DHCP Server DHCP Client
2960
CiscoIOS
DHCP Server
2960 DHCP Client
2960交换机相关配置:
ip dhcp snooping vlan 10
ip dhcp snooping
!
interface FastEthernet0/1
description : Connect to IOS DHCP Server C2821_Gi0/0
switchport access vlan 10
switchport mode access
spanning-tree portfast
ip dhcp snooping trust
!
interface FastEthernet0/2
description : Connect to DHCP Client
switchport access vlan 10
switchport mode access
spanning-tree portfast
ip dhcp snooping limit rate 15
2821路由器相关配置:
ip dhcp excluded-address 192.168.10.1 192.168.10.2
!
ip dhcp pool test
network 192.168.10.0 255.255.255.0
default-router 192.168.10.1
lease 8
!
interface GigabitEthernet0/0
description : Connect to C2960_Fa0/1
ip dhcp relay information trusted
ip address 192.168.10.2 255.255.255.0
说明:
I、需要注意的是路由器连接到交换机的端口需要配置ip dhcp relay information trusted,否则客户端将
无法得到IP地址。
这是因为交换机配置了(默认情况)ip dhcp snooping information option,此时交换机会在客户端发出
的DHCP请求报文中插入选项82信息。另一方面由于DHCP服务器(这里指Cisco IOS DHCP服务器)与
客户端处于同一个VLAN中,所以请求实际上并没有经过DHCP中继代理。
对于Cisco IOS DHCP服务器来说,如果它收到的DHCP请求被插入了选项82信息,那么它会认为
这是一个从DHCP中继代理过来的请求报文,但是它检查了该报文的giaddr字段却发现是0.0.0.0,而不
是一个有效的IP地址(DHCP请求报文中的giaddr字段是该报文经过的第一个DHCP中继代理的IP地址,
具体请参考DHCP报文格式),因此该报文被认为“非法”,所以将被丢弃。可以参考路由器上的DHCP
的debug过程。
Cisco IOS里有一个命令,专门用来处理这类DHCP请求报文:ip dhcp relay information trusted(接口
命令)或者ip dhcp relay information trust-all(全局命令,对所有路由器接口都有效);这两条命令的作用
就是允许被插入了选项82信息,但其giaddr字段为0.0.0.0的DHCP请求报文通过。
II、如果交换机不插入选项82信息,即配置了no ip dhcp relay information trusted,那么就不会出现客
户端无法得到IP地址的情况,路由器也不需要配置ip dhcp relay information trusted命令。
III、Windows DHCP服务器应该没有检查这类DHCP请求的机制,所以上一个实例中不论交换机是否
插入选项82信息,客户端总是可以得到IP地址。
3、单交换机(DHCP服务器和DHCP客户端位于不同VLAN)
环境:Cisco IOS DHCP服务器(2821路由器)的IP地址为192.168.2.2,位于vlan 2;DHCP客户端位于
vlan 10;交换机为3560,路由器接在fa0/1,客户端接在fa0/2
3560交换机相关配置:
ip routing
!
ip dhcp snooping vlan 2,10
ip dhcp snooping
!
interface FastEthernet0/1
description : Connect to IOS DHCP Server C2821_Gi0/0
switchport access vlan 2
switchport mode access
spanning-tree portfast
ip dhcp snooping trust
!
interface FastEthernet0/2
description : Connect to DHCP Client
switchport access vlan 10
switchport mode access
spanning-tree portfast
ip dhcp snooping limit rate 15
!
interface Vlan2
ip address 192.168.2.1 255.255.255.0
!
interface Vlan10
ip address 192.168.10.1 255.255.255.0
ip helper-address 192.168.2.2
CiscoIOS
DHCP Server
3560 DHCP Client
2821路由器相关配置:
no ip routing
!
ip dhcp excluded-address 192.168.10.1 192.168.10.2
!
ip dhcp pool test
network 192.168.10.0 255.255.255.0
default-router 192.168.10.1
lease 8
!
interface GigabitEthernet0/0
description : Connect to C3560_Fa0/1
ip address 192.168.2.2 255.255.255.0
!
ip default-gateway 192.168.2.1
说明:本例中的路由器不需要配置ip dhcp relay information trusted命令,因为从交换机过来的DHCP请求
经过了中继代理,其报文中的giaddr字段为192.168.10.1,而不是0.0.0.0,是默认正常的DHCP请求报文。
4、多交换机环境(DHCP服务器和DHCP客户端位于不同VLAN)
环境:2611路由器作为DHCP服务器,IP地址为192.168.2.2,位于vlan 2;PC位于vlan 10;
路由器接在3560的Gi0/2,PC接2960的fa0/1口,两交换机互连口都是gi0/1
3560交换机相关配置:
ip routing
!
interface GigabitEthernet0/1
description : Connect to C2960_Gi0/1
switchport trunk encapsulation dot1q
switchport mode trunk
!
interface GigabitEthernet0/2
description : Connect to IOS DHCP Server C2611_Gi0/0
switchport access vlan 2
switchport mode access
spanning-tree portfast
!
interface Vlan2
ip address 192.168.2.1 255.255.255.0
!
PC
CIisco IOS 3560 2960
DHCP Server
interface Vlan10
ip address 192.168.10.1 255.255.255.0
ip helper-address 192.168.2.2
ip dhcp relay information trusted
2960交换机相关配置:
ip dhcp snooping vlan 10
ip dhcp snooping
interface FastEthernet0/1
description : Connect to PC
switchport access vlan 10
switchport mode access
spanning-tree portfast
ip dhcp snooping limit rate 15
!
interface GigabitEthernet0/1
description : Connect to C3560_Gi0/1
switchport mode trunk
ip dhcp snooping trust
2611路由器相关配置:
no ip routing
!
ip dhcp excluded-address 192.168.10.1 192.168.10.2
!
ip dhcp pool test
network 192.168.10.0 255.255.255.0
default-router 192.168.10.1
lease 8
!
interface GigabitEthernet0/0
description : Connect to C3560_Gi0/2
ip address 192.168.2.2 255.255.255.0
!
ip default-gateway 192.168.2.1
说明:本例中3560没有开启DHCP监听功能,2960开启了该功能。需要注意的是int vlan 10需要配置ip
dhcp relay information trusted,理由如同实例2。
5、多交换机环境(DHCP服务器和DHCP客户端位于同一VLAN)
环境:3560交换机自身作为DHCP服务器;PC1和PC2都位于vlan 10;
PC1接3560的fa0/1口,PC2接2960的fa0/1口;两交换机互连口都是gi0/1
3560交换机相关配置:
ip dhcp excluded-address 192.168.10.1
!
ip dhcp pool test
network 192.168.10.0 255.255.255.0
default-router 192.168.10.1
lease 8
!
ip dhcp snooping vlan 10
ip dhcp snooping information option allow-untrusted
ip dhcp snooping
!
interface FastEthernet0/1
description : Connect to PC1
switchport access vlan 10
switchport mode access
spanning-tree portfast
ip dhcp snooping limit rate 15
!
interface GigabitEthernet0/1
description : Connect to C2960_Gi0/1
switchport trunk encapsulation dot1q
switchport mode trunk
ip dhcp snooping limit rate 360
2960交换机相关配置:
ip dhcp snooping vlan 10
ip dhcp snooping
interface FastEthernet0/1
description : Connect to PC2
switchport access vlan 10
switchport mode access
spanning-tree portfast
ip dhcp snooping limit rate 15
PC1
PC2
3560
2960
!
interface GigabitEthernet0/1
description : Connect to C3560_Gi0/1
switchport mode trunk
ip dhcp snooping trust
说明:本例中3560和2960同时开启了DHCP监听功能。从2960过来的DHCP请求报文是已经被插入了选
项82信息,如果将3560的Gi0/1设置为信任端口,那么插入了82选项的DHCP请求报文是允许通过的,
但不会为其建立DHCP监听绑定表。即3560上只有PC1的绑定条目,而没有PC2的绑定条目。
如果此时同时部署DAI,IPSG,由于2960不支持这两项功能,对于3560来说,从2960上过来的数
据可能存在IP欺骗和ARP欺骗等攻击,是不安全的。另一方面,由于3560没有PC2的绑定条目,而DAI
和IPSG必须依赖DHCP监听绑定表。因此如果需要在3560上再部署DAI或者IPSG,就不能将3560的
Gi0/1设置为信任端口。
但是将3560的Gi0/1口设置为非信任端口以后,默认情况下,非信任端口将会丢弃收到的插入了82
选项的DHCP请求报文。而从2960过来的DHCP请求报文又正好是被插入了选项82信息的。因此必须配
置ip dhcp snooping information option allow-untrusted命令,否则3560将丢弃这些DHCP请求报文,接在
2960上的PC2将得不到IP地址。只有配置了该命令以后,3560才会接收从2960发送的插入了选项82的
DHCP报文,并为这些信息建立绑定条目。
3560下联的Gi0/1口由于是非信任端口,默认限速为每秒15个DHCP请求报文,如果2960上的所有
PC都同时发起DHCP请求,可能此端口会被errdisable掉。这里假设2960为24口,因此简单的设置限速
为24*15=360。
2960上联的Gi0/1口必须被配置为信任端口,否则将丢弃从3560过来的DHCP应答报文,PC2将无
法得到IP地址。
C3560#show ip dhcp snooping
Switch DHCP snooping is enabled
DHCP snooping is configured on following VLANs:
10
DHCP snooping is operational on following VLANs:
10
DHCP snooping is configured on the following L3 Interfaces:
Insertion of option 82 is enabled
circuit-id format: vlan-mod-port
remote-id format: MAC
Option 82 on untrusted port is allowed
Verification of hwaddr field is enabled
DHCP snooping trust/rate is configured on the following Interfaces:
Interface Trusted Rate limit (pps)
------------------------ ------- ----------------
FastEthernet0/1 no 15
GigabitEthernet0/1 no 360
C2960#show ip dhcp snooping
Switch DHCP snooping is enabled
DHCP snooping is configured on following VLANs:
10
Insertion of option 82 is enabled
circuit-id format: vlan-mod-port
remote-id format: MAC
Option 82 on untrusted port is not allowed
Verification of hwaddr field is enabled
Interface Trusted Rate limit (pps)
------------------------ ------- ----------------
FastEthernet0/1 no 15
GigabitEthernet0/1 yes unlimited
C2960#show ip dhcp snooping binding
MacAddress IpAddress Lease(sec) Type VLAN I nterface
------------------ --------------- ---------- ------------- ---- --------------------
00:0BB:08:21:E0 192.168.10.3 688023 dhcp-snooping 10 FastEthernet0/1
6、多交换机环境(DHCP服务器和DHCP客户端位于同一VLAN)
环境:4503交换机自身作为DHCP服务器;PC1和PC2都位于vlan 10;
PC1接4503的gi2/1口,PC2接3560的fa0/1口;两交换机互连口是4503 gi1/1 -- 3560 gi0/1
4503交换机相关配置:
ip dhcp excluded-address 192.168.10.1
!
ip dhcp pool test
network 192.168.10.0 255.255.255.0
default-router 192.168.10.1
lease 8
!
ip dhcp snooping vlan 10
ip dhcp snooping
!
interface GigabitEthernet2/1
PC1
PC2
4503
3560
description : Connect to PC1
switchport access vlan 10
switchport mode access
spanning-tree portfast
ip dhcp snooping limit rate 15
!
interface GigabitEthernet1/1
description : Connect to C3560_Gi0/1
switchport trunk encapsulation dot1q
switchport mode trunk
ip dhcp snooping trust
3560交换机相关配置:
ip dhcp snooping vlan 10
ip dhcp snooping
interface FastEthernet0/1
description : Connect to PC2
switchport access vlan 10
switchport mode access
spanning-tree portfast
ip dhcp snooping limit rate 15
!
interface GigabitEthernet0/1
description : Connect to C4503_Gi1/1
switchport trunk encapsulation dot1q
switchport mode trunk
ip dhcp snooping trust
说明:本例中4503和3560同时开启了DHCP监听功能。由于4503的下联口被设置为信任端口,所以从
3560过来的DHCP请求报文即使已经被插入了选项82信息,也允许通过的,但不会为其建立DHCP监听
绑定表。所以4503上只有PC1的绑定条目,而没有PC2的绑定条目。
作为接入层交换机的3560支持DAI,IPSG,如果同时配置这两项功能,那么有理由相信从3560过
来的数据是已经经过检验的安全数据,因此将4503的下联口设置为信任端口是可行的。另外,4503没有
PC2的绑定条目,也减少了系统运行时所需的内存空间。
C4503#show ip dhcp snooping binding
MacAddress I pAddress Lease(sec) Type VLAN Interface
------------------ --------------- ---------- ------------- ---- --------------------
00:0F:1F:C5:10:08 192.168.10.2 685618 dhcp-snooping 10 GigabitEthernet2/1
C3560#show ip dhcp snooping binding
MacAddress IpAddress Lease(sec) Type VLAN Interface
------------------ --------------- ---------- ------------- ---- --------------------
00:0B:DB:08:21:E0 192.168.10.3 688023 dhcp-snooping 10 FastEthernet0/1