思科Packet Tracer 7.4 生成树协议(STP)配置与安全防护上机讲义

思科Packet Tracer 7.4 生成树协议(STP)配置与安全防护上机讲义

一、实验目的

  1. 理解STP/RSTP工作原理及网络环路危害
  2. 掌握交换机基础IP配置与管理
  3. 熟练配置RSTP并手动指定根桥
  4. 掌握BPDU Guard、Root Guard安全防护配置
  5. 验证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攻击)

  1. 将PC连接到交换机B的Fa0/1端口(已启用BPDU Guard)
  2. 在PC上安装攻击工具(如Yersinia),发送伪造高优先级BPDU
  3. 查看交换机B端口状态:
bash 复制代码
B#show interface FastEthernet0/1 status
# 结果:端口自动变为"Err-disabled"(错误禁用),防护生效

8.2 测试Root Guard(非法根桥抢占)

  1. 新增一台交换机D,优先级设为0(高于交换机A)
  2. 将交换机D连接到交换机A的Fa0/23端口(已启用Root Guard)
  3. 查看交换机A端口状态:
bash 复制代码
A#show spanning-tree vlan 1
# 结果:Fa0/23端口被阻塞,交换机A仍为根桥,防护生效

九、实验总结

  1. RSTP通过阻塞冗余端口解决环路,根桥选举由优先级+MAC决定
  2. BPDU Guard保护接入端口,防止终端伪造BPDU破坏拓扑
  3. Root Guard保护核心端口,防止非法设备抢占根桥
  4. 网络安全需基础配置+安全特性结合,提升稳定性

十、常见问题排查

  1. 端口Err-disabled:BPDU攻击触发,用shutdown+no shutdown恢复
  2. 根桥异常:检查优先级配置,确保主根桥优先级最小
  3. 端口Down:确认no shutdown配置,物理连接正常

"""

Cisco Packet Tracer 7.4 上机讲义:STP/RSTP 配置与安全防护

一、实验目的

  1. 理解 STP/RSTP 作用:防止二层环路、实现冗余。
  2. 掌握交换机基础配置:主机名、管理 VLAN IP。
  3. 配置 RSTP,指定根桥,控制拓扑。
  4. 配置 BPDU Guard、Root Guard,防御 STP 攻击。
  5. 验证 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 的作用

---
相关推荐
z202305083 小时前
以太网之VLAN介绍
linux·服务器·网络·人工智能·ai
vx-程序开发3 小时前
基于机器学习的动漫可视化系统的设计与实现-计算机毕业设计源码08339
java·c++·spring boot·python·spring·django·php
imuliuliang4 小时前
Laravel6.x核心特性全解析
android·php·laravel
qq 13740186114 小时前
ISTA 2A-2011 (2022) 全解析|≤68kg 单个包装件部分模拟运输测试标准
网络·安全·安全性测试·ista·运输测试·运输包装
IT大白鼠4 小时前
Stuxnet病毒:改写战争形态的网络武器革命
安全·震网病毒
墨痕诉清风5 小时前
Web浏览器客户端检测网站网络健康(代码)
前端·网络·测试工具
ElevenS_it1885 小时前
Redis监控实战:内存使用+命中率+连接数三类核心指标接入Zabbix+分级告警完整配置方案
运维·网络·redis·mybatis·zabbix
财迅通Ai5 小时前
开拓药业KX-826:安全疗效构筑壁垒,机制互补卡位脱发新药黄金赛道
安全·开拓药业
oo哦哦6 小时前
搜索矩阵系统的最短路密码:用Dijkstra算法和网络流理论,解释为什么你做了1000个关键词,流量还不如别人30个
网络·算法·矩阵