一、dhcp snooping的原理


dhcp snooping在交换机上配置完成;而且必须指明在哪个vlan上进行监听,没有监听的vlan不受规则限制。交换机上开启snooping后,交换机任何一个接口的dhcp服务器都不能提供服务。因此需要在开启了dhcp snooping的交换机定义两类接口:

1、可信任接口:连接dhcp服务器的接口或上联接口

2、不可信任接口:连接客户端的接口,默认下接客户端的全为不可信任接口。


交换机只接受合法的服务器发过来的dhcp消息,drop非法的服务器发过来的dhcp消息。

 dhcp snooping需要注意的是:

 1、交换机开启dhcp snooping后默认会开启中继效果,而且中继是无法关闭的

 2、开启中继的交换机,会将dhcp请求包的giaddr值设置为0.0.0.0

 3、dhcp服务器要能对giaddr为0.0.0.0的请求包做应答:  dhcpserver(config-if)#ip dhcp relay information trusted

 4、如果是dhcp服务器在远程网络,还需要配置 dhcpserver(config-if)#ip helper-address x.x.x.x


二、实验

1、拓扑图:

wKioL1b8j2TCKr8-AADWSwWQYpc963.jpg

R2作为合法的dhcp server上的配置:
interface FastEthernet5/0/17
 no switchport
 ip dhcp relay information trusted
 ip address 10.1.1.1 255.255.255.0
ip dhcp excluded-address 10.1.1.1
!
ip dhcp pool sw2
   network 10.1.1.0 255.255.255.0
   default-router 10.1.1.1
   lease 0 0 1
R3作为非法的dhcp server上的配置:
interface FastEthernet1/0/3
 no switchport
 ip address 20.1.1.1 255.255.255.0
ip dhcp excluded-address 20.1.1.1
!
ip dhcp pool sw3
   network 20.1.1.0 255.255.255.0
   default-router 20.1.1.1
   lease 0 0 1
开启了dhcp snooping的交换机的配置:
ip dhcp snooping vlan 1
ip dhcp snooping

interface FastEthernet1/0/17
 switchport mode access
 ip dhcp snooping trust
 
interface FastEthernet1/0/3 !开启snooping后默接口都是不信任端口
 switchport mode access


wKioL1b8lQeSSl6IAAAl1PHLObI066.png


开启dhcp snooping特性后,client只能从合法的服务器出得到IP地址。

C:\Users\Administrator>ping 10.1.1.1

Pinging 10.1.1.1 with 32 bytes of data:
Reply from 10.1.1.1: bytes=32 time=3ms TTL=255
Reply from 10.1.1.1: bytes=32 time=1ms TTL=255
Reply from 10.1.1.1: bytes=32 time=1ms TTL=255
Reply from 10.1.1.1: bytes=32 time=2ms TTL=255