一篇文章讓你明白STP生成樹協議

文章核心:
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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章