一篇文章让你明白STP生成树协议

简介: STP(Spanning Tree Protocol)协议(生成树协议)逻辑上断开环路,防止二层网络的广播风暴的产生。

文章核心:


1.STP协议是什么?

2.STP选举规则

3.STP简单实验

4.STP基本配置


一、STP(Spanning Tree Protocol)协议(生成树协议)逻辑上断开环路,防止二层网络的广播风暴的产生。



二、关键问题:


(1)为什么要用STP协议?


为了解决第二层网络环路问题而又要保证网络的稳定和健壮性,引入了链路动态管理的策略。首先通过阻塞某些链路避免环路的产生(避免环路),当正常工作的链路由于故障断开时,阻塞的链路立刻激活,迅速取代故障链路的位置,保证网络的正常运行。(生成冗余链路)这就是生成树(STP)协议。


(2)解决环路问题


避免环路


每个LAN都会选择一台设备为指定交换机,通过该设备的端口连接到根,该端口为指定端口( Designated port )


将交换网络中所有设备的根端口(RP)和指定端口(DP)设为转发状态(Forwarding),将其他端口设为阻塞状态(Blocking)

生成树经过一段时间(默认值是50秒左右)稳定之后,所有端口要么进入转发状态,要么进入阻塞状态。


(3)建立冗余链路让网络更稳定


冗余链路可以理解为备份链路,其他链路出现问题了备份的冗余链路会代替上去,维持网络稳定


三、STP收敛过程


说白了就是我在一个阶段给你发请求你长时间不回应,我会结束这个阶段进入下一个阶段


当网络的拓扑发生变化时,网络会从一个状态向另一个状态过渡,重新打开或阻断某些端口。交换机的端口要经过几种状态:禁用(Disable)——>阻塞(Blocking)——>监听状态(Listenning)——>学习状态(Learning)——>转发状态(Forwarding)


四、STP中根桥,根端口,指定端口的选举规则:


1.在一个广播域选择一个根桥


使用stp协议,会向邻居s发送BPDU,bridge protocol date unit

交换机向所在广播域发送的bpdu

内容有:

bridge ID

优先级

mac地址


选举规则:


主板mac地址,交换机端口mac地址是端口号+主板mac地址得来

查看优先级,mac地址,网桥ID依次查看选取最小的为根桥


2.每个非根桥选择一个根端口(RP)


1.路径成本最低

2.直连的网桥id最小

3.最低发送者端口id最小


3.每个段选择一个指定端口(DP)


每一个线连接的两段选一个指定端口,RP的对端肯定是DP

对比bri id优先成为dp,另一个无身份


4.阻塞非指定端口


没有身份的会被阻塞掉,称为AP,用来防环

指定端口发bpdu,根端口接受


5.个端口状态


block 非指定端口回到block状态

listen 监听bpdu,不能学习mac地址,不转发数据,维持15秒,确定端口角色!

learn 学习mac地址,不转发数据,维持15秒

forword 可转发数据

disable 禁用


五、实验部分:


1.理解STP中端口角色变化规则
2.掌握基本配置STP协议


一、在Cisco模拟器中拖三台交换机连接查看他们的默认生成树情况


微信图片_20220509084618.png


我们在图中也可以看出S0为根桥两个端口分别是指定端口


S1两个端口与S0对应的端口为根端口,另一个为指定端口
S2两个端口与S0对应的为根端口,另一个为非指定端口(阻塞端口)


黄色的等代表就是阻塞端口(非指定端口)


S0
Switch#show spanning-tree 
VLAN0001
  Spanning tree enabled protocol ieee
