笔记 STP

发布时间:2020-07-01 22:08:10 作者:俊凤
来源:网络 阅读:3277

STP
-定义
-作用
-类型
1、802.1d - STP :生成树协议 PVST/PVST+(思科)
2、802.1w - RSTP :快速生成树协议 PV-RSTP(思科)
3、802.1s - MSTP :多生成树协议
-报文

PVST:per-vlan STP,即在每个 VLAN 内部都运行一个 STP (802.1d);

STP的工作过程:
1、确定交换机的角色
根交换机:整个交换网络中,有且只有一个;
非根交换机:剩余的其他交换机,都称之为非根交换机

    注意:
        每一个非根交换机都会计算出一条去往根交换机的最短的、
        无环、2层数据转发路径,并且最终该路径是“转发”状态;

        选举原则:
              比较每个交换机的 BID (bridge ID):优先级+MAC地址
              优先级:默认值为 32768 ; 2个字节;
              MAC地址:使用的是交换机的主板MAC;6个字节;
                 比较原则 - 
                       首先比较优先级,越小越好;
                       其次比较MAC地址,越小越好;

2、确定端口的角色
        根端口:在每一个非根交换机上,有且只有一个;
                距离根交换机最近的端口;

        指定端口:在每一个"网段/segment"中,有且只有一个;
                距离根交换机最近的端口;

        非指定端口:其他所有端口,都叫做“非指定端口”

3、确定端口的状态
        down       -关闭(指的是当前端口没有启动STP)

        listening  -侦听,此时侦听的是网络中的所有的BPDU
                          目的是为了确定交换机和端口的角色;
                          端口在该状态停留15s;

        learning   -学习,该阶段主要是学习端口上收到的数据帧
                           的源MAC地址,从而形成 MAC地址表;
                           端口在该状态停留15s;

        forwarding -转发(最终状态),该状态实现数据包的发送和接收

        blocking   -阻塞(最终状态),该状态不能发送和接收数据包;
                                    只能接收 BPDU。

BPDU类型:
1、配置BPDU
用于创建和维护 STP 无环转发路径树
2、TCN BPDU
只有当 STP 无环转发路径树(拓扑)变化的时候,才会
产生并发送。
并且是:感知到该变化的交换机,产生 TCN BPDU ,只
发送给根交换机,然后再由根交换机转发给其他的所有
非根交换机;

STP计时器:
hello:交换机周期性发送 BPDU 的时间间隔,默认是 2s ;
forward-delay : 转发延迟,默认时间为15s ;
max-age:最大老化时间,默认时间为 20s ;


STP参数修改(思科):
1、修改交换机的 STP 优先级 (确保网络中有主根交换机和辅根交换机)
spanning-tree vlan x priority {value} , value 是4096的倍数

2、修改交换机的 STP 模式 (必须确保网络的所有交换机的STP模式相同)
        spanning-tree mode  {pvst | rapid-pvst | mstp }

3、修改交换机的 端口  cost 
        interface fas0/22 (该链路指的是 trunk 链路)
           spanning-tree  vlan 3 cost {value} 
4、针对某个 VLAN ,关闭 STP 功能
        no spanning-tree vlan x 

STP参数修改(华为):
1、修改交换机的 STP 优先级:
[SW] stp priority {value} -> 必须得是4096的倍数
2、修改交换机的 STP 模式
[SW] stp mode {stp | rstp | mstp }
3、修改交换机的端口的 STP cost :
[SW]interface fas0/13
[sw-fas0/13]stp cost {value}
4、在交换机上关闭/开启 STP :
[sw]stp disable -> 关闭 STP ;
[sw]stp enable -> 开启 STP ,默认是开启的;

验证命令:
show spanning-tree vlan x ->可以查看交换机上关于 VLAN x 的 STP 信息
show spanning-tree ->可以查看交换机上关于所有VLAN的 STP 信息
show spanning-tree summary ->可以查看交换机运行的 STP 的模式;
show version -> 可以查看交换机的 base mac ;

display  stp  
display  stp brief 

注意:
交换机上的 STP 功能,默认都是开启的;可以人工关闭;

=============================================================
MSTP的配置:

=====================================================================

STP 收敛速度比较慢 :30-50s

RSTP收敛速度要比 STP 快,因为做了以下改进:
1、发现问题比较快

