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
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
本文出自 “cisco network” 博客,谢绝转载!