# 根桥的信息
  Root ID    Priority    32769 # 根桥的优先级
             Address     0001.63D0.3450 # 根桥的mac地址
             This bridge is the root # 这个s是根桥
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
  Bridge ID  Priority    32769  (priority 32768 sys-id-ext 1)
             Address     0001.63D0.3450
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  20
Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/1            Desg FWD 19        128.1    P2p # 可以看出与根桥两个端口都是指定端口
Fa0/2            Desg FWD 19        128.2    P2p # 指定端口
S1
Switch#show spanning-tree 
VLAN0001
  Spanning tree enabled protocol ieee
  Root ID    Priority    32769
             Address     0001.63D0.3450
             Cost        19
             Port        1(FastEthernet0/1)
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
  Bridge ID  Priority    32769  (priority 32768 sys-id-ext 1)
             Address     0090.216C.B791
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  20
Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/2            Desg FWD 19        128.2    P2p # 指定端口,妆发状态
Fa0/1            Root FWD 19        128.1    P2p # 根端口(与),转发状态
S2
Switch#show spanning-tree 
VLAN0001
  Spanning tree enabled protocol ieee
  Root ID    Priority    32769
             Address     0001.63D0.3450
             Cost        19
             Port        1(FastEthernet0/1)
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
  Bridge ID  Priority    32769  (priority 32768 sys-id-ext 1)
             Address     00E0.A3D9.8D5E
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  20
Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/1            Root FWD 19        128.1    P2p #根端口,处于转发状态
Fa0/2            Altn BLK 19        128.2    P2p #阻塞端口,处于block状态


二、更改根桥,设置备份根桥,查看结果


微信图片_20220509084742.png


从图中可以看出变化S1成了根桥,S0为备份根桥。如果S1出故障了S0会代替S1称为根桥

再次查看Switch生成树状态


S0
Switch(config)#spanning-tree vlan 1 root secondary 
Switch#show spanning-tree 
VLAN0001
  Spanning tree enabled protocol ieee
  Root ID    Priority    24577
             Address     0090.216C.B791
             Cost        19
             Port        1(FastEthernet0/1)
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
  Bridge ID  Priority    28673  (priority 28672 sys-id-ext 1)
             Address     0001.63D0.3450
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  20
Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/1            Root FWD 19        128.1    P2p
Fa0/2            Desg FWD 19        128.2    P2p
S1
Switch(config)#spanning-tree vlan 1 root primary
Switch#show spanning-tree 
VLAN0001
  Spanning tree enabled protocol ieee
  Root ID    Priority    24577
             Address     0090.216C.B791
             This bridge is the root
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
  Bridge ID  Priority    24577  (priority 24576 sys-id-ext 1)
             Address     0090.216C.B791
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  20
Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/2            Desg FWD 19        128.2    P2p
Fa0/1            Desg FWD 19        128.1    P2p
S2
Switch#show spanning-tree 
VLAN0001
  Spanning tree enabled protocol ieee
  Root ID    Priority    24577
             Address     0090.216C.B791
             Cost        19
             Port        2(FastEthernet0/2)
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
  Bridge ID  Priority    32769  (priority 32768 sys-id-ext 1)
             Address     00E0.A3D9.8D5E
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  20
Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/1            Altn BLK 19        128.1    P2p
Fa0/2            Root FWD 19        128.2    P2p


相关文章
|
3月前
|
运维 负载均衡 算法
|
2月前
|
网络协议
|
5月前
|
安全 数据中心 C++
|
5月前
Stp-生成树实验
Stp-生成树实验
|
5月前
|
网络虚拟化
网络之路26:STP生成树协议
网络之路26:STP生成树协议
|
Python
一篇文章让你明白STP生成树协议
一篇文章让你明白STP生成树协议
217 0
一篇文章让你明白STP生成树协议
|
网络协议
计算机网络学习16:以太网交换机自学习与帧转发流程、生成树协议STP
假设各主机已经知道网络中其他主机的MAC地址,无需进行ARP。
计算机网络学习16:以太网交换机自学习与帧转发流程、生成树协议STP
|
负载均衡 网络虚拟化
MSTP多生成树协议
1、MSTP概述 2、MSTP相关配置命令
|
算法
STP生成树协议
1、STP介绍 2、STP生成树算法
STP生成树协议
STP生成树协议的介绍
STP是一种网络上使用非常广泛的技术。现在已经衍生了STP,RSTP,MSTP。
653 0
STP生成树协议的介绍