当交换机的接口连接的是主机或服务器时,建议启用portfast功能,从而跳过STP的计算,使接口直接过渡到forwarding状态,当接口连接的是交换机时,接口就会收到交换机发送的BPDU,如果开启了portfast功能,则当接口收到BPDU时,就会关闭接口的portfast功能,但是此接口配置portfast功能是错误的配置,为了杜绝此类错误配置,BPDU Guard功能可以使端口在收到BPDU时,立即被shutdown或进入err-disabled状态。

BPDU Guard功能和portfast功能一样,可以在接口下配置也可以在全局配置,但是操作会有不同:

如果BPDU Guard是全局开启,则只对portfast端口有影响,当portfast端口收到BPDU 后,会shutdown此端口,需要注意,某些型号的交换机会将接口error-disabled。

如果BPDU Guard是接口下开启,将对任何端口有影响,无论是正常端口还是portfast端口,当端口收到BPDU后,会变成error-disabled状态。


全局配置BPDU Guard(只对portfast端口有影响):

Sw2(config)#spanning-tree portfast bpduguard default

Sw2(config)#


接口模式下配置BPDU Guard(对所有的端口有影响,只要端口收到BPDU,端口就进入到err-disable状态):

Sw2(config-if)#spanning-tree bpduguard enable

Sw2(config-if)#

配置好之后如果端口收到了BPDU,则会出现如下log信息:

*Mar 17 02:57:20.153: %SPANTREE-2-BLOCK_BPDUGUARD: Received BPDU on port Et0/0 with BPDU Guard enabled. Disabling port.

Sw2(config-if)#

*Mar 17 02:57:20.153: %PM-4-ERR_DISABLE: bpduguard error detected on Et0/0, putting Et0/0 in err-disable state

*Mar 17 02:57:21.158: %LINEPROTO-5-UPDOWN: Line protocol on Interface Ethernet0/0, changed state to down

Sw2(config-if)#

*Mar 17 02:57:22.157: %LINK-3-UPDOWN: Interface Ethernet0/0, changed state to down

Sw2(config-if)#end

Sw2#sh in

*Mar 17 02:57:26.933: %SYS-5-CONFIG_I: Configured from console by console

Sw2#show inter

Sw2#show interfaces e0/0

Ethernet0/0 is down, line protocol is down (err-disabled)


当端口进入到err-disabled状态时,需要进入到该端口下,手动的shutdown,并no shutdown启用该端口。