思科模拟器——STP协议实验配置

  1. STP生成树协议+实验配置
  2. 思科交换机配置——生成树协议(STP)
  3. 一文搞懂STP(从原理到配置)

一、以太网环路问题

  • 拓扑图
    在这里插入图片描述

二、基本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执行过程:

  1. 每个广播域中选举一个根桥 (Root)
  2. 每个非根桥选举一个根端口(Root Port)
  3. 每个物理网段选举一个指定端口 (Designated port)
  4. 非指定端口只会被阻塞 (Blocking)

具体过程

  1. 选根桥:
    桥ID=bridge ID+MAC地址,bridge ID的取值范围为0-65535(必须是4096的倍数)。先比BID,小的作为根桥;BID相同,比MAC,小的作为根桥。上述S1和S2的BID相同,S1的MAC比S2的MAC大,所以S2被选为根桥。
  2. 非根桥选根端口:
    ① 到根网桥开销最小的端口(开销 = 到根的路径开销之和)
    ② 直连网桥的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端口被选举为根端口。在这里插入图片描述
  3. 选择指定端口
    ①到根网桥的开销最小
    ②所在网桥的bridge-id最小
    ③比较本端口的端口ID
  4. 阻塞端口
    非根非指定端口,在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#

在这里插入图片描述


  • 9
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

二木 同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值