学校为了开展计算机教学和网络办公,创建了一个计算机教室和一个校办公区,这两处的计算机网络经过两台交换机互相链接组成内部校园网,为了提升网络的可靠性,做为网络管理员,你要用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 ......