交换机二层增强特性实验记录

更新时间:2024-05-24 16:52:02 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

一、 UDLD增强特性设计

UDLD(UniDirectional Link Detection)工作原理介绍:

UDLD针对光纤链路故障,工作在物理层模式,如果监测到单向的光纤链路故障出,可 通过erro-disable状态强行将发生故障的端口关闭,避免单向链路故障引起生成树无法 正常运算从而引起通信问题。

设计范围与原则:

?所有交换机的光纤端口都启用UDLD特性。 ?UDLD协商模式为主动方式(aggressive )。 ?Access-SW的接入端口不做设定

测试配置udld网络是否瞬间中断,插拔单芯光纤观察端口状态

(一) UDLD介绍

UDLD (UniDirectional Link Detection 单向链路检测):是一个Cisco私有的二层协议,用于监听利用光纤或双绞线连接的以太链路的物理配置,当出现单向链路(只能向一个方向传输,比如我能把数据发给你,你也能收到,但是你发给我的数据我收不到)时,UDLD可以检测出这一状况,关闭相应接口并发送警告信息。单向链路可能引起很多问题,尤其是生成树,可能会造成回环。注意:UDLD需要链路两端设备都支持才能正常运行。

工作原理维护邻居数据库

检测和回报

交换机会向其邻居发送回复(echo),当邻居在一定时间内没有收到回复,则认为与邻居间的链路出现问题。如果是普通模式,链路有可能会被认为是不确定的状态而不会被关闭(强调一下,普通模式只能检测光纤误解,比如Tx、Rx插反了)。如果是激进模式,则链路会被认为是单向的而被关闭(接口置于err-disable状态)。

UDLD周期型的在每个活动接口上发送hello包(也叫通告advertisement或探针probe)。

当交换机收到hello包后,存储这一信息直到老化时间到期,当老化时间到期前再次收到hello时,则刷新老化时间。 UDLD支持两种工作模式;普通(normal)模式(默认)和激进(aggressive)模式。

普通(normal)模式:这个模式下,UDLD可以检测单向链路,并标记端口为undetermined状态产生系统日志,但并激进(aggressive)模式:这个模式下,UDLD可以检测到由单向链路。并且会尝试重建链路,连续发送8秒的UDLD message,

不影响流量转发。

如果此间没有任何的UDLD echo应答,此端口会被放置于errdisable状态,并不允许任何流量通过。

(二) Cisco下UDLD命令

Cisco全局配置模式下: udld ?

aggressive Enable UDLD protocol in aggressive mode on fiber ports except where locally configured enable Enable UDLD protocol on fiber ports except where locally configured message Set UDLD message parameters

udld message ?

time Set UDLD message time period

udld message time ?

<1-90> Time in seconds between sending of messages in steady state

Cisco接口配置模式下: udld ?

port Enable UDLD protocol on this interface despite global UDLD setting

udld port ?

aggressive Enable UDLD protocol in aggressive mode on this interface despite global UDLD setting disable Disable UDLD protocol on this interface despite global UDLD setting

关于errdisable恢复设置: errdisable recovery cause udld errdisable recovery interval ? <30-86400> timer-interval(sec) 注意:

设备两端的光口,speed 需要设置成非自动协商,否则出现单向链路,端口就会立即物理down,这是光口的特性,所以,如果光端口之间的speed能自动协商,是不需要udld这个功能的。

(三) 使用单台Cisco3750进行环接测试

1. 端口初始配置

interface GigabitEthernet2/0/1 no switchport no ip address speed nonegotiate !

interface GigabitEthernet2/0/2 speed nonegotiate spanning-tree portfast

端口状态:

Interface IP-Address OK? Method Status Protocol GigabitEthernet2/0/1 unassigned YES unset up up GigabitEthernet2/0/2 unassigned YES unset up up

拔一芯,端口状态:

Interface IP-Address OK? Method Status Protocol GigabitEthernet2/0/1 unassigned YES unset up up GigabitEthernet2/0/2 unassigned YES unset down down 一端端口依然up,另一端端口down,满足实验前提。

2. 对端口设置udld,使用默认普通模式

端口配置:

interface GigabitEthernet2/0/1 no switchport no ip address speed nonegotiate udld port !

interface GigabitEthernet2/0/2 speed nonegotiate udld port

spanning-tree portfast

show udld: Interface Gi2/0/1 ---

Port enable administrative configuration setting: Enabled Port enable operational state: Enabled Current bidirectional state: Bidirectional

