ip dhcp snooping配置

一、DHCP snooping 技术介绍
 
DHCP监听(DHCP Snooping)是一种DHCP安全特性。Cisco交换机支持在每个VLAN基础上启用DHCP监听特性。通过这种特性,交换机能够拦截第二层VLAN域内的所有DHCP报文。
 
通过开启DHCP监听特性,交换机限制用户端口(非信任端口)只能够发送DHCP请求,丢弃来自用户端口的所有其它DHCP报文,例如DHCP Offer报文等。而且,并非所有来自用户端口的DHCP请求都被允许通过,交换机还会比较DHCP 请求报文的(报文头里的)源MAC地址和(报文内容里的)DHCP客户机的硬件地址(即CHADDR字段),只有这两者相同的请求报文才会被转发,否则将被丢弃。这样就防止了DHCP耗竭攻击。信任端口可以接收所有的DHCP报文。通过只将交换机连接到合法DHCP服务器的端口设置为信任端口,其他端口设置为非信任端口,就可以防止用户伪造DHCP服务器来攻击网络。DHCP监听特性还可以对端口的DHCP报文进行限速。通过在每个非信任端口下进行限速,将可以阻止合法DHCP请求报文的广播攻击。DHCP监听还有一个非常重要的作用就是建立一张DHCP监听绑定表(DHCP Snooping Binding)。一旦一个连接在非信任端口的客户端获得一个合法的DHCP Offer,交换机就会自动在DHCP监听绑定表里添加一个绑定条目,内容包括了该非信任端口的客户端IP地址、MAC地址、端口号、VLAN编号、租期等信息。
 
二、DHCP snooping 配置
 
Switch(config)#ip dhcp snooping // 打开DHCP Snooping功能
Switch(config)#ip dhcp snooping vlan 10 // 设置DHCP Snooping功能将作用于哪些 VLAN
Switch(config)#ip dhcp snooping verify mac-adress                 
 
//检测非信任端口收到的DHCP请求报文的源MAC和CHADDR字段是否相同,以防止DHCP耗竭攻击,该功能默认即为开启

Switch(config-if)#ip dhcp snooping trust 
 
// 配置接口为DHCP监听特性的信任接口,所有接口默认为非信任接口

Switch(config-if)#ip dhcp snooping limit rate 15 
 
// 限制非信任端口的DHCP报文速率为每秒15个包(默认即为每秒15个包)如果不配该语句,则show ip dhcp snooping的结果里将不列出没有该语句的端口,可选速率范围为1-2048
 
建议:在配置了端口的DHCP报文限速之后,最好配置以下两条命令
Switch(config)#errdisable recovery cause dhcp-rate-limit                 
// 使由于DHCP报文限速原因而被禁用的端口能自动从err-disable状态恢复

Switch(config)#errdisable recovery interval 30
// 设置恢复时间;端口被置为err-disable状态后,经过30秒时间才能恢复
 
Switch(config)#ip dhcp snooping information option                 
// 设置交换机是否为非信任端口收到的DHCP报文插入Option 82,默认即为开启状态
Switch(config)#ip dhcp snooping information option allow-untrusted                
// 设置汇聚交换机将接收从非信任端口收到的接入交换机发来的带有选项82的DHCP报文

Switch#ip dhcp snooping binding 000f.1fc5.1008 vlan 10 192.168.10.131 interface fa0/2 expiry 692000                  // 特权模式命令;手工添加一条DHCP监听绑定条目;expiry为时间值,即为监听绑定表中的lease(租期)
Switch(config)#ip dhcp snooping database
flash:dhcp_snooping.db                 
// 将DHCP监听绑定表保存在flash中,文件名为 dhcp_snooping.db

Switch(config)#ip dhcp snooping database
tftp://192.168.2.5/Switch/dhcp_snooping.db 
//将DHCP监听绑定表保存到tftp服务器;192.168.2.5为tftp服务器地址,必须事先确定可达。URL中的Switch是tftp服务器下一个文件夹;保存后的文件名为dhcp_snooping.db,当更改保存位置后会立即执行“写”操作。

Switch(config)#ip dhcp snooping database write-delay 30
                
// 指DHCP监听绑定表发生更新后,等待30秒,再写入文件,默认为300秒;可选范围为15-86400秒
Switch(config)#ip dhcp snooping database timeout 60 
// 指DHCP监听绑定表尝试写入操作失败后,重新尝试写入操作,直到60秒后停止尝试。默认为300秒;可选范围为0-86400秒

说明:实际上当DHCP监听绑定表发生改变时会先等待write-delay的时间,然后执行写入操作,如果写入操作失败(比如tftp服务器不可达),接着就等待timeout的时间,在此时间段内不断重试。在timeout时间过后,停止写入尝试。但由于监听绑定表已经发生了改变,因此重新开始等待write-delay时间执行写入操作……不断循环,直到写入操作成功。
Switch#renew ip dhcp snooping database flash:dhcp_snooping.db         
 
/ 特权级命令;立即从保存好的数据库文件中读取DHCP监听绑定表。



解决IP地址冲突的完美方法--DHCP SNOOPING 使用的方法是采用DHCP方式为用户分配IP,然后限定这些用户只能使用动态IP的方式,如果改成静态IP的方式则不能连接上网络;也就是使用了DHCP SNOOPING功能。 例子: version 12.1 no service pad service timestamps debug uptime service timestamps log uptime no service password-encryption service compress-config ! hostname C4-2_4506 ! enable password xxxxxxx! clock timezone GMT 8 ip subnet-zero no ip domain-lookup ! ip dhcp snooping vlan 180-181 // 对哪些VLAN 进行限制 ip dhcp snooping ip arp inspection vlan 180-181 ip arp inspection validate src-mac dst-mac ip errdisable recovery cause udld errdisable recovery cause bpduguard errdisable recovery cause security-violation errdisable recovery cause channel-misconfig errdisable recovery cause pagp-flap errdisable recovery cause dtp-flap errdisable recovery cause link-flap errdisable recovery cause l2ptguard errdisable recovery cause psecure-violation errdisable recovery cause gbic-invalid errdisable recovery cause dhcp-rate-limit errdisable recovery cause unicast-flood errdisable recovery cause vmps errdisable recovery cause arp-inspection errdisable recovery interval 30 spanning-tree extend system-id ! ! interface GigabitEthernet2/1 // 对该端口接入的用户进行限制,可以下联交换机 ip arp inspection limit rate 100 arp timeout 2 ip dhcp snooping limit rate 100 ! interface GigabitEthernet2/2 ip arp inspection limit rate 100 arp timeout 2 ip dhcp snooping limit rate 100 ! interface GigabitEthernet2/3 ip arp inspection limit rate 100 arp timeout 2 ip dhcp snooping limit rate 100 ! interface GigabitEthernet2/4 ip arp inspection limit rate 100 arp timeout 2 ip dhcp snooping limit rate 100 --More-- 编者注:对不需要明确地址的所有人的时候是一个很好的解决办法。另外,可以查看www.cisco.com的 IP Source Guard Similar to DHCP snooping, this feature is enabled on a DHCP snooping untrusted Layer 2 port. Initially, all IP traffic on the port is blocked except for DHCP packets that are captured by the DHCP snooping process. When a client receives a valid IP address from the DHCP server, or when a static IP source binding is configured by the user, a per-port and VLAN Access Control List (PACL) is installed on the port. This process restricts the client IP traffic to those source IP addresses configured in the binding; any IP traffic with a source IP address other than that in the IP source binding will be filtered out. This filtering limits a host's ability to attack the network by claiming neighbor host's IP address.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值