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

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

文章核心: 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模拟器中拖三台交换机连接查看他们的默认生成树情况


image.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状态


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


image.png

从图中可以看出变化S1成了根桥,S0为备份根桥。如果S1出故障了S0会代替S1称为根桥再次查看Switch生成树状态

python

复制代码

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

相关文章
|
Unix Perl
sed的插入操作
sed的插入操作
887 4
|
负载均衡 网络虚拟化
生成树详细配置(STP、RSTP、MSTP)
生成树详细配置(STP、RSTP、MSTP)
863 0
生成树详细配置(STP、RSTP、MSTP)
|
负载均衡 算法 网络虚拟化
生成树原理详解
生成树原理详解
593 0
|
人工智能 边缘计算 算法
AI人流热力图分析监测技术
通过深度学习算法(如CSRNet)进行实时密度估算和热力图生成,结合历史数据分析预测高峰时段,优化人员调度与促销活动。采用边缘计算减少延迟,确保实时响应,并通过数据可视化工具提升管理决策效率。
1328 24
|
NoSQL Ubuntu Java
在Ubuntu下安装Redis
【1月更文挑战第6天】在Ubuntu下安装Redis
1088 114
|
网络虚拟化 网络架构
网络技术基础(11)—— 生成树STP简单学习
【3月更文挑战第1天】网络基础笔记(加班了几天,中途耽搁了,预计推迟6天),这篇借鉴了之前师兄的笔记,边听边记笔记实在是太慢了。
|
网络安全 网络架构 Windows
详解Traceroute过防火墙回显问题,原来如此!
详解Traceroute过防火墙回显问题,原来如此!
823 2
|
Unix Shell Linux
技术笔记:linux中SIGHUP与nohup的关系
技术笔记:linux中SIGHUP与nohup的关系
282 1
|
网络虚拟化
网络二层环路,老练的网工,都是这么排查的!
网络二层环路,老练的网工,都是这么排查的!
1474 0
|
网络协议