Current operational state: Advertisement - Single neighbor detected Message interval: 7 Time out interval: 5

Entry 1 ---

Expiration time: 45 Device ID: 1

Current neighbor state: Bidirectional Device name: FDO1515V0BS Port ID: Gi2/0/2

Neighbor echo 1 device: FDO1515V0BS Neighbor echo 1 port: Gi2/0/1

Message interval: 15 Time out interval: 5 CDP Device name: Switch

Interface Gi2/0/2 ---

Port enable administrative configuration setting: Enabled Port enable operational state: Enabled Current bidirectional state: Bidirectional

Current operational state: Advertisement - Single neighbor detected Message interval: 7 Time out interval: 5

Entry 1 ---

Expiration time: 43 Device ID: 1

Current neighbor state: Bidirectional Device name: FDO1515V0BS Port ID: Gi2/0/1

Neighbor echo 1 device: FDO1515V0BS Neighbor echo 1 port: Gi2/0/2

Message interval: 15 Time out interval: 5 CDP Device name: Switch

可见当期的邻居状态为Bidirectional,双向的。

拔一芯,当Expiration time为0时,show udld: Interface Gi2/0/1 ---

Port enable administrative configuration setting: Enabled Port enable operational state: Enabled Current bidirectional state: Unknown Current operational state: Advertisement Message interval: 7 Time out interval: 5

No neighbor cache information stored

说是有log,目前没有产生log,这个需要研究下

端口状态:

GigabitEthernet2/0/1 unassigned YES unset up up GigabitEthernet2/0/2 unassigned YES unset down down

3. 对端口设置udld,使用aggressive模式

端口配置:

interface GigabitEthernet2/0/1 no switchport no ip address speed nonegotiate udld port aggressive !

interface GigabitEthernet2/0/2 speed nonegotiate udld port aggressive spanning-tree portfast

show udld: Interface Gi2/0/1 ---

Port enable administrative configuration setting: Enabled / in aggressive mode Port enable operational state: Enabled / in aggressive mode Current bidirectional state: Bidirectional

Current operational state: Advertisement - Single neighbor detected Message interval: 15 Time out interval: 5

Entry 1 ---

Expiration time: 40 Device ID: 1

Current neighbor state: Bidirectional Device name: FDO1515V0BS Port ID: Gi2/0/2

Neighbor echo 1 device: FDO1515V0BS Neighbor echo 1 port: Gi2/0/1

Message interval: 15 Time out interval: 5 CDP Device name: Switch Interface Gi2/0/2 ---

Port enable administrative configuration setting: Enabled / in aggressive mode Port enable operational state: Enabled / in aggressive mode Current bidirectional state: Bidirectional

Current operational state: Advertisement - Single neighbor detected Message interval: 15

Time out interval: 5

Entry 1 ---

Expiration time: 39 Device ID: 1

Current neighbor state: Bidirectional Device name: FDO1515V0BS Port ID: Gi2/0/1

Neighbor echo 1 device: FDO1515V0BS Neighbor echo 1 port: Gi2/0/2

Message interval: 15 Time out interval: 5 CDP Device name: Switch

拔一芯:当Expiration time为0时,show udld Interface Gi2/0/1 ---

Port enable administrative configuration setting: Enabled / in aggressive mode Port enable operational state: Enabled / in aggressive mode Current bidirectional state: Unknown Current operational state: Disabled port Message interval: 7 Time out interval: 5

No neighbor cache information stored

有log输出:

*Mar 1 17:08:54.088: %UDLD-4-UDLD_PORT_DISABLED: UDLD disabled interface Gi2/0/1, aggressive mode failure detected *Mar 1 17:08:54.088: %PM-4-ERR_DISABLE: udld error detected on Gi2/0/1, putting Gi2/0/1 in err-disable state *Mar 1 17:08:54.138: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet2/0/1, changed state to down *Mar 1 17:08:56.093: %LINK-3-UPDOWN: Interface GigabitEthernet2/0/1, changed state to down

4. 一个端口设置udld aggressive,另一个端口不设置udld

端口配置:

interface GigabitEthernet2/0/1 no switchport no ip address speed nonegotiate udld port aggressive !

interface GigabitEthernet2/0/2

speed nonegotiate spanning-tree portfast

show udld: Interface Gi2/0/1 ---

Port enable administrative configuration setting: Enabled / in aggressive mode Port enable operational state: Enabled / in aggressive mode Current bidirectional state: Unknown Current operational state: Advertisement Message interval: 7 Time out interval: 5

