三层交换机实现PC互通方案

目标是实现 3台路由器(实际应为2台三层交换机 + 1台物理路由器)与3台PC


✅ 一、网络拓扑结构梳理

设备组成:

类型 数量 说明
三层交换机(支持路由+VLAN) 2 台 SW1、SW2(作为网关,运行VRRP)
二层交换机(仅转发) 5 台 其中:3个用于接入用户设备(如PC),2个用于连接交换机或扩展链路
PC(终端) 3 台 分别接入不同VLAN
路由器(物理) 1 台(可选) 若无特殊要求,可不需额外物理路由器

⚠️ 注意:题目说"3个路由器",但根据配置内容看,实际是 两台三层交换机(SW1/SW2)充当网关角色 ,可能误将"三层交换机"称为"路由器"。

所以我们按 2台三层交换机 + 5台二层交换机 + 3台PC 来理解。


✅ 二、网络规划概览

🌐 VLAN 划分(共7个)

VLAN ID 用途 网段 网关(虚拟)
10 用户1 192.168.10.0/24 192.168.10.254
20 用户2 192.168.20.0/24 192.168.20.254
30 用户3 192.168.30.0/24 192.168.30.254
40 用户4 192.168.40.0/24 192.168.40.254
50 用户5 192.168.50.0/24 192.168.50.254
60 用户6 192.168.60.0/24 192.168.60.254
100 链路管理/互联 192.168.100.0/30 192.168.100.10 / 192.168.100.101

💡 注:192.168.100.0/30 是点对点链路,只用两个地址:

  • 192.168.100.10(SW2)
  • 192.168.100.101(SW1)

✅ 三、设备角色定义

设备 角色 说明
SW1 核心三层交换机(主网关) 运行 VRRP,优先级高(120),负责部分VLAN的主网关
SW2 核心三层交换机(备网关) 运行 VRRP,优先级默认(100),作为备份
其他5台二层交换机 接入层交换机 仅做接入,不参与路由
3台PC 终端主机 分属不同VLAN,需配置对应网关

✅ 四、详细配置整理(按设备)


🔹 1. 通用配置(所有交换机)

bash 复制代码
# 创建VLAN
vlan batch 10 20 30 40 50 60 100

# 关闭接口自动协商(可选,建议统一设置)
interface GigabitEthernet0/0/1
 undo negotiation auto
 speed 100
 duplex full

🔹 2. SW1 配置(主网关)

bash 复制代码
# 配置各VLAN IP地址(作为网关)
interface Vlanif10
 ip address 192.168.10.252 255.255.255.0

interface Vlanif20
 ip address 192.168.20.252 255.255.255.0

interface Vlanif30
 ip address 192.168.30.252 255.255.255.0

interface Vlanif40
 ip address 192.168.40.252 255.255.255.0

interface Vlanif50
 ip address 192.168.50.252 255.255.255.0

interface Vlanif60
 ip address 192.168.60.252 255.255.255.0

interface Vlanif100
 ip address 192.168.100.101 255.255.255.252

# 启用VRRP(虚拟网关)
interface Vlanif10
 vrrp vrid 10 virtual-ip 192.168.10.254
 vrrp vrid 10 priority 120

interface Vlanif20
 vrrp vrid 20 virtual-ip 192.168.20.254
 vrrp vrid 20 priority 120

interface Vlanif30
 vrrp vrid 30 virtual-ip 192.168.30.254
 vrrp vrid 30 priority 120

interface Vlanif40
 vrrp vrid 40 virtual-ip 192.168.40.254
 vrrp vrid 40 priority 120

interface Vlanif50
 vrrp vrid 50 virtual-ip 192.168.50.254
 vrrp vrid 50 priority 120

interface Vlanif60
 vrrp vrid 60 virtual-ip 192.168.60.254
 vrrp vrid 60 priority 120

# 上行口:连接到另一台交换机(如SW2)
interface GigabitEthernet0/0/1
 port link-type access
 port default vlan 100

interface GigabitEthernet0/0/2
 port link-type trunk
 port trunk allow-pass vlan 10 20 30 40 50 60 100

interface GigabitEthernet0/0/23
 port link-type trunk
 port trunk allow-pass vlan 10 20 30 40 50 60 100

interface GigabitEthernet0/0/24
 port link-type trunk
 port trunk allow-pass vlan 10 20 30 40 50 60 100

# STP配置(根桥)
stp instance 1 root primary
stp instance 2 root primary

stp region-configuration
 region-name 2025HB
 revision-level 2
 instance 1 vlan 10 20 30
 instance 2 vlan 40 50 60
 active region-configuration

🔹 3. SW2 配置(备用网关)

bash 复制代码
# 配置各VLAN IP地址
interface Vlanif10
 ip address 192.168.10.253 255.255.255.0

interface Vlanif20
 ip address 192.168.20.253 255.255.255.0

interface Vlanif30
 ip address 192.168.30.253 255.255.255.0

interface Vlanif40
 ip address 192.168.40.253 255.255.255.0

interface Vlanif50
 ip address 192.168.50.253 255.255.255.0