2、反应/传输问题比较快
发现拓扑变更的交换机,会产生TCN BPDU,直接发送给与自己相连
的其他所有交换机;

3、解决问题比较快

端口角色细化:

根端口(root port ) 
指定端口 (designated port )  
替代端口(alternative port ):是根端口的备胎;
备份端口(bakcup port ):是指定端口的备胎

(边缘端口:一般都建议关闭 STP ;或者将连接非交换机的端口,设置非边缘端口)


端口状态精简化:
learning :学习
forwarding :转发
discarding :丢弃,相当于之前 STP 中的 down / blocking / listening


案例:

1 案例1:STP算法
1.1 问题
选择出根网桥、根端口、指定端口、被阻塞的端口。

1.2 方案
如图-1所示:

笔记  STP

1.3 步骤
实现此案例需要按照如下步骤进行。

1)每个广播域选择根网桥(Root Bridge)

每个非根网桥选择根端口(Root Ports)
每个网段上选择指定端口(Designated Ports)
2)结果如图-2所示

笔记  STP

2 案例2:配置STP
2.1 问题
首先查看当前根网桥,然后通过修改交换机的优先级来分配根网桥。

2.2 方案
使用eNSP搭建实验环境,如图-3所示。

笔记  STP

2.3 步骤
实现此案例需要按照如下步骤进行。

[A]stp mode stp
[B]stp mode stp
[C]stp mode stp
[D]stp mode stp
[A]dis stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge :32768.4c1f-cc3b-03cb
Config Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
Active Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
CIST Root/ERPC :32768.4c1f-cc17-3481 / 200000
CIST RegRoot/IRPC :32768.4c1f-cc3b-03cb / 0
CIST RootPortId :128.2
BPDU-Protection :Disabled
TC or TCN received :106
TC count per hello :0
STP Converge Mode :Normal
Time since last TC :0 days 0h:9m:8s
Number of TC :12
Last TC occurred :Ethernet0/0/2
[B]dis stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge :32768.4c1f-cc17-3481
Config Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
Active Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
CIST Root/ERPC :32768.4c1f-cc17-3481 / 0
CIST RegRoot/IRPC :32768.4c1f-cc17-3481 / 0
CIST RootPortId :0.0
BPDU-Protection :Disabled
TC or TCN received :23
TC count per hello :0
STP Converge Mode :Normal
Time since last TC :0 days 0h:9m:52s
Number of TC :13
Last TC occurred :Ethernet0/0/4
[C]dis stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge :32768.4c1f-cc50-3d65
Config Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
Active Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
CIST Root/ERPC :32768.4c1f-cc17-3481 / 400000
CIST RegRoot/IRPC :32768.4c1f-cc50-3d65 / 0
CIST RootPortId :128.4
BPDU-Protection :Disabled
TC or TCN received :92
TC count per hello :0
STP Converge Mode :Normal
Time since last TC :0 days 0h:10m:26s
Number of TC :11
Last TC occurred :Ethernet0/0/4
[D]dis stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge :32768.4c1f-cc22-4507
Config Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
Active Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
CIST Root/ERPC :32768.4c1f-cc17-3481 / 200000
CIST RegRoot/IRPC :32768.4c1f-cc22-4507 / 0
CIST RootPortId :128.2
BPDU-Protection :Disabled
TC or TCN received :49
TC count per hello :0
STP Converge Mode :Normal
Time since last TC :0 days 0h:11m:12s
Number of TC :13
Last TC occurred :Ethernet0/0/2
可以看出,交换机B是根网桥。

[A]stp priority 4096
[A]dis stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge :4096 .4c1f-cc3b-03cb
Config Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
Active Times :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
CIST Root/ERPC :4096 .4c1f-cc3b-03cb / 0
CIST RegRoot/IRPC :4096 .4c1f-cc3b-03cb / 0
CIST RootPortId :0.0
BPDU-Protection :Disabled
TC or TCN received :108
TC count per hello :0
STP Converge Mode :Normal
Time since last TC :0 days 0h:0m:14s
Number of TC :15
Last TC occurred :Ethernet0/0/3
此时,根网桥已经是交换机A了。

3 案例3:配置MSTP及负载均衡
3.1 问题
配置MSTP实现多生成树效果
配置A成为vlan 10 和 20 的主根,vlan 30 和 40 的次根
配置B成为vlan 30 和 40 的主根,vlan 10 和 20 的次根
查看配置信息
3.2 方案
使用eNSP搭建实验环境,如图-4所示。