No neighbor cache information stored

Interface Gi2/0/2 ---

Port enable administrative configuration setting: Follows device default Port enable operational state: Disabled Current bidirectional state: Unknown 可见,两个端口都没有学到邻居信息

拔一芯,查看控制台,无输出,可见,udld不起作用,因为学不到邻居信息 所以,一对端口,必须同时启用udld,udld功能才能正常起作用。

5. 一个端口udld设置默认模式,一个端口设置aggressive模式

结果与udld定义一致,拔一芯,如果亮的端口设置的是默认模式,则一直亮;如果亮的端口设置的是aggressive模式,Expiration time为0,端口则会err-disabled。

6. 关于errdisable recovery的测试

配置如下:

errdisable recovery cause udld errdisable recovery interval 30

拔一芯,log输出如下:

*Mar 1 01:58:20.537: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet2/0/2, changed state to down *Mar 1 01:58:22.541: %LINK-3-UPDOWN: Interface GigabitEthernet2/0/2, changed state to down

*Mar 1 01:59:05.055: %UDLD-4-UDLD_PORT_DISABLED: UDLD disabled interface Gi2/0/1, aggressive mode failure detected *Mar 1 01:59:05.055: %PM-4-ERR_DISABLE: udld error detected on Gi2/0/1, putting Gi2/0/1 in err-disable state *Mar 1 01:59:05.105: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet2/0/1, changed state to down *Mar 1 01:59:07.060: %LINK-3-UPDOWN: Interface GigabitEthernet2/0/1, changed state to down *Mar 1 01:59:35.094: %PM-4-ERR_RECOVER: Attempting to recover from udld err-disable state on Gi2/0/1

*Mar 1 01:59:37.166: %LINK-3-UPDOWN: Interface GigabitEthernet2/0/1, changed state to up

*Mar 1 01:59:37.175: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet2/0/1, changed state to up

udld检测,发现端口出现单向链路,置端口err-disable状态,然后errdisable recovery起作用,端口状态被恢复成up,此时udld已经失效,因为依然是单向链路,学不到邻居信息。

(四) 使用Cisco3750与LP连接测试

与lp连接,3750g交换机端口speed不能设置nonegotiate,因为lp端口不亮,这样测试将无法进行。

(五) 使用Cisco3750与H3C7506连接测试

最后进行测试,需要16A插排,先往后进行。

(六) 总结

UDLD,UniDirectional Link Detection—单向链路检测,是Cisco私有的二层协议,也是Cisco特有的名词。

当光纤链路,出现单向链路时,互联端口有时会出现一端端口亮up,一端端口灭down的情况,这种情况,会产生譬

如生成树无法正常运算,影响通信,或者监控无法正常报警等问题,这时,如果光纤链路两端互联的设备均为Cisco,就可以通过udld这个特性解决此类问题。

这时,依然up的端口,如果配置成udld aggressive,则此端口会置为err-disable。

但是,如果光纤链路两端的端口speed是自动协商的,出现单向链路时,两端端口会都灭,是不需要udld的,这是光

端口的特性。

所以,当光纤链路两端端口的speed协商模式是nonegotiate时,建议使用udld这个特性。

配置示例:

Switch(config)#errdisable recovery cause udld Switch(config)#errdisable recovery interval 3600 Switch(config)#int g2/0/1

Switch(config-if)#udld port aggressive 其中: ? ?

errdisable recovery interval恢复时间为30到86400秒,默认为300秒,5分钟

当errdisable recovery后,如果依然是单向链路,则udld将失效,因为学不到对应的邻居信息,不能执行必要的hello检测,恢复的端口,会一直up下去。 注意: ? ?

光纤链路互联的两个端口,必须同时配置udld

如果光纤链路互联端口的speed可以自动协商,不需要使用udld,因为不会产生单向链路的问题,只要有一个链路有问题,互联两个端口都会down。

二、 广播及组播流量控制设计

Interface range fa0/1 -xxx

storm-control broadcast level 8.00 4.00 storm-control multicast level 8.00 4.00 storm-control action shutdown

设计要点:ES交换机接入端口上监视广播及组播流量,通过控制广播及组播的流量实现 对整体网络带宽的保护,在出现广播风暴时及时抑制。 设定范围:

?所有ES交换机接入端口。

?通过对端口带宽广播及组播流量的百分比进行阀值设定。

