当前位置:首页>微思动态 > >详情
全国热线电话 400-881-4699

在线留言

实验!!配置STP

发布作者:微思网络   发布时间:2022-05-23   浏览量:0

学习目标

  • 掌握启用和禁用STP的方法

  • 掌握修改交换机STP模式的方法

  • 掌握修改桥优先级,控制根桥选举的方法

  • 掌握修改端口优先级,控制根端口和指定端口选举的方法

  • 掌握修改端口开销,控制根端口和指定端口选举的方法

  • 掌握边缘端口的配置方法


拓扑图

图片

3.1 配置STP实验拓扑图


场景

您是公司的网络管理员,为了避免网络中的环路问题,需要在网络中的交换机上配置STP。本实验中,您还需要通过修改桥优先级来控制STP的根桥选举,并通过配置STP的一些特性来加快STP的收敛速度。


操作步骤:

一:配置 STP 并验证

为了保证实验结果的准确性,确保设备以空配置启动。

华为交换机STP特性默认是打开的,如果STP被禁用,则执行stp enable命令启用STP。

关闭交换机STP特性命令:

[Huawei]stp disable


启用交换机STP特性命令:

[Huawei]stp enable

 

本实验中,SW1和SW2之间有两条链路,在SW1和SW2上启用STP,并把SW1配置为根桥。

配置SW1:

<Huawei>system-view 
Huawei]sysname SW1
[SW1]stp mode stp
[SW1]stp root primary   <设置本交换机的优先级为0>

    配置SW2:

<Huawei>system-view 
Huawei]sysname SW2
[SW2]stp mode stp
[SW2]stp root secondary  <设置本交换机的优先级为4096>

     执行 display stp brief  命令查看STP信息

[SW1]display stp brief 
 MSTID  Port                       Role   STP State        Protection
   0    GigabitEthernet0/0/9       DESI   FORWARDING       NONE
   0    GigabitEthernet0/0/10      DESI   FORWARDING       NONE

[SW2]display stp brief 
 MSTID  Port                       Role     STP State        Protection
   0    GigabitEthernet0/0/9       ROOT     FORWARDING       NONE
   0    GigabitEthernet0/0/10      ALTE     DISCARDING       NONE

    执行 display stp interface 命令查看端口的STP状态

[SW1]display stp interface GigabitEthernet 0/0/10
-------[CIST Global Info][Mode STP]-------
CIST Bridge         :0    .4c1f-cc16-05ac
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-cc16-05ac / 0
CIST RegRoot/IRPC   :0    .4c1f-cc16-05ac / 0
CIST RootPortId     :0.0
BPDU-Protection     :Disabled
CIST Root Type      :Primary root
TC or TCN received  :8
TC count per hello  :0
STP Converge Mode   :Normal 
Time since last TC  :0 days 0h:19m:33s
Number of TC        :6
----[Port34(GigabitEthernet0/0/10)][FORWARDING]----
 Port Protocol       :Enabled
 Port Role           :Designated Port
 Port Priority       :128
 Port Cost(Dot1T )   :Config=auto / Active=20000
 Designated Bridge/Port   :0.4c1f-cc16-05ac / 128.34
 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      :17
 TC or TCN received  :0
 BPDU Sent           :556             
          TCN: 0, Config: 556, RST: 0, MST: 0
 BPDU Received       :2             
          TCN: 0, Config: 2, RST: 0, MST: 0

[SW2]display stp interface GigabitEthernet 0/0/10
-------[CIST Global Info][Mode STP]-------
CIST Bridge         :4096 .4c1f-cc78-50fb
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-cc16-05ac / 20000
CIST RegRoot/IRPC   :4096 .4c1f-cc78-50fb / 0
CIST RootPortId     :128.9
BPDU-Protection     :Disabled
CIST Root Type      :Secondary root
TC or TCN received  :43
TC count per hello  :0
STP Converge Mode   :Normal 
Time since last TC  :0 days 0h:23m:3s
Number of TC        :8
----[Port10(GigabitEthernet0/0/10)][DISCARDING]----
 Port Protocol       :Enabled
 Port Role           :Alternate Port
 Port Priority       :128
 Port Cost(Dot1T )   :Config=auto / Active=20000
 Designated Bridge/Port   :0.4c1f-cc16-05ac / 128.34
 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      :0
 TC or TCN received  :17
 BPDU Sent           :2             
          TCN: 0, Config: 2, RST: 0, MST: 0
 BPDU Received       :645             
          TCN: 0, Config: 645, RST: 0, MST: 0

二:控制根桥选举

 执行display stp命令查看根桥信息。根桥设备的CIST Bridge与CIST Root/ERPC字段取值相同。

