生成树协议(英语:Spanning Tree Protocol,STP),是一种工作在OSI网络模型中的第二层(数据链路层)的通信协议,基本应用是防止交换机冗余链路产生的环路.用于确保以太网中无环路的逻辑拓扑结构.从而避免了广播风暴,大量占用交换机的资源。
案例:
[SW1]stp enable
[SW1]vlan batch 10 20
[SW1]interface g0/0/1
[SW1-GigabitEthernet0/0/1]port link-type trunk
[SW1-GigabitEthernet0/0/1]port trunk allow-pass vlan all
[SW1]interface g0/0/2
[SW1-GigabitEthernet0/0/2]port link-type trunk
[SW1-GigabitEthernet0/0/2]port trunk allow-pass vlan all
配置sw2
[Huawei]sysname SW2
[SW2]vlan batch 10 20
[SW2]stp enable
[SW2]interface g0/0/1
[SW2-GigabitEthernet0/0/1]port link-type trunk
[SW2-GigabitEthernet0/0/1]port trunk allow-pass vlan all
[SW2]interface g0/0/3
[SW2-GigabitEthernet0/0/3]port link-type trunk
[SW2-GigabitEthernet0/0/3]port trunk allow-pass vlan all
配置sw3
[SW3]vlan batch 10 20
[SW3]stp enable
[SW3]interface g0/0/2
[SW3-GigabitEthernet0/0/2]port link-type trunk
[SW3-GigabitEthernet0/0/2]port trunk allow-pass vlan all
[SW3]interface g0/0/3
[SW3-GigabitEthernet0/0/3]port link-type trunk
[SW3-GigabitEthernet0/0/3]port trunk allow-pass vlan all
第二步配置stp模式
[SW1]stp mode ?
mstp Multiple Spanning Tree Protocol (MSTP) mode
rstp Rapid Spanning Tree Protocol (RSTP) mode
stp Spanning Tree Protocol (STP) mode
[SW1]stp mode stp
[SW1]stp priority 4096
[SW2]stp mode stp
[SW2]stp priority 8192
[SW3]stp mode stp
[SW1]display stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge :4096 .4c1f-cc1b-22ed
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-cc1b-22ed / 0
CIST RegRoot/IRPC :4096 .4c1f-cc1b-22ed / 0
CIST RootPortId :0.0
BPDU-Protection :Disabled
TC or TCN received :7
TC count per hello :0
STP Converge Mode :Normal
Time since last TC :0 days 0h:1m:33s
Number of TC :9
Last TC occurred :GigabitEthernet0/0/2
[SW2]display stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge :8192 .4c1f-cca6-0f90
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-cc1b-22ed / 20000
CIST RegRoot/IRPC :8192 .4c1f-cca6-0f90 / 0
CIST RootPortId :128.1
BPDU-Protection :Disabled
TC or TCN received :42
TC count per hello :0
STP Converge Mode :Normal
Time since last TC :0 days 0h:4m:13s
Number of TC :8
Last TC occurred :GigabitEthernet0/0/1
[SW3]display stp
-------[CIST Global Info][Mode STP]-------
CIST Bridge :32768.4c1f-ccf2-7f99
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-cc1b-22ed / 20000
CIST RegRoot/IRPC :32768.4c1f-ccf2-7f99 / 0
CIST RootPortId :128.2
BPDU-Protection :Disabled
TC or TCN received :66
TC count per hello :0
STP Converge Mode :Normal
Time since last TC :0 days 0h:5m:59s
Number of TC :9
Last TC occurred :GigabitEthernet0/0/2
现在来查看一下sw2的g0/0/1的stp状态
[SW2]display stp interface g0/0/1
-------[CIST Global Info][Mode STP]-------
CIST Bridge :8192 .4c1f-cca6-0f90
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-cc1b-22ed / 20000
CIST RegRoot/IRPC :8192 .4c1f-cca6-0f90 / 0
CIST RootPortId :128.1
BPDU-Protection :Disabled
TC or TCN received :42
TC count per hello :0
STP Converge Mode :Normal
Time since last TC :0 days 0h:9m:55s
Number of TC :8
Last TC occurred :GigabitEthernet0/0/1
----[Port1(GigabitEthernet0/0/1)][FORWARDING]----
Port Protocol :Enabled
Port Role :Root Port
Port Priority :128
Port Cost(Dot1T ) :Config=auto / Active=20000
Designated Bridge/Port :4096.4c1f-cc1b-22ed / 128.1
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 :2
TC or TCN received :35
BPDU Sent :3
TCN: 2, Config: 1, RST: 0, MST: 0
BPDU Received :303
TCN: 0, Config: 303, RST: 0, MST: 0