?LAN设定界限值(端口带宽百分比):当端口收到的广播或者组播流量达到端口带宽的8%时(8Mbps), 端口将通过Shutdown动作进行保护,流量下降到4%时端口将自动恢复原先状态。 测试广播包大时shutdown及恢复时间

(一) cisco下storm-control命令

接口配置模式下: storm-control ?

action Action to take for storm-control broadcast Broadcast address storm control multicast Multicast address storm control unicast Unicast address storm control

storm-control action ?

shutdown Shutdown this interface if a storm occurs trap Send SNMP trap if a storm occurs

storm-control broadcast ?

level Set storm suppression level on this interface

storm-control broadcast level 0.8 ? <0.00 - 100.00> Enter falling threshold

(二) 模拟广播风暴产生环境

1、交换机初始配置 2、环接交换机两个端口 3、no spanning-tree vlan 1

4、用网线,把电脑与交换机任一端口进行连接

5、产生广播风暴,交换机CPU与端口流量均大幅提高

产生广播风暴时,log的输出示例:

*Mar 1 00:04:50.958: %SW_MATM-4-MACFLAP_NOTIF: Host d4be.d92d.1893 in vlan 1 is flapping between port Gi2/0/5 and port Gi2/0/2

*Mar 1 00:05:01.931: %SW_MATM-4-MACFLAP_NOTIF: Host d4be.d92d.1893 in vlan 1 is flapping between port Gi2/0/1 and port Gi2/0/2

*Mar 1 00:05:17.055: %SW_MATM-4-MACFLAP_NOTIF: Host d4be.d92d.1893 in vlan 1 is flapping between port Gi2/0/2 and port Gi2/0/1

*Mar 1 00:05:32.155: %SW_MATM-4-MACFLAP_NOTIF: Host d4be.d92d.1893 in vlan 1 is flapping between port Gi2/0/2 and port Gi2/0/1 ......

端口流量: sh int g2/0/1

GigabitEthernet2/0/1 is up, line protocol is up (connected)

Hardware is Gigabit Ethernet, address is 0036.ffaa.3781 (bia 0036.ffaa.3781) MTU 1500 bytes, BW 1000000 Kbit, DLY 10 usec, reliability 255/255, txload 32/255, rxload 32/255 Encapsulation ARPA, loopback not set Keepalive not set

Full-duplex, 1000Mb/s, link type is auto, media type is 1000BaseSX SFP input flow-control is off, output flow-control is unsupported ARP type: ARPA, ARP Timeout 04:00:00

Last input 00:00:00, output 00:00:01, output hang never Last clearing of \

Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 208 Queueing strategy: fifo Output queue: 0/0 (size/max)

5 minute input rate 128709000 bits/sec, 182816 packets/sec 5 minute output rate 128898000 bits/sec, 182237 packets/sec 87752023 packets input, 7753956242 bytes, 0 no buffer Received 87752023 broadcasts (32393650 multicasts) ......

88340976 packets output, 7848486122 bytes, 0 underruns ......

CPU使用率: sh processes cpu

CPU utilization for five seconds: 43%/32%; one minute: 29%; five minutes: 13%

(三) 实验步骤与记录

A.

使用cisco871充当hub使用,871一个lan端口与3750g的Gi2/0/5连接,待端口稳定后:

Switch#sh port-security

Secure Port MaxSecureAddr CurrentAddr SecurityViolation Security Action (Count) (Count) (Count) ---------------------------------------------------------------------------

Gi2/0/5 1 1 0 Shutdown --------------------------------------------------------------------------- Total Addresses in System (excluding one mac per port) : 0 Max Addresses limit in System (excluding one mac per port) : 6144

Switch#sh port-security address Secure Mac Address Table

------------------------------------------------------------------------

Vlan Mac Address Type Ports Remaining Age (mins) ---- ----------- ---- ----- ------------- 1 0019.e75b.1e79 SecureDynamic Gi2/0/5 - ------------------------------------------------------------------------ Total Addresses in System (excluding one mac per port) : 0 Max Addresses limit in System (excluding one mac per port) : 6144 B.

电脑与871另一个lan口连接,log输入如下:

*Mar 1 00:38:20.667: %PM-4-ERR_DISABLE: psecure-violation error detected on Gi2/0/5, putting Gi2/0/5 in err-disable state *Mar 1 00:38:20.718: %PORT_SECURITY-2-PSECURE_VIOLATION: Security violation occurred, caused by MAC address d4be.d92d.1893 on port GigabitEthernet2/0/5.

