學校爲了開展計算機教學和網絡辦公,創建了一個計算機教室和一個校辦公區,這兩處的計算機網絡經過兩臺交換機互相鏈接組成內部校園網,爲了提升網絡的可靠性,做爲網絡管理員,你要用2條鏈路將交換機互連,現要求在交換機上作適當的配置,使網絡避免環路
默認狀況下STP協議啓用的,經過兩臺交換機之間傳送BPDU協議數據單元,選出根交換機、根端口等,以便肯定端口的轉發狀態。上圖中標記爲橙色的端口處於block堵塞狀態
設置RSTP 查看交換機 show spanning-tree 狀態,瞭解根交換機和根端口狀況; 經過更改交換機生成樹的優先級spanning-tree vlan * priority 4096 能夠變化根交換機的角色;算法
S1: Switch>en Switch#conf t Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#hostname S1 S1(config)#end S1# %SYS-5-CONFIG_I: Configured from console by console S1#show spanning-tree //查看交換機spanning-tree 狀態 VLAN0001 Spanning tree enabled protocol ieee Root ID Priority 32769 Address 0060.5C36.5620 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 0060.7078.8BDE Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Aging Time 20 Interface Role Sts Cost Prio.Nbr Type ---------------- ---- --- --------- -------- -------------------------------- Fa0/10 Desg FWD 19 128.10 P2p Fa0/1 Root FWD 19 128.1 P2p Fa0/2 Altn BLK 19 128.2 P2p S1#conf t Enter configuration commands, one per line. End with CNTL/Z. S1(config)#interface fa0/10 S1(config-if)#switchport access vlan 10 //將fa0/10劃分到vlan 10 % Access VLAN does not exist. Creating vlan 10 S1(config-if)#exit S1(config)#interface range fa0/1 - 2 //設置fa0/1,fa0/2端口狀態爲trunk模式 S1(config-if-range)#switchport mode trunk %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to down %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to up S1(config-if-range)#exit S1(config)#spanning-tree mode ? //設置spanning-tree 爲RSTP模式 pvst Per-Vlan spanning tree mode rapid-pvst Per-Vlan rapid spanning tree mode S1(config)#spanning-tree mode rapid-pvst S1(config)# S2: Switch>en Switch#show spanning-tree VLAN0001 Spanning tree enabled protocol ieee Root ID Priority 32769 Address 0060.5C36.5620 This bridge is the root //根交換機 Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Bridge ID Priority 32769 (priority 32768 sys-id-ext 1) Address 0060.5C36.5620 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 Fa0/10 Desg FWD 19 128.10 P2p Switch# %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to down %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to up Switch# Switch#conf t Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#hostname S2 S2(config)#interface fa0/10 S2(config-if)#switchport access vlan 10 % Access VLAN does not exist. Creating vlan 10 S2(config-if)#exit S2(config)#interface range fa0/1 - 2 S2(config-if-range)#switchport mode trunk S2(config-if-range)#exit S2(config)#spanning-tree mode rapid-pvst S2(config)#
當主鏈路處於down狀態時,可以自動的切換到備份鏈路,保證數據的正常轉發。
在S2上shutdown 掉 fa0/1
Switch#conf t Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#int Switch(config)#interface fa0/1 Switch(config-if)#shu Switch(config-if)#shutdown //shutdown fa0/1端口 Switch(config-if)# %LINK-5-CHANGED: Interface FastEthernet0/1, changed state to administratively down %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down Switch#show spanning-tree VLAN0001 Spanning tree enabled protocol rstp Root ID Priority 32769 Address 0001.63E2.4A7A This bridge is the root Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Bridge ID Priority 32769 (priority 32768 sys-id-ext 1) Address 0001.63E2.4A7A 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 VLAN0010 Spanning tree enabled protocol rstp Root ID Priority 32778 Address 0001.63E2.4A7A This bridge is the root Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Bridge ID Priority 32778 (priority 32768 sys-id-ext 10) Address 0001.63E2.4A7A 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 Fa0/10 Desg FWD 19 128.10 P2p Switch# PC1: PC>ipconfig IP Address......................: 192.168.1.2 Subnet Mask.....................: 255.255.255.0 Default Gateway.................: 192.168.1.1 PC>ping -t 192.168.1.3 Pinging 192.168.1.3 with 32 bytes of data: Reply from 192.168.1.3: bytes=32 time=78ms TTL=128 Reply from 192.168.1.3: bytes=32 time=94ms TTL=128 Reply from 192.168.1.3: bytes=32 time=78ms TTL=128 Reply from 192.168.1.3: bytes=32 time=78ms TTL=128 Reply from 192.168.1.3: bytes=32 time=78ms TTL=128 Reply from 192.168.1.3: bytes=32 time=94ms TTL=128 Reply from 192.168.1.3: bytes=32 time=93ms TTL=128 Reply from 192.168.1.3: bytes=32 time=93ms TTL=128 Reply from 192.168.1.3: bytes=32 time=62ms TTL=128 Reply from 192.168.1.3: bytes=32 time=94ms TTL=128 Reply from 192.168.1.3: bytes=32 time=79ms TTL=128 Reply from 192.168.1.3: bytes=32 time=94ms TTL=128 ......