| HCNA-12 STP配置和选路规则 
 
 1、STP的基本配置 华为交换机默认开启MSTP <Huawei>system-view [Huawei]sysnamesw1 [sw1]stpenable  //STP开启 [sw1]stpmode stp  //STP模式STP   <Huawei>system-view [Huawei]sysnamesw2 [sw2]stpenable [sw2]stpmode stp   <Huawei>system-view [Huawei]sysnamesw3 [sw3]stpenable  [sw3]stpmode stp   <Huawei>system-view [Huawei]sysnamesw4 [sw4]stpenable  [sw4]stpmode stp   <sw3>displaystp  //查看STP ----[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   :32768.4c1f-cc38-3f7a / 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 15sRemHop 20  TC or TCN send      :36  TC or TCN received  :0  BPDU Sent           :328                        TCN: 0, Config: 328, RST: 0, MST: 0  BPDU Received       :2                        TCN: 0, Config: 2, RST: 0, MST: 0 ----[Port5(GigabitEthernet0/0/5)][DISCARDING]----  //丢弃  Port Protocol       :Enabled  Port Role           :Alternate Port //替代端口  Port Priority       :128  Port Cost(Dot1T )   :Config=auto / Active=20000  Designated Bridge/Port   :32768.4c1f-cc10-724e / 128.5  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 15sRemHop 0  TC or TCN send      :1  TC or TCN received  :52  BPDU Sent           :2                        TCN: 1, Config: 1, RST: 0, MST: 0  BPDU Received       :538                        TCN: 0, Config: 538, RST: 0, MST: 0 <sw1>displaystp brief   //查看STP简介  MSTID Port                       Role  STP State     Protection    0   GigabitEthernet0/0/1       DESI  FORWARDING      NONE     0   GigabitEthernet0/0/2       DESI  FORWARDING      NONE <sw2>displaystp brief  MSTID Port                       Role  STP State     Protection    0   GigabitEthernet0/0/1       ROOT  FORWARDING      NONE    0   GigabitEthernet0/0/4        DESI  FORWARDING      NONE    0   GigabitEthernet0/0/5       DESI  FORWARDING      NONE  <sw3>display stp brief   MSTID Port                       Role  STP State     Protection    0   GigabitEthernet0/0/2       ROOT  FORWARDING      NONE    0   GigabitEthernet0/0/3       DESI  FORWARDING      NONE    0   GigabitEthernet0/0/5       ALTE  DISCARDING      NONE    0   GigabitEthernet0/0/10      DESI  FORWARDING      NONE    0   GigabitEthernet0/0/11      DESI  FORWARDING      NONE <sw4>displaystp brief  MSTID Port                       Role  STP State     Protection    0   GigabitEthernet0/0/3       ALTE  DISCARDING      NONE    0   GigabitEthernet0/0/4       ROOT  FORWARDING      NONE Sw1所有端口都是DESI FORWARDING 指定接口,可以初步认定是ROOT 根交换机。 <sw1>displaystp -------[CISTGlobal Info][Mode STP]------- CIST Bridge        :32768.4c1f-cc02-6b54 ConfigTimes        :Hello 2s MaxAge 20s FwDly15s MaxHop 20 ActiveTimes        :Hello 2s MaxAge 20s FwDly15s MaxHop 20 CIST Root/ERPC     :32768.4c1f-cc02-6b54 / 0 CISTRegRoot/IRPC   :32768.4c1f-cc02-6b54 / 0 CISTRootPortId     :0.0 BPDU-Protection     : Disabled TC or TCNreceived  :20 TC countper hello  :0 STPConverge Mode   :Normal  Time sincelast TC  :0 days 0h:30m:29s Number ofTC        :16 自身交换机ID和根交换机ID相同,SW1为根交换机。 -------[CISTGlobal Info][Mode STP]------- CISTBridge         :32768.4c1f-cc10-724e ConfigTimes        :Hello 2s MaxAge 20s FwDly15s MaxHop 20 ActiveTimes        :Hello 2s MaxAge 20s FwDly15s MaxHop 20 CIST Root/ERPC     :32768.4c1f-cc02-6b54 / 20000 CISTRegRoot/IRPC   :32768.4c1f-cc10-724e / 0 CISTRootPortId     :128.1 BPDU-Protection     : Disabled TC or TCNreceived  :128 TC countper hello  :0 STPConverge Mode   :Normal  Time sincelast TC  :0 days 0h:32m:6s Number ofTC        :20 
 2、配置网络中的根交换机 由于根交换机的默认选举是通过交换机ID,MAC地址越小,越优先。交换机默认的优先级为32768也可以通过修改优先级来手动配置根交换机选举,一般性能好的做根。 2.1、通过优先级参数来配置SW2为主根,SW1为备根;SW2优先级为0,SW1优先级为4096。 <sw2>system-view [sw2]stppriority 0  //配置STP优先级   <sw1>system-view [sw1]stppriority 4096   [sw1]displaystp brief  MSTID Port                       Role  STP State     Protection    0   GigabitEthernet0/0/1       ROOT  FORWARDING      NONE    0   GigabitEthernet0/0/2       DESI  FORWARDING      NONE   [sw2]displaystp brief  MSTID Port                        Role  STP State    Protection    0   GigabitEthernet0/0/1       DESI  FORWARDING      NONE    0   GigabitEthernet0/0/4       DESI  FORWARDING      NONE    0   GigabitEthernet0/0/5       DESI  FORWARDING      NONE   [sw2]displaystp  -------[CISTGlobal Info][Mode STP]------- CISTBridge         :0   .4c1f-cc10-724e  //优先级为0 ConfigTimes        :Hello 2s MaxAge 20s FwDly15s MaxHop 20 ActiveTimes        :Hello 2s MaxAge 20s FwDly15s MaxHop 20 CISTRoot/ERPC      :0    .4c1f-cc10-724e / 0 CISTRegRoot/IRPC   :0    .4c1f-cc10-724e / 0 CISTRootPortId     :0.0 BPDU-Protection     : Disabled TC or TCNreceived  :129 TC countper hello  :0 STPConverge Mode   :Normal  Time sincelast TC  :0 days 0h:2m:30s Number ofTC        :21 [sw1]displaystp -------[CISTGlobal Info][Mode STP]------- CISTBridge         :4096 .4c1f-cc02-6b54  //优先级为4096 ConfigTimes        :Hello 2s MaxAge 20s FwDly15s MaxHop 20 ActiveTimes        :Hello 2s MaxAge 20s FwDly15s MaxHop 20 CISTRoot/ERPC      :0    .4c1f-cc10-724e / 20000 CISTRegRoot/IRPC   :4096 .4c1f-cc02-6b54 / 0 CISTRootPortId     :128.1 BPDU-Protection     : Disabled TC or TCNreceived  :37 TC countper hello  :0 STPConverge Mode   :Normal  Time sincelast TC  :0 days 0h:5m:20s Number of TC        :17 Last TCoccurred    :GigabitEthernet0/0/1 现在SW2为主根;SW1为备根。 2.2、通过命令配置SW3为主根,SW4为备根 [sw1]undostp priority  //不执行STP优先级参数配置 [sw2]undostp priority   <sw3>system-view [sw3]stproot primary  //配置STP主根   <sw4>system-view [sw4]stproot secondary  //配置STP备根 [sw3]displaystp brief  MSTID Port                       Role  STP State     Protection    0   GigabitEthernet0/0/2       DESI  FORWARDING      NONE    0   GigabitEthernet0/0/3       DESI  FORWARDING      NONE    0   GigabitEthernet0/0/5       DESI  FORWARDING      NONE    0   GigabitEthernet0/0/10      DESI  FORWARDING      NONE    0   GigabitEthernet0/0/11      DESI  FORWARDING      NONE [sw4]displaystp brief  MSTID Port                       Role  STP State     Protection    0   GigabitEthernet0/0/3       ROOT  FORWARDING      NONE    0   GigabitEthernet0/0/4       DESI  FORWARDING      NONE [sw3]displaystp -------[CISTGlobal Info][Mode STP]------- CISTBridge         :0   .4c1f-cc38-3f7a ConfigTimes        :Hello 2s MaxAge 20s FwDly15s MaxHop 20 ActiveTimes        :Hello 2s MaxAge 20s FwDly15s MaxHop 20 CISTRoot/ERPC      :0    .4c1f-cc38-3f7a / 0 CISTRegRoot/IRPC   :0    .4c1f-cc38-3f7a / 0 CISTRootPortId     :0.0 BPDU-Protection     : Disabled CIST RootType      : Primary root TC or TCNreceived  :290 TC countper hello  :0 STPConverge Mode   :Normal  Time sincelast TC  :0 days 0h:1m:10s Number ofTC        :28 Last TCoccurred    :GigabitEthernet0/0/3 [sw4]displaystp -------[CISTGlobal Info][Mode STP]------- CISTBridge         :4096 .4c1f-cc64-2aad ConfigTimes        :Hello 2s MaxAge 20s FwDly15s MaxHop 20 ActiveTimes        :Hello 2s MaxAge 20s FwDly15s MaxHop 20 CISTRoot/ERPC      :0    .4c1f-cc38-3f7a / 20000 CISTRegRoot/IRPC   :4096 .4c1f-cc64-2aad / 0 CISTRootPortId     :128.3 BPDU-Protection     : Disabled CIST RootType      :Secondary root TC or TCNreceived  :365 TC countper hello  :0 STPConverge Mode   :Normal  Time sincelast TC  :0 days 0h:1m:26s Number ofTC        :26 Last TCoccurred    :GigabitEthernet0/0/3 现在SW3为根交换机,SW4为备根。 
 3、理解根端口选举默认根端口选举原则:比较此交换机上每个端口到达根交换机的根路径开销,路径开销最小的端口成为根端口;若开销相同,则比较每个端口所在链路上的上行交换机ID;若仍相同,则比较每个端口所在链路的上行端口ID,每台交换机只能拥有一个根端口。
 通过配置接口的开销值来影响根接口的选举
 [sw4]display stp brief
 MSTID  Port                       Role  STP State     Protection
 0    GigabitEthernet0/0/3        ALTE DISCARDING      NONE
 0    GigabitEthernet0/0/4        ROOT LEARNING        NONE
 当前根接口为 ge 0/0/4
 [sw4]display stp interface GigabitEthernet 0/0/4  //查看生成树接口信息
 ……
 ----[Port4(GigabitEthernet0/0/4)][FORWARDING]----
 Port Protocol       :Enabled
 Port Role           :Root Port
 Port Priority       :128
 Port Cost(Dot1T )   :Config=auto / Active=20000
 Designated Bridge/Port   :4096.4c1f-cc10-724e / 128.4
 ……
 [sw4]display stp interface GigabitEthernet 0/0/3
 ----[Port3(GigabitEthernet0/0/3)][DISCARDING]----
 Port Protocol       :Enabled
 Port Role           :Alternate Port
 Port Priority       :128
 Port Cost(Dot1T )   :Config=auto / Active=20000
 Designated Bridge/Port   :32768.4c1f-cc38-3f7a / 128.3
 ……
 [sw4]interface GigabitEthernet 0/0/4
 [sw4-GigabitEthernet0/0/4]stp cost 30000  //配置生成树接口开销值为30000
 [sw4-GigabitEthernet0/0/4]quit
 [sw4]display stp brief
 MSTID  Port                       Role  STP State     Protection
 0    GigabitEthernet0/0/3        ROOT FORWARDING      NONE
 0    GigabitEthernet0/0/4        ALTE DISCARDING      NONE
 配置完成后,根端口成了GE 0/0/3
 另一种配置方法:
 [sw4]interface GigabitEthernet 0/0/4
 [sw4-GigabitEthernet0/0/4]undo stp cost  //恢复默认COST值
 [sw4]display stp brief
 MSTID  Port                       Role  STP State     Protection
 0    GigabitEthernet0/0/3        ALTE DISCARDING      NONE
 0    GigabitEthernet0/0/4        ROOT FORWARDING      NONE
 [sw4]interface GigabitEthernet 0/0/3
 [sw4-GigabitEthernet0/0/3]stp cost 2000
 [sw4-GigabitEthernet0/0/3]quit
 [sw4]display stp brief
 MSTID  Port                       Role  STP State     Protection
 0    GigabitEthernet0/0/3        ROOT LEARNING        NONE
 0    GigabitEthernet0/0/4        ALTE DISCARDING      NONE
 [sw4]display stp interface GigabitEthernet 0/0/3
 ……
 Last TC occurred    :GigabitEthernet0/0/3
 ----[Port3(GigabitEthernet0/0/3)][FORWARDING]----
 Port Protocol       :Enabled
 Port Role           :Root Port
 Port Priority       :128
 Port Cost(Dot1T )   :Config=2000 / Active=2000
 Designated Bridge/Port   :32768.4c1f-cc38-3f7a / 128.3
 ……
 说明COST的值越小,越优先。
 
 |