计算机网络—VLAN 间路由配置

目录

1.拓扑图

2.实验环境准备

[3.为 R3 配置 IP 地址](#3.为 R3 配置 IP 地址)

[4.创建 VLAN](#4.创建 VLAN)

[5.配置 R2 上的子接口实现 VLAN 间路由](#5.配置 R2 上的子接口实现 VLAN 间路由)

6.配置文件


1.拓扑图

2.实验环境准备

配置R1、R3和S1的设备名称,并按照拓扑图配置R1的G0/0/1接口的IP地址。

复制代码
[Huawei]sysname R1
[R1]interface GigabitEthernet 0/0/1
[R1-GigabitEthernet0/0/1]ip address 10.0.4.1 24
<Huawei>system-view
Enter system view, return user view with Ctrl+Z. 
[Huawei]sysname R3
<Quidway>system-view
[Quidway]sysname S1

3.为 R3 配置 IP 地址

复制代码
[R3]interface GigabitEthernet 0/0/1
[R3-GigabitEthernet0/0/1]ip address 10.0.8.1 24

4.创建 VLAN

在S1上创建VLAN 4和VLAN 8,将端口G0/0/1加入到VLAN 4中,将端口 G0/0/3加入到VLAN 8中。

复制代码
[S1]vlan batch 4 8
Info: This operation may take a few seconds. Please wait for a moment...done.
[S1]interface GigabitEthernet 0/0/1
[S1-GigabitEthernet0/0/1]port link-type access
[S1-GigabitEthernet0/0/1]port default vlan 4
[S1-GigabitEthernet0/0/1]quit
[S1]interface GigabitEthernet0/0/3
[S1-GigabitEthernet0/0/3]port link-type access
[S1-GigabitEthernet0/0/3]port default vlan 8
[S1-GigabitEthernet0/0/3]quit

将S1连接R2路由器的G0/0/2端口配置为Trunk接口,并允许VLAN 4和 VLAN 8的报文通过。

复制代码
[S1]interface GigabitEthernet0/0/2
[S1-GigabitEthernet0/0/2]port link-type trunk
[S1-GigabitEthernet0/0/2]port trunk allow-pass vlan 4 8

5.配置 R2 上的子接口实现 VLAN 间路由

由于路由器只有一个实际的物理接口与交换机S1相连,而实际上不同部门 属于不同VLAN和不同网段,所以在路由器上配置不同的逻辑子接口来扮演不同 的网关角色,在R2上配置子接口G0/0/1.1和G0/0/1.3,并作为VLAN 4和VLAN 8的网关。

复制代码
<Huawei>system-view
Enter system view, return user view with Ctrl+Z. 
[Huawei]sysname R2
[R2]interface GigabitEthernet0/0/1.1
[R2-GigabitEthernet0/0/1.1]ip address 10.0.4.254 24
[R2-GigabitEthernet0/0/1.1]dot1q termination vid 4
[R2-GigabitEthernet0/0/1.1]arp broadcast enable
[R2-GigabitEthernet0/0/1.1]quit
[R2]interface GigabitEthernet0/0/1.3
[R2-GigabitEthernet0/0/1.3]ip address 10.0.8.254 24
[R2-GigabitEthernet0/0/1.3]dot1q termination vid 8
[R2-GigabitEthernet0/0/1.3]arp broadcast enable

在R1和R3上各配置一条默认路由指向各自的网关。

复制代码
[R1]ip route-static 0.0.0.0 0.0.0.0 10.0.4.254

[R3]ip route-static 0.0.0.0 0.0.0.0 10.0.8.254

配置完成后,检测R1与R3间的连通性。

复制代码
<R1>ping 10.0.8.1

[R2]display ip routing-table

10.0.4.0/24 Direct 0 0 D 10.0.4.254 GigabitEthernet0/0/1.1
10.0.8.0/24 Direct 0 0 D 10.0.8.254 GigabitEthernet0/0/1.3

6.配置文件

复制代码
[R1]display current-configuration
[V200R007C00SPC600]
#
sysname R1
#
interface GigabitEthernet0/0/1
ip address 10.0.4.1 255.255.255.0
#
ip route-static 0.0.0.0 0.0.0.0 10.0.4.254
#
return
[R2]display current-configuration
[V200R007C00SPC600]
#
sysname R2
#
interface GigabitEthernet0/0/1
#
interface GigabitEthernet0/0/1.1
dot1q termination vid 4
ip address 10.0.4.254 255.255.255.0
arp broadcast enable
#
interface GigabitEthernet0/0/1.3
dot1q termination vid 8
ip address 10.0.8.254 255.255.255.0
arp broadcast enable
#
return
[R3]display current-configuration
[V200R007C00SPC600]
#
sysname R3
#
interface GigabitEthernet0/0/1
ip address 10.0.8.1 255.255.255.0
#
ip route-static 0.0.0.0 0.0.0.0 10.0.8.254
#
return
[S1]display current-configuration
!Software Version V200R008C00SPC500
#
sysname S1
#
vlan batch 4 8
#
interface GigabitEthernet0/0/1
port link-type access
port default vlan 4
#
interface GigabitEthernet0/0/2
port link-type trunk
port trunk allow-pass vlan 4 8
#
interface GigabitEthernet0/0/3
port link-type access
port default vlan 8
#
return
相关推荐
andxe5 小时前
安科士 AndXe 技术博客:400G QSFP112 SR4 光模块|AI 算力与超算短距互联最优方案
网络·人工智能·光模块·光通信
shiyi.十一6 小时前
第2章:应用层 — 知识要点与架构
网络·计算机网络·架构
DFT计算杂谈7 小时前
无 Root 权限在 Tesla K80 零门槛部署 DeepSeek 大模型
linux·服务器·网络·数据库·机器学习
水境传感 李兆栋7 小时前
GNSS 位移监测站 :毫米级感知,筑牢安全监测防线
网络
中微极客9 小时前
2026主流AI Agent框架技术选型与性能对比
运维·网络·人工智能
猿的天空13 小时前
机器人双手迎来全栈训练系统:灵初智能EgoSteer让灵巧手无所不能
网络·人工智能·计算机·ai·程序员·机器人·编程
Xzaveir_77713 小时前
OPPO、vivo、荣耀号码认证:多终端拨测矩阵与异常复现
大数据·网络·科技·矩阵·产品经理·ai-native
wuqingshun31415913 小时前
从网络角度来看,用户从输入网址到网页显示,期间发生了什么?
网络
牛马工作号13 小时前
Zigbee 专业详解:从协议到排障
网络·物联网·安全
牛马工作号13 小时前
Wi‑Fi 完全指南:从 802.11 协议到 Wi‑Fi 7、AC+AP 与 Mesh 工程组网
网络·网络协议·智能路由器