STP的全稱是spanning-tree protocol,STP協議是一個二層的鏈路管理協議,它在提供鏈路冗餘的同時防止網絡產生環路,與VLAN配合可以提供鏈路負載均衡。生成樹協議現已經發展爲多生成樹協議和快速生成樹協議(RSTP,Rapid Spanning Tree Protocol,IEEE802.1W)。
一、配置實例拓撲圖
圖一
兩臺Cisco 2960交換機使用兩個千兆端口相連,默認情況下STP協議啓用的。通過兩臺交換機之間傳送BPDU協議數據單元,選出根交換機、根端口等,以便確定端口的轉發狀態。上圖中標記爲黃色的端口處於block狀態。
二、STP基本配置命令
1、修改Brigde ID,重新選根網橋
switch(config)#spanning-tree vlan 1 priority 4096
1、修改Brigde ID,重新選根網橋
switch(config)#spanning-tree vlan 1 priority 4096
圖二
圖三 根網橋改變,交換機端口的狀態也發生了變化(與圖一比較)
switch(config-if)spanning-tree vlan vlan-id port-priority 優先級值 交換機端口優先級值修改命令,通過修改端口優先值也可以更改端口的轉發狀態。
2、查看、檢驗STP(生成樹協議)配置
switch#show spanning-tree
switch#show spanning-tree active
switch#show spanning-tree detail
switch#show spanning-tree interface interface-id
switch#show spanning-tree vlan vlanid
switch#show spanning-tree
switch#show spanning-tree active
switch#show spanning-tree detail
switch#show spanning-tree interface interface-id
switch#show spanning-tree vlan vlanid
圖四
三、STP與VLAN負載均衡配置
圖五
配置負載均衡後,每個VLAN有自己的根網橋。每條vlan中繼鏈路只轉發所允許的Vlan數據幀。
switch(config-if)switchport trunk allowed vlan vlanid 這條命令配置某條trunk中繼鏈路只能轉發該vlan
switch(config-if)switchport trunk allowed vlan vlanid 這條命令配置某條trunk中繼鏈路只能轉發該vlan
圖六
圖七 查看每個Vlan的STP狀態
switch(config)#spanning-tree vlan vlandid root primary 該命令配置某個vlan的根網橋。利用這個命令可以使用Vlan利用VTP進行負載均衡。