文章核心:
1.STP協定是什麼?
2.STP選舉規則
3.STP簡單實驗
4.STP基本配置
一、STP(Spanning Tree Protocol)協定(生成樹協定)邏輯上斷開環路,防止二層網絡的廣播風暴的産生。
二、關鍵問題:
(1)為什麼要用STP協定?
為了解決第二層網絡環路問題而又要保證網絡的穩定和健壯性,引入了鍊路動态管理的政策。首先通過阻塞某些鍊路避免環路的産生(避免環路),當正常工作的鍊路由于故障斷開時,阻塞的鍊路立刻激活,迅速取代故障鍊路的位置,保證網絡的正常運作。(生成備援鍊路)這就是生成樹(STP)協定。
(2)解決環路問題
避免環路
每個LAN都會選擇一台裝置為指定交換機,通過該裝置的端口連接配接到根,該端口為指定端口( Designated port )
将交換網絡中所有裝置的根端口(RP)和指定端口(DP)設為轉發狀态(Forwarding),将其他端口設為阻塞狀态(Blocking)
生成樹經過一段時間(預設值是50秒左右)穩定之後,所有端口要麼進入轉發狀态,要麼進入阻塞狀态。
(3)建立備援鍊路讓網絡更穩定
備援鍊路可以了解為備份鍊路,其他鍊路出現問題了備份的備援鍊路會代替上去,維持網絡穩定
三、STP收斂過程
說白了就是我在一個階段給你發請求你長時間不回應,我會結束這個階段進入下一個階段
當網絡的拓撲發生變化時,網絡會從一個狀态向另一個狀态過渡,重新打開或阻斷某些端口。交換機的端口要經過幾種狀态:禁用(Disable)——>阻塞(Blocking)——>監聽狀态(Listenning)——>學習狀态(Learning)——>轉發狀态(Forwarding)
四、STP中根橋,根端口,指定端口的選舉規則:
1.在一個廣播域選擇一個根橋
使用stp協定,會向鄰居s發送BPDU,bridge protocol date unit
交換機向所在廣播域發送的bpdu
内容有:
bridge ID
優先級
mac位址
選舉規則:
主機闆mac位址,交換機端口mac位址是端口号+主機闆mac位址得來
檢視優先級,mac位址,網橋ID依次檢視選取最小的為根橋
2.每個非根橋選擇一個根端口(RP)
1.路徑成本最低
2.直連的網橋id最小
3.最低發送者端口id最小
3.每個段選擇一個指定端口(DP)
每一個線連接配接的兩段選一個指定端口,RP的對端肯定是DP
對比bri id優先成為dp,另一個無身份
4.阻塞非指定端口
沒有身份的會被阻塞掉,稱為AP,用來防環
指定端口發bpdu,根端口接受
5.個端口狀态
block 非指定端口回到block狀态
listen 監聽bpdu,不能學習mac位址,不轉發資料,維持15秒,确定端口角色!
learn 學習mac位址,不轉發資料,維持15秒
forword 可轉發資料
disable 禁用
五、實驗部分:
1.了解STP中端口角色變化規則
2.掌握基本配置STP協定
一、在Cisco模拟器中拖三台交換機連接配接檢視他們的預設生成樹情況

我們在圖中也可以看出S0為根橋兩個端口分别是指定端口
S1兩個端口與S0對應的端口為根端口,另一個為指定端口
S2兩個端口與S0對應的為根端口,另一個為非指定端口(阻塞端口)
黃色的等代表就是阻塞端口(非指定端口)
S0
Switch#show spanning-tree
VLAN0001
Spanning tree enabled protocol ieee
# 根橋的資訊
Root ID Priority 32769 # 根橋的優先級
Address 0001.63D0.3450 # 根橋的mac位址
This bridge is the root # 這個s是根橋
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Bridge ID Priority 32769 (priority 32768 sys-id-ext 1)
Address 0001.63D0.3450
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 20
Interface Role Sts Cost Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/1 Desg FWD 19 128.1 P2p # 可以看出與根橋兩個端口都是指定端口
Fa0/2 Desg FWD 19 128.2 P2p # 指定端口
S1
Switch#show spanning-tree
VLAN0001
Spanning tree enabled protocol ieee
Root ID Priority 32769
Address 0001.63D0.3450
Cost 19
Port 1(FastEthernet0/1)
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Bridge ID Priority 32769 (priority 32768 sys-id-ext 1)
Address 0090.216C.B791
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 20
Interface Role Sts Cost Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/2 Desg FWD 19 128.2 P2p # 指定端口,妝發狀态
Fa0/1 Root FWD 19 128.1 P2p # 根端口(與),轉發狀态
S2
Switch#show spanning-tree
VLAN0001
Spanning tree enabled protocol ieee
Root ID Priority 32769
Address 0001.63D0.3450
Cost 19
Port 1(FastEthernet0/1)
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Bridge ID Priority 32769 (priority 32768 sys-id-ext 1)
Address 00E0.A3D9.8D5E
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 20
Interface Role Sts Cost Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/1 Root FWD 19 128.1 P2p #根端口,處于轉發狀态
Fa0/2 Altn BLK 19 128.2 P2p #阻塞端口,處于block狀态
二、更改根橋,設定備份根橋,檢視結果
從圖中可以看出變化S1成了根橋,S0為備份根橋。如果S1出故障了S0會代替S1稱為根橋
再次檢視Switch生成樹狀态
S0
Switch(config)#spanning-tree vlan 1 root secondary
Switch#show spanning-tree
VLAN0001
Spanning tree enabled protocol ieee
Root ID Priority 24577
Address 0090.216C.B791
Cost 19
Port 1(FastEthernet0/1)
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Bridge ID Priority 28673 (priority 28672 sys-id-ext 1)
Address 0001.63D0.3450
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 20
Interface Role Sts Cost Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/1 Root FWD 19 128.1 P2p
Fa0/2 Desg FWD 19 128.2 P2p
S1
Switch(config)#spanning-tree vlan 1 root primary
Switch#show spanning-tree
VLAN0001
Spanning tree enabled protocol ieee
Root ID Priority 24577
Address 0090.216C.B791
This bridge is the root
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Bridge ID Priority 24577 (priority 24576 sys-id-ext 1)
Address 0090.216C.B791
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 20
Interface Role Sts Cost Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/2 Desg FWD 19 128.2 P2p
Fa0/1 Desg FWD 19 128.1 P2p
S2
Switch#show spanning-tree
VLAN0001
Spanning tree enabled protocol ieee
Root ID Priority 24577
Address 0090.216C.B791
Cost 19
Port 2(FastEthernet0/2)
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Bridge ID Priority 32769 (priority 32768 sys-id-ext 1)
Address 00E0.A3D9.8D5E
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 20
Interface Role Sts Cost Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/1 Altn BLK 19 128.1 P2p
Fa0/2 Root FWD 19 128.2 P2p