STP生成树协议实战

一、stp应用场景

为了提高网络可靠性,交换网络中通常会使用冗余链路。然而冗余链路会为交换网络带来环路风险,并导致广播风暴及MAC表不稳定等问题,严重影响通信质量。而此时使用生成树协议(STP,Spanning Tree Protocol),使某些链路在逻辑上断开,以此来避免形成环路,而形成一种树状网络。

二、实验描述

使用eNSP,搭建一个有三台交换机的二层网络,交换机之间通过多条链路互联,在交换机上配置stp,通过更改优先级手动控制根桥选举。
模拟根桥故障,观察根桥选举。

三、实验拓扑

20230831072609507

四、实验过程

(一)干预根桥选举

1、关闭消息提示,并对三台交换机改名

<Huawei>system-view 		#进入系统视图
[Huawei]undo info enable	#关闭消息回显
[Huawei]sysname S1			#更改交换机名称为S1
#其他两台交换机执行上述操作,并改为相应名称
1234

2、三台交换机启用STP,将S1配置为根桥

[S1]stp mode stp 
Info: This operation may take a few seconds. Please wait for a moment...done.
[S1]stp root primary 
123

3、将S2和S3配置为备用根桥

#S2的配置
[S2]stp mode stp
Info: This operation may take a few seconds. Please wait for a moment...done.
[S2]stp root secondary
#S3的配置
[S3]stp mode stp
[S3]stp root secondary
1234567

4、分别查看三台交换机的配置情况
可以看到,S1已被配置为根桥,其端口均为指定端口,同样的命令可以查看S2和S3的配置情况。

[S1]display stp  	#查看详细信息
-------[CIST Global Info][Mode STP]-------
CIST Bridge         :0    .4c1f-cc2f-4087    #S1的MAC地址
Config Times        :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
Active Times        :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
CIST Root/ERPC      :0    .4c1f-cc2f-4087 / 0    #此处的0代表是根桥
CIST RegRoot/IRPC   :0    .4c1f-cc2f-4087 / 0
CIST RootPortId     :0.0
BPDU-Protection     :Disabled
CIST Root Type      :Primary root
TC or TCN received  :32
TC count per hello  :0
STP Converge Mode   :Normal 
Time since last TC  :0 days 0h:0m:58s
Number of TC        :15
Last TC occurred    :GigabitEthernet0/0/4
[S1]display stp brief 		#查看简要信息
 MSTID  Port                        Role  STP State     Protection
   0    GigabitEthernet0/0/3        DESI  FORWARDING      NONE
   0    GigabitEthernet0/0/4        DESI  FORWARDING      NONE
[S1]
123456789101112131415161718192021
#查看端口的stp状态
[S1]display stp interface GigabitEthernet 0/0/3
-------[CIST Global Info][Mode STP]-------
CIST Bridge         :0    .4c1f-cc2f-4087
Config Times        :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
Active Times        :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
CIST Root/ERPC      :0    .4c1f-cc2f-4087 / 0
CIST RegRoot/IRPC   :0    .4c1f-cc2f-4087 / 0
CIST RootPortId     :0.0
BPDU-Protection     :Disabled
CIST Root Type      :Primary root
TC or TCN received  :32
TC count per hello  :0
STP Converge Mode   :Normal 
Time since last TC  :0 days 0h:7m:14s
Number of TC        :15
Last TC occurred    :GigabitEthernet0/0/4
----[Port3(GigabitEthernet0/0/3)][FORWARDING]----
 Port Protocol       :Enabled
 Port Role           :Designated Port
 Port Priority       :128
 Port Cost(Dot1T )   :Config=auto / Active=20000
 Designated Bridge/Port   :0.4c1f-cc2f-4087 / 128.3
 Port Edged          :Config=default / Active=disabled
 Point-to-point      :Config=auto / Active=true
 Transit Limit       :147 packets/hello-time
 Protection Type     :None
 Port STP Mode       :STP 
 Port Protocol Type  :Config=auto / Active=dot1s
 BPDU Encapsulation  :Config=stp / Active=stp
 PortTimes           :Hello 2s MaxAge 20s FwDly 15s RemHop 20
 TC or TCN send      :106
 TC or TCN received  :4
 BPDU Sent           :358             
          TCN: 0, Config: 358, RST: 0, MST: 0
 BPDU Received       :5             
          TCN: 4, Config: 1, RST: 0, MST: 0
