STP是为了防止局域网的物理环路,交换机的环路会带来3个问题:广播风暴,同一帧的多次拷贝,交换机的CAM表不稳定。stp基本思路是阻断一些交换机的接口,建立一张无环路的转发树,交换机利用BPDU与其他交换机进行通讯,从而决定那些口阻塞那些口转发。其中BPDU的格式如图

比较重要的是cost of path bridge id 和端口id 这三个决定哪个交换机为根
我们做下实验如图:

我们看下交换机上的vlan信息,这是我上次实验留下的我们清除下,还原交换机初始设置
sw3#show vlan-switch
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa1/0, Fa1/1, Fa1/2, Fa1/3
Fa1/4, Fa1/5, Fa1/6, Fa1/7
Fa1/8, Fa1/9, Fa1/10, Fa1/11
Fa1/12, Fa1/13, Fa1/14, Fa1/15
10 VLAN0010 active
20 msn active
30 laliwangwang active
40 360 active
1002 fddi-default act/unsup
1003 trcrf-default act/unsup
1004 fddinet-default act/unsup
1005 trbrf-default act/unsup
VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
1 enet 100001 1500 - - - - - 1002 1003
10 enet 100010 1500 - - - - - 0 0
20 enet 100020 9818 - - - - - 0 0
30 enet 100030 9818 - - - - - 0 0
40 enet 100040 9818 - - - - - 0 0
VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
1002 fddi 101002 1500 - - - - - 1 1003
1003 trcrf 101003 4472 1005 3276 - - srb 1 1002
1004 fdnet 101004 1500 - - 1 ibm - 0 0
1005 trbrf 101005 4472 - - 15 ibm - 0 0
VLAN AREHops STEHops Backup CRF
---- ------- ------- ----------
1003 7 7 off
清除过程:sw3#delete flash:vla
sw3#delete flash:vlan.dat
Delete filename [vlan.dat]? vlan.dat
Delete flash:vlan.dat? [confirm]y
sw3#erase startup-config 擦除配置
Erasing the nvram filesystem will remove all configuration files! Continue? [confirm]y[OK]
Erase of nvram: complete
sw3#reload 重启下交换机
System configuration has been modified. Save? [yes/no]: y
Building configuration...
[OK]
Proceed with reload? [confirm] y
A summary of U.S. laws governing Cisco cryptographic products may be found at:
http://www.cisco.com/wwl/export/crypto/tool/stqrg.html
If you require further assistance please contact us by sending email to
export@cisco.com.
Cisco 3725 (R7000) processor (revision 0.1) with 124928K/6144K bytes of memory.
Processor board ID XXXXXXXXXXX
R7000 CPU at 240MHz, Implementation 39, Rev 2.1, 256KB L2, 512KB L3 Cache
18 FastEthernet interfaces
DRAM configuration is 64 bits wide with parity enabled.
55K bytes of NVRAM.
16384K bytes of ATA System CompactFlash (Read/Write) 这是cisco3725 的一些信息
sw3#show vlan-switch
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa1/0, Fa1/1, Fa1/2, Fa1/3
Fa1/4, Fa1/5, Fa1/6, Fa1/7
Fa1/8, Fa1/9, Fa1/10, Fa1/11
Fa1/12, Fa1/13, Fa1/14, Fa1/15
1002 fddi-default act/unsup
1003 token-ring-default act/unsup
1004 fddinet-default act/unsup
1005 trnet-default act/unsup
VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
1 enet 100001 1500 - - - - - 1002 1003
1002 fddi 101002 1500 - - - - - 1 1003
1003 tr 101003 1500 1005 0 - - srb 1 1002
1004 fdnet 101004 1500 - - 1 ibm - 0 0
1005 trnet 101005 1500 - - 1 ibm - 0 0
发现没有了上次存在的vlan信息。好我们开始做实验
STP是交换机默认启动的,而具体选择哪个生成树协议就在于你了。我们先什么都不配看看默认下的生成树。sw1 sw2是核心交换机,sw3为接入层交换机,由于我们在sw1和sw2之间启的是trunk链路我们用2层图标。
sw1# show spanning-tree brief
VLAN1
Spanning tree enabled protocol ieee
Root ID Priority 32768 交换机的根
Address c200.0130.0000
Cost 19
Port 42 (FastEthernet1/1)
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Bridge ID Priority 32768 本地交换机状态
Address c200.13dc.0000
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 300
Interface Designated
Name Port ID Prio Cost Sts Cost Bridge ID Port ID
-------------------- ------- ---- ----- --- ----- -------------------- -------
FastEthernet1/1 128.42 128 19 FWD 0 32768 c200.0130.0000 128.42 trunk口是转发的
FastEthernet1/5 128.46 128 19 BLK 19 32768 c200.0f3c.0000 128.46 f1/5是阻塞
sw2#show spanning-tree brief 根交换机 两个口都是指定端口转发流量
VLAN1
Spanning tree enabled protocol ieee
Root ID Priority 32768
Address c200.0130.0000
This bridge is the root
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Bridge ID Priority 32768
Address c200.0130.0000
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 300
Interface Designated
Name Port ID Prio Cost Sts Cost Bridge ID Port ID
-------------------- ------- ---- ----- --- ----- -------------------- -------
FastEthernet1/1 128.42 128 19 FWD 0 32768 c200.0130.0000 128.42
FastEthernet1/6 128.47 128 19 FWD 0 32768 c200.0130.0000 128.47
sw3#show spanning-tree brief
VLAN1
Spanning tree enabled protocol ieee
Root ID Priority 32768
Address c200.0130.0000
Cost 19
Port 47 (FastEthernet1/6)
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Bridge ID Priority 32768
Address c200.0f3c.0000
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 300
Interface Designated
Name Port ID Prio Cost Sts Cost Bridge ID Port ID
-------------------- ------- ---- ----- --- ----- -------------------- -------
FastEthernet1/5 128.46 128 19 FWD 19 32768 c200.0f3c.0000 128.46
FastEthernet1/6 128.47 128 19 FWD 0 32768 c200.0130.0000 128.47
发现即使我们没有设置stp也是运行的,它自动阻塞端口防止形成环路。cisco默认的stp是pvst (per vlan stp )它是基于每个vlan建立一个生成树,缺点:不能快速迁移。即使是在点对点链路或边缘端口,也必须等待2倍的forward delay的时间延迟,网络才能收敛。
我们还可以通过手工指定网桥优先级
sw1(config)#spanning-tree vlan 1 priority ?
<0-65535> bridge priority
sw1(config)#spanning-tree vlan 1 priority 0
或者
sw1(config)#spanning-tree vlan 1 root primary
sw1(config)#spanning-tree vlan 1 root secondary 使用宏命令指定
我们在做2层交换网络的配置还需完成下面的配置
sw1(config)#spanning-tree ?
backbonefast Enable BackboneFast Feature
portfast Spanning tree portfast options
uplinkfast Enable UplinkFast Feature
vlan VLAN Switch Spanning Tree
我们一般在全部交换机上启用backbonefast 在sw3启用uplinkfast 在接入层交换机如果连接时pc或者服务器我们要指定portfast
我们还可以针对接入层的安全启用根防护和BPDU防护
2.下面我们做下快速stp的配置,我们知道在pvst的端口有5种状态:blocking listening learning forwarding disabling,想要从blocking切换至forwarding状态,必需要经过50秒的周期,这50秒我们只能被动地去等待。20秒的blocking状态下,如果没有检测到邻居发来的BPDU包,则进入listening,这时要做的是选举Root Bridge、Designate Port、Root Port,15秒后,进入learning,learning状态下可以学习MAC地址,为最后的forwarding做准备,同样是15秒,最后到达转发状态。而RSTP(802.1w)的出现解决了延时的问题,它的收敛速度很快,当然CISCO也针对这种技术推出了自已的RPVST+技术。RSTP在STP基础上额外定义了两种port role(注意这里的概念,端口角色),分别是alternate与backup。另外重新规定了port state(端口状态),分别为discarding、Learning、Forwarding.