*Mar 1 00:38:20.726: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet2/0/5, changed state to down *Mar 1 00:38:22.672: %LINK-3-UPDOWN: Interface GigabitEthernet2/0/5, changed state to down 其中,d4be.d92d.1893为电脑mac地址。 C.

断开电脑与871的连接,等待errdisable recovery恢复:

*Mar 1 00:38:50.715: %PM-4-ERR_RECOVER: Attempting to recover from psecure-violation err-disable state on Gi2/0/5 *Mar 1 00:38:54.927: %LINK-3-UPDOWN: Interface GigabitEthernet2/0/5, changed state to up

*Mar 1 00:38:54.935: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet2/0/5, changed state to up D.

871换另一个未使用的端口与3750g的Gi2/0/5连接,待端口稳定后:

Switch#sh port-security

Secure Port MaxSecureAddr CurrentAddr SecurityViolation Security Action (Count) (Count) (Count) ---------------------------------------------------------------------------

Gi2/0/5 1 1 0 Shutdown ---------------------------------------------------------------------------

Total Addresses in System (excluding one mac per port) : 0 Max Addresses limit in System (excluding one mac per port) : 6144

Switch#sh port-security address Secure Mac Address Table

------------------------------------------------------------------------

Vlan Mac Address Type Ports Remaining Age (mins) ---- ----------- ---- ----- ------------- 1 0019.e75b.1e7c SecureDynamic Gi2/0/5 - ------------------------------------------------------------------------ Total Addresses in System (excluding one mac per port) : 0 Max Addresses limit in System (excluding one mac per port) : 6144

可见,本次871使用端口mac 0019.e75b.1e7c与步骤A中871使用端口mac 0019.e75b.1e79是不同的,但可以正常接入。

Switch#sh log

*Mar 1 00:46:44.403: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet2/0/5, changed state to down *Mar 1 00:46:46.400: %LINK-3-UPDOWN: Interface GigabitEthernet2/0/5, changed state to down *Mar 1 00:46:48.405: %LINK-3-UPDOWN: Interface GigabitEthernet2/0/5, changed state to up

*Mar 1 00:46:48.413: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet2/0/5, changed state to up log信息也正常。

(四) 总结

为了实现交换机端口接入安全,防止用户私接hub,cisco需要做如下配置:(不考虑默认参数) 1.

全局模式下配置:

errdisable recovery cause psecure-violation errdisable recovery interval 30

其中recovery的时间,根据实际情况酌情设置,范围为30-86400秒,最大为24小时 2.

接口模式下配置:

switchport mode access switchport port-security

switchport port-security maximum 1 switchport port-security violation shutdown

其中第一条语句必须有,因为端口安全必须在access 模式下做,否则第二条语句不能设置

通过以上配置,当用户私接hub时,相对应的交换机端口将会被置为err-disable状态,端口的err-disable状态会根据

设置的errdisable recovery时间间隔,进行尝试恢复,如果hub依然连接,此端口将会再次被置为errdisable状态,直到撤掉hub,此端口才会恢复正常状态。

当用户更换电脑,接入时间,只为端口正常协商时间,如果端口配置为spanning-tree portfast,将接入更快,端口配置

的接入安全参数,不影响用户更换电脑,只要不违反mac数目限制即可。

四、 DHCP Snooping

---全局配置--- ip dhcp snooping

---全局上启用dhcp snooping--- ip dhcp snooping vlan 8

---在VLAN8上启用dhcp snooping--- ip dhcp snooping database flash:/pool ----建立一个database,命名为pool--- ip dhcp snooping database write-delay 30 ip dhcp snooping database timeout 180 要点说明:

? 对连接办公区与外围的ES交换机、连接车间的ES交换机进行DHCP Snooping特性设定。

? 对于使用静态IP的终端设备,使用ARP ACL把IP与相应的MAC地址进行捆绑,说见IP arp inspection设计。

如果内部有一台电脑私自架设DHCP服务器,其他客户端不会受到影响,因为非法的DHCP数据包被ES所丢弃,不能发送到其它交换机去。

(一) cisco下DHCP Snooping命令

全局配置模式下: ip dhcp snooping ?

database DHCP snooping database agent information DHCP Snooping information verify DHCP snooping verify vlan DHCP Snooping vlan 说明:

ip dhcp snooping information option默认是开启的。

ip dhcp snooping database ? flash2: Database agent URL flash: Database agent URL ftp: Database agent URL http: Database agent URL rcp: Database agent URL tftp: Database agent URL

timeout Configure abort timeout interval