[S1]
1234567891011121314151617181920212223242526272829303132333435363738

5、改变各个交换机的优先级,使S2成为根桥。

将S1和S3的优先级设为8192,S的优先级设为4096。优先级的数值越小,优先级越高

#S1
[S1]undo stp root
[S1]stp priority 8192
#S2
[S2]undo stp root
[S2]stp priority 4096
#S3
[S3]undo stp root 
[S3]stp priority 8192
123456789

6、查看配置结果

#此时S的两个端口都变成了指定端口,S2已经成为根桥
[S2]display stp brief 
 MSTID  Port                        Role  STP State     Protection
   0    GigabitEthernet0/0/2        DESI  DISCARDING      NONE
   0    GigabitEthernet0/0/3        DESI  DISCARDING      NONE
[S2]
#查看详细信息
[S2]display stp 
-------[CIST Global Info][Mode STP]-------
CIST Bridge         :4096 .4c1f-cca9-530b
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-cca9-530b / 0
CIST RegRoot/IRPC   :4096 .4c1f-cca9-530b / 0
CIST RootPortId     :0.0
BPDU-Protection     :Disabled
TC or TCN received  :263
TC count per hello  :0
STP Converge Mode   :Normal 
Time since last TC  :0 days 0h:3m:54s
Number of TC        :20
Last TC occurred    :GigabitEthernet0/0/3
---- More ----
1234567891011121314151617181920212223

(二)模拟根桥故障

1、关闭S2的两个端口,模拟根桥故障

[S2]interface GigabitEthernet 0/0/2
[S2-GigabitEthernet0/0/2]shutdown
[S2-GigabitEthernet0/0/2]q    #退出此端口
[S2]interface GigabitEthernet 0/0/3
[S2-GigabitEthernet0/0/3]shutdown
12345

2、在其他两个交换机上查看根桥选举情况,发现S3已成为根桥

#S1
[S1]display stp 
-------[CIST Global Info][Mode STP]-------
CIST Bridge         :8192 .4c1f-cc2f-4087
Config Times        :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
Active Times        :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
CIST Root/ERPC      :8192 .4c1f-cc1c-6f43 / 20000
CIST RegRoot/IRPC   :8192 .4c1f-cc2f-4087 / 0
CIST RootPortId     :128.4
BPDU-Protection     :Disabled
TC or TCN received  :150
TC count per hello  :0
STP Converge Mode   :Normal 
Time since last TC  :0 days 0h:2m:57s
Number of TC        :24
Last TC occurred    :GigabitEthernet0/0/3
----[Port1(GigabitEthernet0/0/1)][DOWN]----
 Port Protocol       :Enabled
 Port Role           :Disabled Port
 Port Priority       :128
 Port Cost(Dot1T )   :Config=auto / Active=200000000
 Designated Bridge/Port   :8192.4c1f-cc2f-4087 / 128.1
 Port Edged          :Config=default / Active=disabled
 Point-to-point      :Config=auto / Active=false
 Transit Limit       :147 packets/hello-time
 Protection Type     :None
  ---- More ----
[S1]display stp brief 
 MSTID  Port                        Role  STP State     Protection
   0    GigabitEthernet0/0/4        ROOT  FORWARDING      NONE
[S1]
12345678910111213141516171819202122232425262728293031
#S3
[S3]display stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge         :8192 .4c1f-cc1c-6f43
Config Times        :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
Active Times        :Hello 2s MaxAge 20s FwDly 15s MaxHop 20
CIST Root/ERPC      :8192 .4c1f-cc1c-6f43 / 0
CIST RegRoot/IRPC   :8192 .4c1f-cc1c-6f43 / 0
CIST RootPortId     :0.0
BPDU-Protection     :Disabled
TC or TCN received  :173
TC count per hello  :0
STP Converge Mode   :Normal 
Time since last TC  :0 days 0h:5m:26s
Number of TC        :21
Last TC occurred    :GigabitEthernet0/0/4
----[Port1(GigabitEthernet0/0/1)][DOWN]----
 Port Protocol       :Enabled
 Port Role           :Disabled Port
 Port Priority       :128
 Port Cost(Dot1T )   :Config=auto / Active=200000000
 Designated Bridge/Port   :8192.4c1f-cc1c-6f43 / 128.1
 Port Edged          :Config=default / Active=disabled
 Point-to-point      :Config=auto / Active=false
 Transit Limit       :147 packets/hello-time
 Protection Type     :None
  ---- More ----