我们配置下
sw1 :spanning-tree mode rapid-pvst
sw1(config)#int f1/5
sw1(config-if)#duplex full
sw1(config-if)#spanning-tree link- type point-to-point (我们需要指定链路类型p2p)

指定链路类型有利于快速stp的运行,上图我标志了3种链路类型和应用情况
MST:MSTP可以将多个VLAN的生成树映射为一个实例,即vlan map to a instance,我们不需要那么多的生成树,只需要按照冗余链路的条数来得出需要几棵生成树。
如果只有两条链路,并且有1-1000个VLAN,我们可以将1-500定义为instance 1,将501-1000定义到instance 2。只生成两棵树1和2,同样实现了冗余与负载分担。
MSTP是基于RSTP的,没有RSTP,MSTP是无法运行的。
sw1(config)#SPanning-tree mode mst
sw1(config)#spanning-tree mst config
name liang
version 1
instance 1 vlan 1-2 (把vlan1 vlan2 映射到实例1)
instance 2 vlan 3-4
spanning-tree mst 1 pri 8192 (设置优先级,两个交换机分为跟,辅 负载均衡)
spanning-tree mst 2 pri 12288
sw2就把优先级改下就行了,互为跟 辅
一般我们在设置是用的做多的cisco默认的pvst+,一来这种配置简单cisco的交换机都支持,mst和rpvst 结合具体情况大家使用
本文转自q狼的诱惑 51CTO博客,原文链接:http://blog.51cto.com/liangrui/423203,如需转载请自行联系原作者