一、以太网环路问题
- 拓扑图
二、基本STP命令
- 查看S1交换机
Switch>enable // 进入特权模式
Switch#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname S1 // 重命名
S1(config)#exit
S1#
S1#show spanning-tree // 查看S1的STP
VLAN0001 // VLAN 1的STP配置信息
Spanning tree enabled protocol ieee // 启用了 IEEE 标准的STP
// root桥信息
Root ID Priority 32769 // 根桥ID/优先级
Address 00D0.9777.8101 // root的MAC地址
Cost 19 // 到根交换机的路径代价,即端口开销
Port 1(FastEthernet0/1) // 该交换机到根桥的连接端口
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec // 确定网络拓扑并防止环路的 STP 计时器值
// 本交换机信息
Bridge ID Priority 32769 (priority 32768 sys-id-ext 1)
Address 00E0.8F04.CE19 // S1的MAC地址,S1不是root
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 20 // MAC 地址表的老化时间
// Role:该端口在 STP 中的角色。
// 可能的角色有 Root(根端口)、Desg(指定端口)、Altn(备用端口)等
// Sts:端口状态,可能的状态包括 FWD(转发)和 BLK(阻塞)
// Cost: 连接到该端口的路径代价
// Prio.Nbr: 端口优先级和端口编号
// Type: 端口类型,通常是 P2p(点对点连接)或者 Alt(备用)
Interface Role Sts Cost Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/3 Desg FWD 19 128.3 P2p
Fa0/2 Altn BLK 19 128.2 P2p // 2端口BLK阻塞,备用端口
Fa0/1 Root FWD 19 128.1 P2p // 1端口连接的是根交换机
S1#
- 查看S2交换机
Switch>enable // 进入特权模式
Switch#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname S2 // 重命名
S2(config)#exit
S2#
VLAN0001
Spanning tree enabled protocol ieee
Root ID Priority 32769
Address 00D0.9777.8101 // MAC地址
This bridge is the root // root交换机
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Bridge ID Priority 32769 (priority 32768 sys-id-ext 1)
Address 00D0.9777.8101
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 20
Interface Role Sts Cost Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/3 Desg FWD 19 128.3 P2p // 端口都是FWD转发
Fa0/1 Desg FWD 19 128.1 P2p
Fa0/2 Desg FWD 19 128.2 P2p
S2#
在此例中S2为根网桥,所以它的端口都为转发状态
,S1的端口开销都是19默认端口开销。
如何更改S1的Fa0/2端口为Root端口?
思科PT不支持cost命令。
要更改S1的Fa0/2端口为Root端口,需要在S2上面设置相应的端口的优先级,所以下面的设置在S2
上进行
S2#show spanning-tree
VLAN0001
Spanning tree enabled protocol ieee
Root ID Priority 32769
Address 00D0.9777.8101
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 00D0.9777.8101
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 20
Interface Role Sts Cost Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/3 Desg FWD 19 128.3 P2p
Fa0/1 Desg FWD 19 128.1 P2p
Fa0/2 Desg FWD 19 128.2 P2p // 2端口优先级为128
S2#configure terminal // 进入终端配置
Enter configuration commands, one per line. End with CNTL/Z.
S2(config)#interface f0/2 // 进入f0/2端口
S2(config-if)#spanning-tree vlan 1 port-priority 48 // 修改成小于128
// 注意必须是16的倍数
S2(config-if)#exit
S2(config)#end
S2#
%SYS-5-CONFIG_I: Configured from console by console
S2#show spanning-tree
VLAN0001
Spanning tree enabled protocol ieee
Root ID Priority 32769
Address 00D0.9777.8101
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 00D0.9777.8101
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/3 Desg FWD 19 128.3 P2p
Fa0/2 Desg FWD 19 48.2 P2p // 优先级修改成功
S2#
修改后网络拓扑改变:
- 查看S1信息
S1>enable
S1#show spanning-tree
VLAN0001
Spanning tree enabled protocol ieee
Root ID Priority 32769
Address 00D0.9777.8101
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.8F04.CE19
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 // 1端口阻塞,备用端口
Fa0/2 Root FWD 19 128.2 P2p // 2端口变为Root
Fa0/3 Desg FWD 19 128.3 P2p
S1#
STP执行过程:
- 每个广播域中选举一个根桥 (Root)
- 每个非根桥选举一个根端口(Root Port)
- 每个物理网段选举一个指定端口 (Designated port)
- 非指定端口只会被阻塞 (Blocking)
具体过程:
- 选根桥:
桥ID=bridge ID+MAC地址
,bridge ID的取值范围为0-65535(必须是4096的倍数)。先比BID,小的作为根桥;BID相同,比MAC,小的作为根桥。上述S1和S2的BID相同,S1的MAC比S2的MAC大,所以S2被选为根桥。 - 非根桥选根端口:
① 到根网桥开销最小的端口(开销 = 到根的路径开销之和)
② 直连网桥的bridge-id最小的端口(有两个端口到根开销相同,比较两个端口连的网桥BID,小的作为Root Port)
③ 比较对方的端口ID:两个交换机间的环路,前两步都没比较出来。
如下,S2是根桥,S1要选个根端口,前两步比较不出。S1的Fa0/1连的S2的Fa0/1,S2的Fa0/1端口ID是128.1
(端口ID=优先级+编号);S1的Fa0/2连的S2的Fa0/2,S2的Fa0/2端口ID是128.2
,小的作为根端口,所以S1的Fa0/1被选举为根端口。
上面把S2
的优先级改为48,S2的Fa0/2端口ID变成48.2,48.2 < 128.1,所以S1的Fa0/2端口被选举为根端口。 - 选择指定端口
①到根网桥的开销最小
②所在网桥的bridge-id最小
③比较本端口的端口ID - 阻塞端口
非根非指定端口,在STP协议中将会被阻塞
如何更改S1为Root(根网桥)?
S1>enable
S1#show spanning-tree
VLAN0001
Spanning tree enabled protocol ieee
Root ID Priority 32769
Address 00D0.9777.8101
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.8F04.CE19
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 20
Interface Role Sts Cost Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/2 Root FWD 19 128.2 P2p
Fa0/3 Desg FWD 19 128.3 P2p
Fa0/1 Altn BLK 19 128.1 P2p
S1#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
S1(config)#spanning-tree vlan 1 root primary // 把当前交换机改为vlan 1的根桥
S1(config)#end
S1#
%SYS-5-CONFIG_I: Configured from console by console
S1#show spanning-tree
VLAN0001
Spanning tree enabled protocol ieee
Root ID Priority 24577 // Root ID和优先级改变
Address 00E0.8F04.CE19
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 00E0.8F04.CE19
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 20
Interface Role Sts Cost Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/2 Altn BLK 19 128.2 P2p
Fa0/3 Desg FWD 19 128.3 P2p
Fa0/1 Desg LRN 19 128.1 P2p // LRN状态:不转发用户流量正在学习MAC地址,之后变成FWD
S1#