本文基于172.16.0.0/16 内网规划,实现双核心交换机互为备份,整合 VLAN、MSTP、VRRP、Eth-Trunk、DHCP 中继、NAT outbound 等技术,满足 PC 自动获取 IP、内网互通、访问公网及 ISP 环回的全业务需求。
一、网络需求与规划
- 内网地址:172.16.0.0/16
- SW1、SW2 双核心互为备份
- 必用技术:VRRP、STP(MSTP)、VLAN、Eth-Trunk
- 所有 PC 通过 DHCP 获取 IP
- ISP 仅配置 IP,无其他策略
- 全网 PC 可互通、可访问 ISP 环回、可访问公网
基础 IP 规划
- VLAN2:172.16.2.0/24,网关虚拟 IP:172.16.2.254
- VLAN3:172.16.3.0/24,网关虚拟 IP:172.16.3.254
- AR1 与 ISP 互联:202.100.1.1/30
- ISP 环回:172.16.100.1
- DHCP Server:172.16.1.1(AR1)
二、核心配置(按顺序:VRRP → VLAN → MSTP → Eth-Trunk → DHCP → NAT)
1. VRRP 配置
vlan batch 2 3
# VLAN2 接口配置
interface Vlanif2 ip address 172.16.2.252 255.255.255.0
# VRID 1 虚拟网关
vrrp vrid 1 virtual-ip 172.16.2.254
# 优先级120,成为Master
vrrp vrid 1 priority 120
# 抢占延迟6秒
vrrp vrid 1 preempt-mode timer delay 6
# VLAN3 接口配置
interface Vlanif3 ip address 172.16.3.252 255.255.255.0
vrrp vrid 2 virtual-ip 172.16.3.254
Sw2相似
2.Eth-Trunk 配置
# SW1 配置
interface Eth-Trunk1
trunkport GigabitEthernet 0/0/1 0/0/2
port link-type trunk
port trunk allow-pass vlan all
SW2 配置与SW1一致
3. VLAN 配置
VLAN vlan batch 2 3
# PC接入口:Access类型
interfaceGigabitEthernet0/0/1
port link-type access
port default vlan 2
InterfaceGigabitEthernet0/0/2
port link-type access
port default vlan 3
# 交换机互联口:Trunk允许所有VLAN
interface GigabitEthernet0/0/3
port link-type trunk
port trunk allow-pass vlan all
interface GigabitEthernet0/0/4
port link-type trunk
port trunk allow-pass vlan all
interface GigabitEthernet0/0/5
port link-type trunk
port trunk allow-pass vlan all
此配置为sw3与sw4相似,sw1和sw2则全为trunk
4. MSTP 配置
# 开启MSTP
stp enable stp mode mstp
# 域配置
stp region-configuration
region-name a
instance 1 vlan 2
instance 2 vlan 3
active region-configuration
# 根桥优先级
stp instance 1 root primary
stp instance 2 root secondary
此为sw1配置与sw2相似
5. DHCP 配置
# 开启DHCP服务
dhcp enable
# VLAN2 地址池
ip pool VLAN2
gateway-list 172.16.2.254
network 172.16.2.0 mask 255.255.255.0
dns-list 8.8.8.8
# VLAN3 地址池
ip pool VLAN3
gateway-list 172.16.3.254
network 172.16.3.0 mask 255.255.255.0
dns-list 8.8.8.8
# 三层接口直接启用DHCP
interface Vlanif2
dhcp select global
interface Vlanif3
dhcp select global
6. NAT 配置
# AR1配置
acl number 2000
rule permit source 172.16.0.0 0.0.255.255
# 出接口 IP
interface GigabitEthernet0/0/0
ip address 202.100.1.1 255.255.255.252
nat outbound 2000
四、验证结果
- PC 可自动获取 IP:172.16.2.0/24、172.16.3.0/24 段
- 内网跨 VLAN 互通正常
- 可 ping 通 ISP 环回 172.16.100.1
- 可 ping 通公网 8.8.8.8,0 丢包
- MSTP、VRRP、Eth-Trunk 均正常协商,主备切换生效