[SW1]display stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge         :0    .4c1f-cc16-05ac   <本交换机SW1的网桥ID>
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-cc16-05ac / 0     <本设备SW1为根交换机>
CIST RegRoot/IRPC   :0    .4c1f-cc16-05ac / 0
CIST RootPortId     :0.0
BPDU-Protection     :Disabled
CIST Root Type      :Primary root
TC or TCN received  :8
TC count per hello  :0
STP Converge Mode   :Normal 
Time since last TC  :0 days 0h:24m:37s
……output omit……

[SW2]display stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge         :4096 .4c1f-cc78-50fb     <本交换机SW2的网桥ID>
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-cc16-05ac / 20000    <在SW2上看到SW1为根交换机>
CIST RegRoot/IRPC   :4096 .4c1f-cc78-50fb / 0
CIST RootPortId     :128.9
BPDU-Protection     :Disabled
CIST Root Type      :Secondary root
TC or TCN received  :43
TC count per hello  :0
STP Converge Mode   :Normal 
Time since last TC  :0 days 0h:26m:12s
……output omit……

以上回显表示SW1为根桥,SW2为备份根桥。

通过配置优先级,使SW2为根桥,SW1为备份根桥。桥优先级取值越小,则优先级越高。把SW1和SW2的优先级分别设置为8192和4096。
    配置SW1:

[SW1]undo stp root
[SW1]stp priority 8192

   配置SW2:

[SW2]undo stp root
[SW2]stp priority 4096

   执行display stp命令查看新的根桥信息。

[SW1]display stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge         :8192 .4c1f-cc16-05ac
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-cc78-50fb / 20000
CIST RegRoot/IRPC   :8192 .4c1f-cc16-05ac / 0
CIST RootPortId     :128.33
BPDU-Protection     :Disabled
TC or TCN received  :24
TC count per hello  :2
STP Converge Mode   :Normal 
Time since last TC  :0 days 0h:0m:16s
……output omit……
[SW2]display stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge         :4096 .4c1f-cc78-50fb
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-cc78-50fb / 0
CIST RegRoot/IRPC   :4096 .4c1f-cc78-50fb / 0
CIST RootPortId     :0.0
BPDU-Protection     :Disabled
TC or TCN received  :43
TC count per hello  :0
STP Converge Mode   :Normal 
Time since last TC  :0 days 0h:0m:52s
……output omit……

由上述回显信息中的灰色部分可以看出,SW2已经变成新的根桥。关闭SW2的G0/0/9和G0/0/10端口,从而隔离SW1与SW2,模拟SW2发生故障。

[SW2]interface GigabitEthernet 0/0/9
[SW2-GigabitEthernet0/0/9]shutdown
[SW2-GigabitEthernet0/0/9]quit
[SW2]interface GigabitEthernet 0/0/10
[SW2-GigabitEthernet0/0/10]shutdown   

[SW1]display stp                 
-------[CIST Global Info][Mode STP]-------
CIST Bridge         :8192 .4c1f-cc16-05ac
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-cc16-05ac / 0
CIST RegRoot/IRPC   :8192 .4c1f-cc16-05ac / 0
CIST RootPortId     :0.0
BPDU-Protection     :Disabled
TC or TCN received  :43
TC count per hello  :0
STP Converge Mode   :Normal 
Time since last TC  :0 days 0h:9m:17s
……output omit……

在上述回显信息中,灰色部分表明当SW2故障时,SW1变成根桥,然后开启SW2之前关闭的接口。

[SW2]interface GigabitEthernet 0/0/9 
[SW2-GigabitEthernet0/0/9]undo shutdown
[SW2-GigabitEthernet0/0/9]quit
[SW2]interface GigabitEthernet 0/0/10
[SW2-GigabitEthernet0/0/10]undo shutdown

[SW1]display stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge         :8192 .4c1f-cc16-05ac
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-cc78-50fb / 20000
CIST RegRoot/IRPC   :8192 .4c1f-cc16-05ac / 0
CIST RootPortId     :128.33
BPDU-Protection     :Disabled
TC or TCN received  :54
TC count per hello  :0
STP Converge Mode   :Normal 
Time since last TC  :0 days 0h:0m:14s
……output omit……

[SW2]display stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge         :4096 .4c1f-cc78-50fb
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-cc78-50fb / 0  <SW2为根桥>
CIST RegRoot/IRPC   :4096 .4c1f-cc78-50fb / 0
CIST RootPortId     :0.0
BPDU-Protection     :Disabled
TC or TCN received  :45
TC count per hello  :0
STP Converge Mode   :Normal 
Time since last TC  :0 days 0h:0m:43s
……output omit……

