思科Packet Tracer 7.4 生成树协议(STP)配置与安全防护上机讲义
一、实验目的
- 理解STP/RSTP工作原理及网络环路危害
- 掌握交换机基础IP配置与管理
- 熟练配置RSTP并手动指定根桥
- 掌握BPDU Guard、Root Guard安全防护配置
- 验证STP状态及攻击防护效果
二、实验环境
- 软件:Cisco Packet Tracer 7.4
- 设备:3台Cisco 2960交换机(命名A、B、C)、1台PC(攻击测试用)
- 拓扑:交换机A为主根桥,连接交换机B、C;交换机B、C互连形成冗余环网
三、IP规划
- 交换机A:VLAN1 IP 192.168.1.1/24
- 交换机B:VLAN1 IP 192.168.1.2/24
- 交换机C:VLAN1 IP 192.168.1.3/24
四、基础配置(三台交换机通用,仅主机名/IP不同)
4.1 交换机A基础配置
bash
# 进入特权模式
Switch>enable
Switch#configure terminal
# 配置主机名
Switch(config)#hostname A
# 配置管理VLAN1接口IP
A(config)#interface Vlan1
A(config-if)#ip address 192.168.1.1 255.255.255.0
A(config-if)#no shutdown
A(config-if)#exit
# 关闭多余端口(可选,增强稳定性)
A(config)#interface range FastEthernet0/1-24
A(config-if-range)#shutdown
A(config-if-range)#exit
# 保存配置
A#write memory
# 或
A#copy running-config startup-config
4.2 交换机B基础配置
bash
Switch>enable
Switch#configure terminal
Switch(config)#hostname B
B(config)#interface Vlan1
B(config-if)#ip address 192.168.1.2 255.255.255.0
B(config-if)#no shutdown
B(config-if)#exit
B(config)#interface range FastEthernet0/1-24
B(config-if-range)#shutdown
B(config-if-range)#exit
B#write memory
4.3 交换机C基础配置
bash
Switch>enable
Switch#configure terminal
Switch(config)#hostname C
C(config)#interface Vlan1
C(config-if)#ip address 192.168.1.3 255.255.255.0
C(config-if)#no shutdown
C(config-if)#exit
C(config)#interface range FastEthernet0/1-24
C(config-if-range)#shutdown
C(config-if-range)#exit
C#write memory
五、RSTP配置(快速生成树协议)
5.1 交换机A(主根桥,优先级最高)
bash
# 全局启用STP
A(config)#spanning-tree
# 切换为RSTP模式(默认PVST,RSTP收敛更快)
A(config)#spanning-tree mode rapid-pvst
# 设置优先级为4096(根桥优先级必须为4096倍数,数值越小优先级越高)
A(config)#spanning-tree vlan 1 priority 4096
5.2 交换机B、C(默认优先级,备用桥)
bash
# 交换机B配置
B(config)#spanning-tree
B(config)#spanning-tree mode rapid-pvst
# 交换机C配置
C(config)#spanning-tree
C(config)#spanning-tree mode rapid-pvst
六、STP安全防护配置
6.1 BPDU Guard配置(接入端口防伪造BPDU攻击)
作用:接入端口启用PortFast+BPDU Guard,收到BPDU直接关闭端口
bash
# 交换机A(所有接入端口,此处以Fa0/1-20为例)
A(config)#interface range FastEthernet0/1-20
A(config-if-range)#spanning-tree portfast
A(config-if-range)#spanning-tree bpduguard enable
A(config-if-range)#no shutdown
# 交换机B
B(config)#interface range FastEthernet0/1-20
B(config-if-range)#spanning-tree portfast
B(config-if-range)#spanning-tree bpduguard enable
B(config-if-range)#no shutdown
# 交换机C
C(config)#interface range FastEthernet0/1-20
C(config-if-range)#spanning-tree portfast
C(config-if-range)#spanning-tree bpduguard enable
C(config-if-range)#no shutdown
6.2 Root Guard配置(互联端口防非法根桥抢占)
作用:交换机互联端口启用Root Guard,收到更高优先级BPDU直接阻塞端口
bash
# 交换机A互联端口(Fa0/23连接B,Fa0/24连接C)
A(config)#interface FastEthernet0/23
A(config-if)#spanning-tree rootguard
A(config-if)#no shutdown
A(config)#interface FastEthernet0/24
A(config-if)#spanning-tree rootguard
A(config-if)#no shutdown
# 交换机B互联端口(Fa0/23连接A,Fa0/24连接C)
B(config)#interface FastEthernet0/23
B(config-if)#spanning-tree rootguard
B(config-if)#no shutdown
B(config)#interface FastEthernet0/24
B(config-if)#spanning-tree rootguard
B(config-if)#no shutdown
# 交换机C互联端口(Fa0/23连接A,Fa0/24连接B)
C(config)#interface FastEthernet0/23
C(config-if)#spanning-tree rootguard
C(config-if)#no shutdown
C(config)#interface FastEthernet0/24
C(config-if)#spanning-tree rootguard
C(config-if)#no shutdown
七、配置验证
7.1 查看STP状态(确认A为根桥)
bash
# 交换机A查看
A#show spanning-tree vlan 1
# 关键输出:
# Root ID 优先级4096,本地为根桥
# 交换机B查看
B#show spanning-tree vlan 1
# 关键输出:
# Root ID 指向交换机A,端口为根端口
# 交换机C查看
C#show spanning-tree vlan 1
# 关键输出:
# Root ID 指向交换机A,端口为根端口
7.2 查看端口安全配置
bash
# 查看BPDU Guard状态
A#show spanning-tree summary
# 查看Root Guard状态
A#show interface FastEthernet0/23 spanning-tree
八、STP攻击防护测试
8.1 测试BPDU Guard(伪造BPDU攻击)
- 将PC连接到交换机B的Fa0/1端口(已启用BPDU Guard)
- 在PC上安装攻击工具(如Yersinia),发送伪造高优先级BPDU
- 查看交换机B端口状态:
bash
B#show interface FastEthernet0/1 status
# 结果:端口自动变为"Err-disabled"(错误禁用),防护生效
8.2 测试Root Guard(非法根桥抢占)
- 新增一台交换机D,优先级设为0(高于交换机A)
- 将交换机D连接到交换机A的Fa0/23端口(已启用Root Guard)
- 查看交换机A端口状态:
bash
A#show spanning-tree vlan 1
# 结果:Fa0/23端口被阻塞,交换机A仍为根桥,防护生效
九、实验总结
- RSTP通过阻塞冗余端口解决环路,根桥选举由优先级+MAC决定
- BPDU Guard保护接入端口,防止终端伪造BPDU破坏拓扑
- Root Guard保护核心端口,防止非法设备抢占根桥
- 网络安全需基础配置+安全特性结合,提升稳定性
十、常见问题排查
- 端口Err-disabled:BPDU攻击触发,用
shutdown+no shutdown恢复 - 根桥异常:检查优先级配置,确保主根桥优先级最小
- 端口Down:确认
no shutdown配置,物理连接正常
"""
Cisco Packet Tracer 7.4 上机讲义:STP/RSTP 配置与安全防护
一、实验目的
- 理解 STP/RSTP 作用:防止二层环路、实现冗余。
- 掌握交换机基础配置:主机名、管理 VLAN IP。
- 配置 RSTP,指定根桥,控制拓扑。
- 配置 BPDU Guard、Root Guard,防御 STP 攻击。
- 验证 STP 状态与防护效果。
二、实验拓扑
- 交换机:A、B、C(Cisco 2960)
- 连接:
- A ↔ B
- A ↔ C
- B ↔ C
- 管理 IP:
- A:192.168.1.1/24
- B:192.168.1.2/24
- C:192.168.1.3/24
三、基础配置(三台交换机)
交换机 A
Switch>enable
Switch#configure terminal
Switch(config)#hostname A
A(config)#interface Vlan1
A(config-if)#ip address 192.168.1.1 255.255.255.0
A(config-if)#no shutdown
A(config-if)#exit
A#write memory
交换机 B
Switch>enable
Switch#configure terminal
Switch(config)#hostname B
B(config)#interface Vlan1
B(config-if)#ip address 192.168.1.2 255.255.255.0
B(config-if)#no shutdown
B(config-if)#exit
B#write memory
### 6.2 查看保护功能
show spanning-tree summary
show interface Fa0/23 spanning-tree
## 七、攻击测试(演示)
### 7.1 BPDU Guard
PC 接入交换机接入端口,发送伪造 BPDU:
- 端口进入 **Err-disabled**,环路阻断。
### 7.2 Root Guard
接一台优先级更低的交换机到互联端口:
- 端口被阻塞,**根桥保持为 A**。
## 八、实验报告要求
1. 拓扑图、IP 规划
2. 完整配置
3. `show spanning-tree` 截图
4. 安全防护测试现象记录
5. 总结:RSTP、BPDU Guard、Root Guard 的作用
---