ip dhcp snooping vlan ?

WORD DHCP Snooping vlan first number or vlan range, example: 1,3-5,7,9-11

#0-86400 sec #15-86400 sec

write-delay Configure delay timer for writes to URL

接口配置模式下: ip dhcp snooping ?

information DHCP Snooping information limit DHCP Snooping limit trust DHCP Snooping trust config vlan DHCP Snooping vlan 说明:

如果全局开启ip dhcp snooping,所有端口默认为untrust端口。

(二) 实验环境搭建

简单拓扑图:

DHCP server ACisco 3750DHCP server BCisco 871接入交换机 CCisco 3750PC

说明: ? ? ? 其中:

DHCP server A 3750交换机,分配172.16.1.0 /24的地址: Switch (config)#service dhcp

//开启DHCP 服务,默认是开启的 //定义地址池

//DHCP 服务器要分配的网络和掩码 //定义租期

//排除的地址段

DHCP server A设定为合法DHCP服务器,DHCP server B设定为非法DHCP服务器 接入交换机C,连接两台DHCP服务器 PC机连接接入交换机C,设置成自动获取IP

Switch (config)#ip dhcp pool test-dhcp-pool Switch (dhcp-config)#network 172.16.1.0 /24 Switch (dhcp-config)#lease infinite Switch (dhcp-config)#exit Switch (config)#int vlan 1

Switch (config-if)#ip add 172.16.1.1 255.255.255.0 Switch (config-if)#ip dhcp relay information trusted

Switch (config-if)#int g2/0/5

Switch (config)#ip dhcp excluded-address 172.16.1.1 172.16.1.5

//连接 接入交换机C

Switch (config-if)#ip dhcp relay information trusted

DHCP server B 871路由器,分配192.168.1.0 /24的地址: Router (config)#service dhcp

//开启DHCP 服务,默认是开启的 //定义地址池

//DHCP 服务器要分配的网络和掩码 //定义租期

//排除的地址段

Router (config)#ip dhcp pool test-dhcp-pool Router (dhcp-config)#network 192.168.1.0 /24 Router (dhcp-config)#lease infinite Router(dhcp-config)#exit

Router(config)#int vlan 1

Router(config-if)#ip add 192.168.1.1 255.255.255.0

接入交换机C,初始配置为: interface Vlan1

ip address 192.168.1.2 255.255.255.0 !

Router (config)#ip dhcp excluded-address 192.168.1.1 192.168.1.5

为了telent到两台DHCP服务器,方便测试,不配置对实验没有影响。

(三) 实验步骤与记录

1. PC机自动获取IP测试

使用ipconfig /renew、ipconfig /renew两个命令,反复自动获取IP,获取的IP如下图:

可以看出,可以获取到DHCP server A分配的IP,也可以获取到DHCP server B分配的IP

2. DHCP Snooping的配置

全局配置模式下:

Switch(config)#ip dhcp snooping Switch(config)#ip dhcp snooping vlan 1

其中:必须配置相应的vlan,否则dhcp snooping不会起作用。

arp access-list static-ip

//建立ARP ACL,把分配的静态IP与相应终端设备的MAC地址进行捆绑 //把建立的ARP ACL应用到VLAN 1中

permit ip host “ip address” mac host “mac address” ip arp inspection filter static-ip vlan 1

(二) 实验步骤与记录

1. 实验环境

在“四、DHCP Snooping”实验的基础上进行,因为arp inspection是以dchp snooping为基础的。

2. arp inspection功能测试

A.

交换机配置:

Switch(config)#ip arp inspection vlan 1

Switch(config)#ip arp inspection validate src-mac ip Switch(config)#ip arp inspection log-buffer entries 1024

Switch(config)#ip arp inspection log-buffer logs 1024 interval 300 Switch(config)#errdisable recovery cause arp-inspection

Switch(config)#int g1/0/1

Switch(config-if)# ip arp inspection trust

Switch(config)#int g1/0/11

Switch(config-if)# ip arp inspection limit rate 2 B.

PC机通过DHCP自动获取IP

//限制端口每秒内通过的arp数据包为2个,默认15

//连接DHCP服务器,不设置PC虽然能获取到IP,但 //是影响正常通信,比如pc不能ping通dhcp服务器

//启用errdisable自动恢复

PC机通信正常。 C.

PC机手动更改IP

IP指定为 172.16.1.14 255.255.255.0

sh log

00:46:53: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet1/0/11, changed state to down 00:46:54: %LINK-3-UPDOWN: Interface GigabitEthernet1/0/11, changed state to down

