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

文章核心: 1.STP協議是什麼? 2.STP選舉規則 3.STP簡單實驗 4.STP基本配置python

1、STP(Spanning Tree Protocol)協議(生成樹協議)邏輯上斷開環路,防止二層網絡的廣播風暴的產生。

2、關鍵問題:

(1)爲何要用STP協議? 爲了解決第二層網絡環路問題而又要保證網絡的穩定和健壯性,引入了鏈路動態管理的策略。首先經過阻塞某些鏈路避免環路的產生(避免環路),當正常工做的鏈路因爲故障斷開時,阻塞的鏈路馬上激活,迅速取代故障鏈路的位置,保證網絡的正常運行。(生成冗餘鏈路)這就是生成樹(STP)協議。 (2)解決環路問題 避免環路 每一個LAN都會選擇一臺設備爲指定交換機,經過該設備的端口鏈接到根,該端口爲指定端口( Designated port ) 將交換網絡中全部設備的根端口(RP)和指定端口(DP)設爲轉發狀態(Forwarding),將其餘端口設爲阻塞狀態(Blocking) 生成樹通過一段時間(默認值是50秒左右)穩定以後,全部端口要麼進入轉發狀態,要麼進入阻塞狀態。 (3)創建冗餘鏈路讓網絡更穩定 冗餘鏈路能夠理解爲備份鏈路,其餘鏈路出現問題了備份的冗餘鏈路會代替上去,維持網絡穩定markdown

3、STP收斂過程

說白了就是我在一個階段給你發請求你長時間不迴應,我會結束這個階段進入下一個階段 當網絡的拓撲發生變化時,網絡會從一個狀態向另外一個狀態過渡,從新打開或阻斷某些端口。交換機的端口要通過幾種狀態:禁用(Disable)——>阻塞(Blocking)——>監聽狀態(Listenning)——>學習狀態(Learning)——>轉發狀態(Forwarding) 4、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 禁用網絡

5、實驗部分:

1.理解STP中端口角色變化規則 2.掌握基本配置STP協議學習

1、在Cisco模擬器中拖三臺交換機鏈接查看他們的默認生成樹狀況 在這裏插入圖片描述咱們在圖中也能夠看出S0爲根橋兩個端口分別是指定端口 S1兩個端口與S0對應的端口爲根端口,另外一個爲指定端口 S2兩個端口與S0對應的爲根端口,另外一個爲非指定端口(阻塞端口) 黃色的等表明就是阻塞端口(非指定端口)ui

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狀態
複製代碼

2、更改根橋,設置備份根橋,查看結果

在這裏插入圖片描述 從圖中能夠看出變化S1成了根橋,S0爲備份根橋。若是S1出故障了S0會代替S1稱爲根橋 再次查看Switch生成樹狀態spa

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
複製代碼