STP(spanning-tree protocol,生成树协议),STP的出现是为了解决因冗余链路而形成的环路问题,逻辑上阻塞某些端口的数据转发。
冗余链路可以解决单点链路故障问题,但冗余又会造成环路
环路带来的问题:
1.广播风暴
2.Mac地址表不稳定
3.重复帧的转发
STP的出现刚好能解决以上问题
二层的帧没有防环field;
三层IPv4 header TTL;
routing有防环机制;
so 二层通过生成树防环
在STP中的一种报文——BPDU,可以决定选举:
- 皇帝(根交换机)
- 钦差,传递御旨(指定端口,传递最优的BPDU,用于转发数据)
- 太守,接收,执行皇帝命令(根端口,用于接收最优的BPDU,用于转发业务数据)
- 庶民(非指定端口,在STP的逻辑里是不转发数据的,被阻塞)
生成树交换机上默认开启,根据它的选举原则,所选的根交换机不一定是我们所希望的那个,所以就需要修改它的优先值来选举根
SW2 # sh span vlan 10
VLAN0010
Spanning tree enabled protocol ieee
Root ID Priority 32778 ------优先级
Address aabb.cc00.0100 ------根桥的MAC地址
This bridge is the root ------这个是根桥
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Bridge ID Priority 32778 (priority 32768 sys-id-ext 10)
Address aabb.cc00.0100
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 300 sec
Interface Role Sts Cost Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
Et0/1 Desg FWD 100 128.2 Shr
Et0/2 Desg FWD 100 128.3 Shr
SW1#sh span vlan 10
VLAN0010
Spanning tree enabled protocol ieee
Root ID Priority 32778 ------根桥优先级
Address aabb.cc00.0100 ------根桥MAC
Cost 100 ------到达根桥Cost值
Port 1 (Ethernet0/0) ------与根桥相连的端口
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Bridge ID Priority 32778 (priority 32768 sys-id-ext 10)
Address aabb.cc00.0900
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 300 sec
Interface Role Sts Cost Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
Et0/0 Root FWD 100 128.1 Shr
Et1/3 Desg FWD 100 128.8 Shr
SW3#sh span vlan 10
VLAN0010
Spanning tree enabled protocol ieee
Root ID Priority 32778
Address aabb.cc00.0100
Cost 100
Port 4 (Ethernet0/3)
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Bridge ID Priority 32778 (priority 32768 sys-id-ext 10)
Address aabb.cc00.0700
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 15 sec
Interface Role Sts Cost Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
Et0/3 Root LIS 100 128.4 Shr
Et1/0 Desg LIS 100 128.5 Shr
SW4#sh span vlan 10
VLAN0010
Spanning tree enabled protocol ieee
Root ID Priority 32778
Address aabb.cc00.0100
Cost 200
Port 6 (Ethernet1/1)
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Bridge ID Priority 32778 (priority 32768 sys-id-ext 10)
Address aabb.cc00.0a00
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 300 sec
Interface Role Sts Cost Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
Et1/1 Root FWD 100 128.6 Shr
Et1/2 Altn BLK 100 128.7 Shr
选根桥的时候,优先值默认为32768,再比较MAC地址,地址小的被选为根交换机,MAC越小,说明机器越老,性能越低,所以这时候我们需要人工修改优先级来选举根桥。
如我们想让SW1成为根桥
修改命令如下:
SW1(config)#spanning-tree vlan 10 priority 0
SW1(config)#do sh span vlan 10
VLAN0010
Spanning tree enabled protocol ieee
Root ID Priority 10 ----这里的优先级是vlan-id+优先级
Address aabb.cc00.0900
This bridge is the root ----SW1已成为root
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Bridge ID Priority 10 (priority 0 sys-id-ext 10)
Address aabb.cc00.0900
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 15 sec
Interface Role Sts Cost Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------------------
Et0/0 Desg FWD 100 128.1 Shr
Et1/3 Desg FWD 100 128.8 Shr
网友评论