00:46:57: %SW_DAI-4-DHCP_SNOOPING_DENY: 1 Invalid ARPs (Req) on Gi1/0/11, vlan 1.([d4be.d92d.1893/0.0.0.0/0000.0000.0000/172.16.1.14/00:46:56 UTC Mon Mar 1 1993])

00:46:58: %SW_DAI-4-DHCP_SNOOPING_DENY: 1 Invalid ARPs (Req) on Gi1/0/11, vlan 1.([d4be.d92d.1893/0.0.0.0/0000.0000.0000/172.16.1.14/00:46:57 UTC Mon Mar 1 1993])

00:46:58: %LINK-3-UPDOWN: Interface GigabitEthernet1/0/11, changed state to up

00:46:59: %SW_DAI-4-DHCP_SNOOPING_DENY: 1 Invalid ARPs (Req) on Gi1/0/11, vlan 1.([d4be.d92d.1893/0.0.0.0/0000.0000.0000/172.16.1.14/00:46:58 UTC Mon Mar 1 1993])

00:46:59: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet1/0/11, changed state to up

sh ip dhcp snooping binding

MacAddress IpAddress Lease(sec) Type VLAN Interface ------------------ --------------- ---------- ------------- ---- --------------------

D4:BE:D9:2D:18:93 172.16.1.6 infinite dhcp-snooping 1 GigabitEthernet1/0/11 Total number of bindings: 1 绑定信息没变,不是172.16.1.14。

sh ip arp inspection statistics

Vlan Forwarded Dropped DHCP Drops ACL Drops ---- --------- ------- ---------- ---------

1 0 3 3 0 Vlan DHCP Permits ACL Permits Source MAC Failures ---- ------------ ----------- -------------------

1 0 0 0 Vlan Dest MAC Failures IP Validation Failures Invalid Protocol Data ---- ----------------- ---------------------- ---------------------

1 0 0 0 丢弃的相关arp信息。

PC机状况

PC机无法通信。

Ping产生的新log

00:51:35: %SW_DAI-4-DHCP_SNOOPING_DENY: 1 Invalid ARPs (Req) on Gi1/0/11, vlan 1.([d4be.d92d.1893/172.16.1.14/0000.0000.0000/172.16.1.1/00:51:35 UTC Mon Mar 1 1993])

00:51:36: %SW_DAI-4-DHCP_SNOOPING_DENY: 1 Invalid ARPs (Req) on Gi1/0/11, vlan 1.([d4be.d92d.1893/172.16.1.14/0000.0000.0000/172.16.1.1/00:51:36 UTC Mon Mar 1 1993])

00:51:37: %SW_DAI-4-DHCP_SNOOPING_DENY: 1 Invalid ARPs (Req) on Gi1/0/11, vlan 1.([d4be.d92d.1893/172.16.1.14/0000.0000.0000/172.16.1.1/00:51:37 UTC Mon Mar 1 1993])

sh ip arp inspection statistics

Vlan Forwarded Dropped DHCP Drops ACL Drops ---- --------- ------- ---------- ---------

1 0 6 6 0 Vlan DHCP Permits ACL Permits Source MAC Failures ---- ------------ ----------- -------------------

1 0 0 0 Vlan Dest MAC Failures IP Validation Failures Invalid Protocol Data ---- ----------------- ---------------------- ---------------------

1 0 0 0 丢弃的arp又多了3条。

通过测试,可见应用了arp inspection后,终端设备通过手动指定IP,是无法进行正常通信的,也就是说,防止了用户手动指定IP的行为。

3. ip arp inspection limit rate测试

PC机自动获取IP,打开三个cmd窗口,分别同时ping 172.16.1.2、172.16.1.3、172.16.1.4,模拟arp请求速率。 log输出

01:09:50: %SW_DAI-4-PACKET_RATE_EXCEEDED: 3 packets received in 989 milliseconds on Gi1/0/11.

01:09:50: %PM-4-ERR_DISABLE: arp-inspection error detected on Gi1/0/11, putting Gi1/0/11 in err-disable state 01:09:51: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet1/0/11, changed state to down 01:09:52: %LINK-3-UPDOWN: Interface GigabitEthernet1/0/11, changed state to down 端口err-disable

如果PC机手动指定IP为172.16.1.14,进行同样的ping操作: log输出