在上述回显信息中,灰色部分表明SW2已经恢复正常,重新变成根桥。



三:控制根端口选举

     在SW1上执行display stp brief命令查看端口角色。

[SW1]display stp brief
 MSTID  Port                       Role    STP State         Protection
   0    GigabitEthernet0/0/9        ROOT  FORWARDING      NONE
   0    GigabitEthernet0/0/10       ALTE   DISCARDING       NONE

上述回显信息表明SW1的G0/0/9是根端口,G0/0/10是Alternate端口。通过修改端口优先级,使G0/0/10成为根端口,G0/0/9成为Alternate端口。修改SW2上G0/0/9和G0/0/10端口的优先级。缺省情况下端口优先级为128。端口优先级取值越大,则优先级越低。在SW2上,修改G0/0/9的端口优先级值为32,G0/0/10的端口优先级值为16。

[SW2]interface GigabitEthernet 0/0/9
[SW2-GigabitEthernet0/0/9]stp port priority 32
[SW2-GigabitEthernet0/0/9]quit
[SW2]interface GigabitEthernet 0/0/10
[SW2-GigabitEthernet0/0/10]stp port priority 16

提示:此处是修改SW2的端口优先级,而不是修改SW1的端口优先级。

SW2的端口优先级修改完成后,SW1的G0/0/10成为了根端口。

[SW2]display stp interface GigabitEthernet 0/0/9
-------[CIST Global Info][Mode STP]-------
CIST Bridge         :4096 .4c1f-cc78-50fb
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-cc78-50fb / 0
CIST RegRoot/IRPC   :4096 .4c1f-cc78-50fb / 0
CIST RootPortId     :0.0
BPDU-Protection     :Disabled
TC or TCN received  :46
TC count per hello  :0
STP Converge Mode   :Normal 
Time since last TC  :0 days 0h:2m:23s
Number of TC        :14
Last TC occurred    :GigabitEthernet0/0/10
----[Port9(GigabitEthernet0/0/9)][FORWARDING]----
 Port Protocol       :Enabled
 Port Role           :Designated Port
 Port Priority       :32
 Port Cost(Dot1T )   :Config=auto / Active=20000
 Designated Bridge/Port   :4096.4c1f-cc78-50fb / 32.9
 Port Edged          :Config=default / Active=disabled
 Point-to-point      :Config=auto / Active=true
……output omit……

[SW2]display stp interface GigabitEthernet 0/0/10
-------[CIST Global Info][Mode STP]-------
CIST Bridge         :4096 .4c1f-cc78-50fb
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-cc78-50fb / 0
CIST RegRoot/IRPC   :4096 .4c1f-cc78-50fb / 0
CIST RootPortId     :0.0
BPDU-Protection     :Disabled
TC or TCN received  :46
TC count per hello  :0
STP Converge Mode   :Normal 
Time since last TC  :0 days 0h:4m:0s
Number of TC        :14
Last TC occurred    :GigabitEthernet0/0/10
----[Port10(GigabitEthernet0/0/10)][FORWARDING]----
 Port Protocol       :Enabled
 Port Role           :Designated Port
 Port Priority       :16
 Port Cost(Dot1T )   :Config=auto / Active=20000
 Designated Bridge/Port   :4096.4c1f-cc78-50fb / 16.10
 Port Edged          :Config=default / Active=disabled
 Point-to-point      :Config=auto / Active=true
……output omit……

  在SW1上执行display stp brief命令查看端口角色。

[SW1]display stp brief
 MSTID  Port                       Role    STP State       Protection
   0    GigabitEthernet0/0/9        ALTE   DISCARDING      NONE
   0    GigabitEthernet0/0/10       ROOT  FORWARDING     NONE

在上述回显信息中,灰色部分表明SW1的G0/0/10端口是根端口,G0/0/9是Alternate端口。关闭SW1的GigabitEthernet 0/0/10端口,再查看端口角色。

[SW1]interface GigabitEthernet 0/0/10
[SW1-GigabitEthernet0/0/10]shutdown

[SW1]disp stp brief 
 MSTID  Port                       Role    STP State         Protection
   0    GigabitEthernet0/0/9        ROOT  DISCARDING      NONE

在上述回显信息中的灰色部分可以看出,SW1的G0/0/9变成了根端口。在SW2上恢复G0/0/9和G0/0/10端口的缺省优先级,并重新开启SW1上关闭的端口。

[SW2]interface GigabitEthernet 0/0/9
[SW2-GigabitEthernet0/0/9]undo stp port priority
[SW2-GigabitEthernet0/0/9]quit
[SW2]interface GigabitEthernet 0/0/10
[SW2-GigabitEthernet0/0/10]undo stp port priority