笔记  STP

3.3 步骤
实现此案例需要按照如下步骤进行。

[A]vlan batch 10 20 30 40
[A]int e0/0/2
[A-Ethernet0/0/2]port link-type trunk
[A-Ethernet0/0/2]port trunk allow-pass vlan all
[A]int e0/0/3
[A-Ethernet0/0/3]port link-type trunk
[A-Ethernet0/0/3]port trunk allow-pass vlan all
交换机B、C也同样配置。

[A]stp region-configuration
[A-mst-region]region-name tedu
[A-mst-region]instance 1 vlan 10 20
[A-mst-region]instance 2 vlan 30 40
[A-mst-region]active region-configuration
查看配置:

[A-mst-region]dis this
#
stp region-configuration
region-name tedu
instance 1 vlan 10 20
instance 2 vlan 30 40
active region-configuration
#
return
交换机B、C也同样配置。

3)配置主根与次根

[A]stp instance 1 priority 4096
[A]stp instance 2 priority 8192
[B]stp instance 2 priority 4096
[B]stp instance 1 priority 8192
4)验证

[A]dis stp instance 1
-------[MSTI 1 Global Info]-------
MSTI Bridge ID :4096.4c1f-cc87-1de7
MSTI RegRoot/IRPC :4096.4c1f-cc87-1de7 / 0
MSTI RootPortId :0.0
Master Bridge :32768.4c1f-cc0d-76bc
Cost to Master :200000
TC received :5
TC count per hello :0
Time since last TC :0 days 0h:3m:6s
Number of TC :4
Last TC occurred :Ethernet0/0/2
----[Port2(Ethernet0/0/2)][FORWARDING]----
Port Role :Designated Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :4096.4c1f-cc87-1de7 / 128.2
Port Times :RemHops 20
TC or TCN send :4
TC or TCN received :3
----[Port3(Ethernet0/0/3)][FORWARDING]----
Port Role :Designated Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :4096.4c1f-cc87-1de7 / 128.3
Port Times :RemHops 20
TC or TCN send :2
TC or TCN received :2
[A]dis stp instance 2
-------[MSTI 2 Global Info]-------
MSTI Bridge ID :8192.4c1f-cc87-1de7
MSTI RegRoot/IRPC :4096.4c1f-cc0d-76bc / 200000
MSTI RootPortId :128.2
Master Bridge :32768.4c1f-cc0d-76bc
Cost to Master :200000
TC received :4
TC count per hello :0
Time since last TC :0 days 0h:3m:49s
Number of TC :4
Last TC occurred :Ethernet0/0/2
----[Port2(Ethernet0/0/2)][FORWARDING]----
Port Role :Root Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :4096.4c1f-cc0d-76bc / 128.1
Port Times :RemHops 20
TC or TCN send :4
TC or TCN received :3
----[Port3(Ethernet0/0/3)][FORWARDING]----
Port Role :Designated Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :8192.4c1f-cc87-1de7 / 128.3
Port Times :RemHops 19
TC or TCN send :2
TC or TCN received :1
[B]dis stp instance 1
-------[MSTI 1 Global Info]-------
MSTI Bridge ID :8192.4c1f-cc0d-76bc
MSTI RegRoot/IRPC :4096.4c1f-cc87-1de7 / 200000
MSTI RootPortId :128.1
Master Bridge :32768.4c1f-cc0d-76bc
Cost to Master :0
TC received :4
TC count per hello :0
Time since last TC :0 days 0h:5m:26s
Number of TC :4
Last TC occurred :Ethernet0/0/3
----[Port1(Ethernet0/0/1)][FORWARDING]----
Port Role :Root Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :4096.4c1f-cc87-1de7 / 128.2
Port Times :RemHops 20
TC or TCN send :3
TC or TCN received :4
----[Port3(Ethernet0/0/3)][FORWARDING]----
Port Role :Designated Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :8192.4c1f-cc0d-76bc / 128.3
Port Times :RemHops 19
TC or TCN send :1
TC or TCN received :0
[B]dis stp instance 2
-------[MSTI 2 Global Info]-------
MSTI Bridge ID :4096.4c1f-cc0d-76bc
MSTI RegRoot/IRPC :4096.4c1f-cc0d-76bc / 0
MSTI RootPortId :0.0
Master Bridge :32768.4c1f-cc0d-76bc
Cost to Master :0
TC received :6
TC count per hello :0
Time since last TC :0 days 0h:6m:4s
Number of TC :5
Last TC occurred :Ethernet0/0/3
----[Port1(Ethernet0/0/1)][FORWARDING]----
Port Role :Designated Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :4096.4c1f-cc0d-76bc / 128.1
Port Times :RemHops 20
TC or TCN send :3
TC or TCN received :4
----[Port3(Ethernet0/0/3)][FORWARDING]----
Port Role :Designated Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :4096.4c1f-cc0d-76bc / 128.3
Port Times :RemHops 20
TC or TCN send :2
TC or TCN received :2
[C]dis stp instance 1
-------[MSTI 1 Global Info]-------
MSTI Bridge ID :32768.4c1f-ccb8-32b8
MSTI RegRoot/IRPC :4096.4c1f-cc87-1de7 / 200000
MSTI RootPortId :128.1
Master Bridge :32768.4c1f-cc0d-76bc
Cost to Master :200000
TC received :3
TC count per hello :0
Time since last TC :0 days 0h:6m:58s
Number of TC :3
Last TC occurred :Ethernet0/0/1
----[Port1(Ethernet0/0/1)][FORWARDING]----
Port Role :Root Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :4096.4c1f-cc87-1de7 / 128.3
Port Times :RemHops 20
TC or TCN send :2
TC or TCN received :2
----[Port2(Ethernet0/0/2)][DISCARDING]----
Port Role :Alternate Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :8192.4c1f-cc0d-76bc / 128.3
Port Times :RemHops 19
TC or TCN send :0
TC or TCN received :1
[C]dis stp instance 2
-------[MSTI 2 Global Info]-------
MSTI Bridge ID :32768.4c1f-ccb8-32b8
MSTI RegRoot/IRPC :4096.4c1f-cc0d-76bc / 200000
MSTI RootPortId :128.2
Master Bridge :32768.4c1f-cc0d-76bc
Cost to Master :200000
TC received :4
TC count per hello :0
Time since last TC :0 days 0h:7m:32s
Number of TC :4
Last TC occurred :Ethernet0/0/2
----[Port1(Ethernet0/0/1)][DISCARDING]----
Port Role :Alternate Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :8192.4c1f-cc87-1de7 / 128.3
Port Times :RemHops 19
TC or TCN send :1
TC or TCN received :2
----[Port2(Ethernet0/0/2)][FORWARDING]----
Port Role :Root Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=200000
Designated Bridge/Port :4096.4c1f-cc0d-76bc / 128.3
Port Times :RemHops 20
TC or TCN send :2
TC or TCN received :2
查看负载均衡:

[A]dis stp bri
MSTID Port Role STP State Protection
0 Ethernet0/0/2 ROOT FORWARDING NONE
0 Ethernet0/0/3 DESI FORWARDING NONE
1 Ethernet0/0/2 DESI FORWARDING NONE
1 Ethernet0/0/3 DESI FORWARDING NONE
2 Ethernet0/0/2 ROOT FORWARDING NONE
2 Ethernet0/0/3 DESI FORWARDING NONE
[B]dis stp bri
MSTID Port Role STP State Protection
0 Ethernet0/0/1 DESI FORWARDING NONE
0 Ethernet0/0/3 DESI FORWARDING NONE
1 Ethernet0/0/1 ROOT FORWARDING NONE
1 Ethernet0/0/3 DESI FORWARDING NONE
2 Ethernet0/0/1 DESI FORWARDING NONE
2 Ethernet0/0/3 DESI FORWARDING NONE
[C]dis stp bri
MSTID Port Role STP State Protection
0 Ethernet0/0/1 ALTE DISCARDING NONE
0 Ethernet0/0/2 ROOT FORWARDING NONE
1 Ethernet0/0/1 ROOT FORWARDING NONE
1 Ethernet0/0/2 ALTE DISCARDING NONE
2 Ethernet0/0/1 ALTE DISCARDING NONE
2 Ethernet0/0/2 ROOT FORWARDING NONE
C上VLAN 10 20的流量通过Ethernet0/0/1口到A,VLAN 30 40的流量通过Ethernet0/0/2口到B,实现了链路的负载均衡。

推荐阅读:
  1. 华为设备的简单配置
  2. stp怎么生成树协议

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

stp st

上一篇:SQL Server timeout分析和总结

下一篇:Grafana + Zabbix

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》