interface Vlanif60
 ip address 192.168.60.253 255.255.255.0

interface Vlanif100
 ip address 192.168.100.10 255.255.255.252

# 启用VRRP(从站)
interface Vlanif10
 vrrp vrid 10 virtual-ip 192.168.10.254

interface Vlanif20
 vrrp vrid 20 virtual-ip 192.168.20.254

interface Vlanif30
 vrrp vrid 30 virtual-ip 192.168.30.254

interface Vlanif40
 vrrp vrid 40 virtual-ip 192.168.40.254

interface Vlanif50
 vrrp vrid 50 virtual-ip 192.168.50.254

interface Vlanif60
 vrrp vrid 60 virtual-ip 192.168.60.254

# 下行口:连接到其他交换机或接入层
interface GigabitEthernet0/0/1
 port link-type access
 port default vlan 100

interface GigabitEthernet0/0/2
 port link-type trunk
 port trunk allow-pass vlan 10 20 30 40 50 60 100

# STP配置(非根桥)
stp instance 1 root secondary
stp instance 2 root secondary

stp region-configuration
 region-name 2025HB
 revision-level 2
 instance 1 vlan 10 20 30
 instance 2 vlan 40 50 60
 active region-configuration

🔹 4. 二层交换机配置(示例:接入层)

假设共有5台二层交换机,每台连接若干终端(例如1~2台PC)。以下为典型接入交换机配置模板:

bash 复制代码
# 创建VLAN
vlan batch 10 20 30 40 50 60

# 接入口配置(连接PC)
interface GigabitEthernet0/0/1
 port link-type access
 port default vlan 10   # 比如连接的是属于VLAN10的PC

interface GigabitEthernet0/0/2
 port link-type access
 port default vlan 20

# 上行口(连接上层交换机)
interface GigabitEthernet0/0/24
 port link-type trunk
 port trunk allow-pass vlan 10 20 30 40 50 60 100

# (可选)关闭广播风暴
undo port link-flap detect

✅ 提示:每个接入交换机根据实际需要分配VLAN,比如:

  • 一台接PC1(VLAN10)
  • 一台接PC2(VLAN20)
  • 一台接PC3(VLAN30)
  • 其余用于扩展链路或连接其他交换机。

🔹 5. 3台PC 的配置建议(静态或DHCP)

PC VLAN IP 地址 子网掩码 网关
PC1 VLAN10 192.168.10.10 255.255.255.0 192.168.10.254
PC2 VLAN20 192.168.20.10 255.255.255.0 192.168.20.254
PC3 VLAN30 192.168.30.10 255.255.255.0 192.168.30.254

✅ 可通过 DHCP 服务器自动分配,但需在三层交换机上启用 DHCP 服务(若未启用则手动配置)。


✅ 五、关键功能验证清单

功能 是否完成 说明
所有VLAN创建 vlan batch 已执行
三层交换机配置网关 各VLAN IF已配置IP
VRRP双机热备 主备切换正常,虚拟网关可达
Trunk链路允许所有VLAN port trunk allow-pass vlan all
STP防环 区域配置 + 根桥选举
PC间互通 通过三层交换机路由,跨VLAN通信成功
链路冗余 通过VRRP + STP 实现

✅ 六、常见问题 & 建议

  1. 错误提示:vrrp vrid 20 virtual-ip 192.168.10.254 写重复?

    应该是笔误,一个VLAN只能有一个虚拟网关。请删除重复项。

  2. 是否需要物理路由器?

    不需要!两台三层交换机已具备路由能力,可替代路由器。

  3. 如何测试PC通信?


✅ 总结:最终目标达成

3台PC可在不同VLAN中互相通信

使用两台三层交换机实现高可用网关(VRRP)

通过5台二层交换机灵活扩展接入

全网无环路(STP保护)

配置规范、易于维护


相关推荐
yuegu7771 小时前
HarmonyOS应用<节气通>开发第18篇:关于页面与隐私政策
华为·harmonyos
Zhu7581 小时前
Docker环境部署Apache Hadoop3.1定制版
运维·docker·容器
风华圆舞1 小时前
Flutter 项目接入 HarmonyOS 的完整工程结构解析
flutter·华为·harmonyos
梦想的旅途21 小时前
企业微信 Webhook 回调系统的工程化实践
网络·架构·自动化·企业微信
知识分享小能手1 小时前
Hadoop学习教程,从入门到精通, HDFS分布式文件系统 — 完整知识点与案例代码(3)
hadoop·学习·hdfs
●VON1 小时前
AtomGit Flutter鸿蒙客户端:通知系统
flutter·华为·跨平台·harmonyos·鸿蒙
星恒随风1 小时前
C++ 类和对象入门(四):日期类 Date 的运算符重载实现详解
开发语言·c++·笔记·学习
小此方2 小时前
Re:Linux系统篇(二十九)文件篇·二:深度解析Linux文件描述符、dup2指针覆盖与内建命令重定向完全解析
linux·运维·驱动开发
Cosolar5 小时前
LlamaIndex索引类型全解析:原理与实战指南
运维·服务器