[SW1]interface GigabitEthernet 0/0/10
[SW1-GigabitEthernet0/0/10]undo shutdown

在SW1上执行display stp brief命令和display stp interface命令查看端口角色。

<SW1>display stp brief  
MSTID Port     Role      STP State       Protection
0  GigabitEthernet0/0/9 ROOT FORWARDING   NONE
0  GigabitEthernet0/0/10 ALTE      DISCARDING   NONE

[SW1]display stp interface GigabitEthernet 0/0/9
-------[CIST Global Info][Mode STP]-------
CIST Bridge         :8192 .4c1f-cc16-05ac
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-cc78-50fb / 20000
CIST RegRoot/IRPC   :8192 .4c1f-cc16-05ac / 0
CIST RootPortId     :128.33
BPDU-Protection     :Disabled
TC or TCN received  :168
TC count per hello  :0
STP Converge Mode   :Normal 
Time since last TC  :0 days 0h:1m:22s
Number of TC        :15
Last TC occurred    :GigabitEthernet0/0/9
----[Port33(GigabitEthernet0/0/9)][FORWARDING]----
 Port Protocol       :Enabled
 Port Role           :Root Port
 Port Priority       :128
 Port Cost(Dot1T )   :Config=auto / Active=20000
 Designated Bridge/Port   :4096.4c1f-cc78-50fb / 128.9
 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      :3
 TC or TCN received  :73
 BPDU Sent           :4             
          TCN: 3, Config: 1, RST: 0, MST: 0
 BPDU Received       :487             
          TCN: 0, Config: 487, RST: 0, MST: 0

[SW1]display stp interface GigabitEthernet 0/0/10
-------[CIST Global Info][Mode STP]-------
CIST Bridge         :8192 .4c1f-cc16-05ac
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-cc78-50fb / 20000
CIST RegRoot/IRPC   :8192 .4c1f-cc16-05ac / 0
CIST RootPortId     :128.33
BPDU-Protection     :Disabled
TC or TCN received  :168
TC count per hello  :0
STP Converge Mode   :Normal 
Time since last TC  :0 days 0h:1m:53s
Number of TC        :15
Last TC occurred    :GigabitEthernet0/0/9
----[Port34(GigabitEthernet0/0/10)][DISCARDING]----
 Port Protocol       :Enabled
 Port Role           :Alternate Port
 Port Priority       :128
 Port Cost(Dot1T )   :Config=auto / Active=20000
 Designated Bridge/Port   :4096.4c1f-cc78-50fb / 128.10
 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      :0
 TC or TCN received  :17
 BPDU Sent           :1             
          TCN: 0, Config: 1, RST: 0, MST: 0
 BPDU Received       :68             
          TCN: 0, Config: 68, RST: 0, MST: 0

在上述回显信息中,灰色部分表明G0/0/9和G0/0/10的端口开销缺省情况下为20000。修改SW1上的G0/0/9端口开销值为200000。

[SW1]interface GigabitEthernet 0/0/9
[SW1-GigabitEthernet0/0/9]stp cost 200000

在SW1上执行display stp brief命令和display stp interface命令查看端口角色。

[SW1]display stp interface GigabitEthernet 0/0/9
-------[CIST Global Info][Mode STP]-------
CIST Bridge         :8192 .4c1f-cc16-05ac
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-cc78-50fb / 20000
CIST RegRoot/IRPC   :8192 .4c1f-cc16-05ac / 0
CIST RootPortId     :128.34
BPDU-Protection     :Disabled
TC or TCN received  :204
TC count per hello  :0
STP Converge Mode   :Normal 
Time since last TC  :0 days 0h:0m:12s
Number of TC        :18
Last TC occurred    :GigabitEthernet0/0/10
----[Port33(GigabitEthernet0/0/9)][DISCARDING]----
 Port Protocol       :Enabled
 Port Role           :Alternate Port
 Port Priority       :128
 Port Cost(Dot1T )   :Config=200000 / Active=200000
 Designated Bridge/Port   :4096.4c1f-cc78-50fb / 128.9
 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      :3
 TC or TCN received  :90
 BPDU Sent           :4             
          TCN: 3, Config: 1, RST: 0, MST: 0
 BPDU Received       :568             
          TCN: 0, Config: 568, RST: 0, MST: 0

[SW1]display stp brief                           
 MSTID  Port                       Role    STP State        Protection
   0    GigabitEthernet0/0/9        ALTE   DISCARDING      NONE
   0    GigabitEthernet0/0/10       ROOT  FORWARDING     NONE

此时,SW1上的G0/0/10端口变为根端口。


配置文件

<S1>display current-configuration 
<S2>display current-configuration 



返回顶部