01:06:03: %SW_DAI-4-DHCP_SNOOPING_DENY: 1 Invalid ARPs (Req) on Gi1/0/11, vlan 1.([d4be.d92d.1893/172.16.1.14/0000.0000.0000/172.16.1.4/01:06:02 UTC Mon Mar 1 1993])

01:06:03: %SW_DAI-4-DHCP_SNOOPING_DENY: 1 Invalid ARPs (Req) on Gi1/0/11, vlan 1.([d4be.d92d.1893/172.16.1.14/0000.0000.0000/172.16.1.3/01:06:03 UTC Mon Mar 1 1993])

01:06:03: %SW_DAI-4-PACKET_RATE_EXCEEDED: 3 packets received in 780 milliseconds on Gi1/0/11.

01:06:03: %PM-4-ERR_DISABLE: arp-inspection error detected on Gi1/0/11, putting Gi1/0/11 in err-disable state

01:06:04: %SW_DAI-4-DHCP_SNOOPING_DENY: 1 Invalid ARPs (Req) on Gi1/0/11, vlan 1.([d4be.d92d.1893/172.16.1.14/0000.0000.0000/172.16.1.4/01:06:03 UTC Mon Mar 1 1993])

01:06:04: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet1/0/11, changed state to down 01:06:05: %LINK-3-UPDOWN: Interface GigabitEthernet1/0/11, changed state to down

通过测试,可见ip arp inspection limit rate的设置,只是限制arp请求的速率,与是否手动指定IP无关,只有违反设定的arp请求速率,端口才会被置为err-disable状态。

4. 允许用户使用静态IP测试

A.

交换机配置:

//建立ARP ACL,把分配的静态IP与相应终端设备的MAC地址进行捆绑

Switch(config)#arp access-list static-ip Switch(config-arp-nacl)#exit

Switch(config-arp-nacl)#permit ip host 172.16.1.14 mac d4be.d92d.1893 Switch(config)#ip arp inspection filter static-ip vlan 1

//把建立的ARP ACL应用到VLAN 1中

IP为需要手动指定的动态IP,mac为PC机物理网卡对应的mac B.

测试PC机的连通性

通过以上配置,即使应用了arp inspection,也可以允许指定的mac使用指定的IP,既可以允许用户使用静态IP。

(三) 总结

在ip dhcp snooping的基础上,可以通过ip arp inspection防止用户不通过DHCP自动获取IP,而直接指定IP的行为。 在ip arp inspection限制下,如果终端设备需要使用静态IP,可以通过ip arp inspection filter来实现。

在配置dhcp snooping的基础上(需要其建立的mac与ip的binding信息): 1.

配置arp inspection基本功能:

//对指定vlan启用arp inspection //对src-mac、ip进行检查 //设置log buffer的条目数 //每3秒钟,记录10条log

Switch(config)#ip arp inspection vlan 1

Switch(config)#ip arp inspection validate src-mac ip Switch(config)#ip arp inspection log-buffer entries 1024

Switch(config)#int g1/0/1

Switch(config-if)# ip arp inspection trust

Switch(config)#ip arp inspection log-buffer logs 10 interval 3

//连接DHCP服务器,不设置PC虽然能获取到IP,但 //是影响正常通信,比如pc不能ping通dhcp服务器

//所以此端口需要设置为arp inspection信任端口

其中,对于不需要进行arp inspection的端口,需要配置成信任端口,一般非直接连接终端的端口,建议配置成信任端口。 2.

防止ARP病毒攻击:

//启用errdisable自动恢复

//限制端口每秒内通过的arp数据包为20个,默认15

Switch(config)#errdisable recovery cause arp-inspection Switch(config)#int g1/0/11

Switch(config-if)# ip arp inspection limit rate 20

通过限制通过端口的arp包的速率,可以防止arp病毒的攻击,当端口每秒接受到的arp请求超过设定数值后,相应的端口会置为err-disable状态,可以通过errdisable recovery尝试恢复端口的状态。

3.

允许用户使用静态IP:

//建立ARP ACL,把分配的静态IP与相应终端设备的MAC地址进行捆绑

Switch(config)#arp access-list static-ip Switch(config-arp-nacl)#exit

Switch(config-arp-nacl)#permit ip host 172.16.1.14 mac d4be.d92d.1893 Switch(config)#ip arp inspection filter static-ip vlan 1

//把建立的ARP ACL应用到VLAN 1中

上面的配置只是个示例,根据实际情况,使用对应的IP与MAC地址,添加需要的arp准许条目数。

本文来源:https://www.bwwdw.com/article/edw7.html

Top