[S3]display stp brief 
 MSTID  Port                        Role  STP State     Protection
   0    GigabitEthernet0/0/4        DESI  FORWARDING      NONE
[S3]
12345678910111213141516171819202122232425262728293031

3、开启S2关闭的端口,S2重新成为根桥

[S2-GigabitEthernet0/0/3]undo shut
[S2-GigabitEthernet0/0/3]q
[S2]interface GigabitEthernet 0/0/2
[S2-GigabitEthernet0/0/2]undo shut
[S2-GigabitEthernet0/0/2]
[S2-GigabitEthernet0/0/2]dis stp brief 
 MSTID  Port                        Role  STP State     Protection
   0    GigabitEthernet0/0/2        DESI  FORWARDING      NONE
   0    GigabitEthernet0/0/3        DESI  FORWARDING      NONE
[S2-GigabitEthernet0/0/2]

1234567891011

五、扩展命令

1、更改端口优先级

[S1]interface GigabitEthernet 0/0/3
[S1-GigabitEthernet0/0/3]stp port priority 32
#查看效果
[S1-GigabitEthernet0/0/3]display stp interface GigabitEthernet 0/0/3
-------[CIST Global Info][Mode STP]-------
CIST Bridge         :8192 .4c1f-cc2f-4087
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-cca9-530b / 20000
CIST RegRoot/IRPC   :8192 .4c1f-cc2f-4087 / 0
CIST RootPortId     :32.3
BPDU-Protection     :Disabled
TC or TCN received  :185
TC count per hello  :0
STP Converge Mode   :Normal 
Time since last TC  :0 days 0h:3m:48s
Number of TC        :27
Last TC occurred    :GigabitEthernet0/0/3
----[Port3(GigabitEthernet0/0/3)][FORWARDING]----
 Port Protocol       :Enabled
 Port Role           :Root Port
 Port Priority       :32    #此处优先级变为32
 Port Cost(Dot1T )   :Config=auto / Active=20000
 Designated Bridge/Port   :4096.4c1f-cca9-530b / 128.3
 Port Edged          :Config=default / Active=disabled
 Point-to-point      :Config=auto / Active=true
 Transit Limit       :147 packets/hello-time
 Protection Type     :None
 Port STP Mode       :STP 
 Port Protocol Type  :Config=auto / Active=dot1s
 BPDU Encapsulation  :Config=stp / Active=stp
 PortTimes           :Hello 2s MaxAge 20s FwDly 15s RemHop 0
 TC or TCN send      :1
 TC or TCN received  :18
 BPDU Sent           :2             
          TCN: 1, Config: 1, RST: 0, MST: 0
 BPDU Received       :132             
          TCN: 0, Config: 132, RST: 0, MST: 0
[S1-GigabitEthernet0/0/3] 
123456789101112131415161718192021222324252627282930313233343536373839

2、修改端口开销,默认情况下,端口开销为20000

#端口开销修改为1000
[S1]interface GigabitEthernet 0/0/4
[S1-GigabitEthernet0/0/4]stp cost 1000
#查看
[S1-GigabitEthernet0/0/4]display stp interface GigabitEthernet 0/0/4
-------[CIST Global Info][Mode STP]-------
CIST Bridge         :8192 .4c1f-cc2f-4087
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-cca9-530b / 20000
CIST RegRoot/IRPC   :8192 .4c1f-cc2f-4087 / 0
CIST RootPortId     :32.3
BPDU-Protection     :Disabled
TC or TCN received  :185
TC count per hello  :0
STP Converge Mode   :Normal 
Time since last TC  :0 days 0h:9m:34s
Number of TC        :27
Last TC occurred    :GigabitEthernet0/0/3
----[Port4(GigabitEthernet0/0/4)][DISCARDING]----
 Port Protocol       :Enabled
 Port Role           :Alternate Port
 Port Priority       :128
 Port Cost(Dot1T )   :Config=1000 / Active=1000    #此处端口开销已经变为1000
 Designated Bridge/Port   :8192.4c1f-cc1c-6f43 / 128.4
 Port Edged          :Config=default / Active=disabled
 Point-to-point      :Config=auto / Active=true
 Transit Limit       :147 packets/hello-time
 Protection Type     :None
  ---- More ----
123456789101112131415161718192021222324252627282930
© 版权声明
THE END
点赞6赞赏 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容