单臂路由实验
单臂路由实验
文章目录
- 单臂路由实验
- 单臂路由简介
- 工作原理
- 优点与缺点
- 应用场景
- 实验拓扑
- 实验需求:
- 实验步骤:
- 1.PC 配置 IP 地址
- 2.PC3 属于 Vlan10,PC4 属于 Vlan20,配置单臂路由实现 Vlan10 和 Vlan20 三层互通
- 2.1.在 SW2 上创建 Vlan10 和 Vlan20,并把 g1/0/1 接口加入 Vlan10,把 g1/0/2 接口加入 Vlan20;把 SW2 的 g1/0/3 接口配置为 Trunk,并允许 Vlan10 和 Vlan20 通过;
- 2.2.在 R1 上创建子接口 g0/0.1,开启 dot1q 识别,绑定到 Vlan10,并配置 IP 地址 `192.168.1.254/24`;在 R1 上创建子接口 0/0.2,开启 dot1q 识别,绑定到 Vlan20,并配置 IP 地址`192.168.2.254/24`
- 2.3.在 R1 上查看路由表,会发现已经产生了到达192.168.1.0/24网段和192.168.2.0/24网段的直连路由,出接口分别指向各自子接口,证明路由器已经可以对 Vlan10 和 Vlan20 间的数据进行三层转发了
- 3.测试在 PC3 上 Ping PC4 ,可以 Ping 通 PC4
单臂路由简介
单臂路由(Router-on-a-Stick) 是一种在网络交换机上通过单个物理接口实现多个VLAN间路由的技术。它通过在一个物理接口上配置多个子接口(Sub-Interface),每个子接口关联一个VLAN,从而在有限硬件条件下实现跨VLAN通信。
工作原理
-
网络拓扑
- 交换机与路由器通过单个物理接口连接(如
GigabitEthernet0/1
)。 - 交换机上划分多个VLAN(如VLAN 10、VLAN 20),并将连接路由器的接口配置为 Trunk 模式,允许不同VLAN的流量通过。
- 交换机与路由器通过单个物理接口连接(如
-
子接口配置
-
在路由器的物理接口上创建多个逻辑子接口(如
GigabitEthernet0/1.10
、GigabitEthernet0/1.20
)。 -
每个子接口配置不同的IP地址,并关联对应的VLAN ID:
BASHinterface GigabitEthernet0/1.10 encapsulation dot1Q 10 ! 关联 VLAN 10 ip address 192.168.10.1 255.255.255.0 interface GigabitEthernet0/1.20 encapsulation dot1Q 20 ! 关联 VLAN 20 ip address 192.168.20.1 255.255.255.0
-
-
数据转发流程
- 当VLAN 10的主机(192.168.10.2)需要与VLAN 20的主机(192.168.20.2)通信时:
- 交换机将VLAN 10的流量通过Trunk链路发送至路由器子接口
GigabitEthernet0/1.10
。 - 路由器根据目标IP地址查路由表,将流量从子接口
GigabitEthernet0/1.20
转发回交换机。 - 交换机将流量送达VLAN 20的主机。
- 交换机将VLAN 10的流量通过Trunk链路发送至路由器子接口
- 当VLAN 10的主机(192.168.10.2)需要与VLAN 20的主机(192.168.20.2)通信时:
优点与缺点
优点 | 缺点 |
---|---|
1. 节省硬件成本:仅需一个路由器接口实现多VLAN互联。 | 1. 性能瓶颈:所有跨VLAN流量集中在一个物理接口,易成为带宽瓶颈。 |
2. 灵活扩展:支持动态增减VLAN,适应中小型网络需求。 | 2. 配置复杂度:需同时配置交换机的Trunk和路由器的子接口。 |
3. 兼容性高:适用于多数支持VLAN和802.1Q协议的设备。 | 3. 单点故障:路由器或Trunk链路故障会导致所有VLAN间通信中断。 |
应用场景
- 小型企业网络
- 在预算有限的情况下,通过单台路由器实现多个部门(VLAN)的互联。
- 实验室环境
- 用于教学或测试跨VLAN路由功能,无需复杂的三层交换机。
- 临时网络部署
- 快速搭建多VLAN网络,如展会或临时办公场景。
实验拓扑
实验需求:
- 按照图示为 PC3 和 PC4 配置 IP 地址和网关
- PC3 属于 Vlan10,PC4 属于 Vlan20,配置单臂路由实现 Vlan10 和 Vlan20 三层互通
- PC3 和 PC4 可以互通
实验步骤:
1.PC 配置 IP 地址
pc3
pc4
2.PC3 属于 Vlan10,PC4 属于 Vlan20,配置单臂路由实现 Vlan10 和 Vlan20 三层互通
2.1.在 SW2 上创建 Vlan10 和 Vlan20,并把 g1/0/1 接口加入 Vlan10,把 g1/0/2 接口加入 Vlan20;把 SW2 的 g1/0/3 接口配置为 Trunk,并允许 Vlan10 和 Vlan20 通过;
注:利用单臂路由实现 vlan 间三层互通,需要把 SW1 连接 R1 的接口配置为 Trunk,并允许 vlan10 和 vlan20 通过 R1 连接 SW2 的接口上要开启子接口,分别作为 vlan10 和 vlan20 的网关。这里规划 g0/0.1 子接口作为 Vlan10 的网关,IP 地址就是192.168.1.254/24,g0/0.2 子接口作为 Vlan20 的网关,IP 地址就是192.168.2.254/24 R1 的子接口上为了能够识别 SW2 的 Trunk 端口发送的 802.1Q 帧,还需要开启 dot1q 识别并绑定相应 Vlan。根据上述分析,g0/0.1 子接口绑定 Vlan10,g0/0.2 子接口绑定 Vlan20
在SW1上
<H3C>system-view
System View: return to User View with Ctrl+Z.
[H3C]sysn
[H3C]sysname SW1
[SW1]vlan 10
[SW1-vlan10]port g1/0/1
[SW1-vlan10]vlan 20
[SW1-vlan20]port g1/0/2
[SW1-vlan20]int g1/0/3
[SW1-GigabitEthernet1/0/3]port link-type trunk
[SW1-GigabitEthernet1/0/3]port trunk permit vlan 10 20
[SW1-GigabitEthernet1/0/3]display this
#
interface GigabitEthernet1/0/3
port link-mode bridge
port link-type trunk
port trunk permit vlan 1 10 20
combo enable fiber
#
return
[SW1-GigabitEthernet1/0/3]
2.2.在 R1 上创建子接口 g0/0.1,开启 dot1q 识别,绑定到 Vlan10,并配置 IP 地址 192.168.1.254/24
;在 R1 上创建子接口 0/0.2,开启 dot1q 识别,绑定到 Vlan20,并配置 IP 地址192.168.2.254/24
在R1上
<H3C>system-view
System View: return to User View with Ctrl+Z.
[H3C]sysn
[H3C]sysname R1
[R1]int
[R1]interface g0/0.1
[R1-GigabitEthernet0/0.1]%Mar 21 16:05:21:643 2025 R1 IFNET/3/PHY_UPDOWN: Physical state on the interface GigabitEthernet0/0.1 changed to up.
%Mar 21 16:05:21:643 2025 R1 IFNET/5/LINK_UPDOWN: Line protocol state on the interface GigabitEthernet0/0.1 changed to up.
[R1-GigabitEthernet0/0.1]vlan-type dot
[R1-GigabitEthernet0/0.1]vlan-type dot1q vid 10
[R1-GigabitEthernet0/0.1]%Mar 21 16:05:33:865 2025 R1 IFNET/3/PHY_UPDOWN: Physical state on the interface GigabitEthernet0/0.1 changed to down.
%Mar 21 16:05:33:865 2025 R1 IFNET/5/LINK_UPDOWN: Line protocol state on the interface GigabitEthernet0/0.1 changed to down.
%Mar 21 16:05:33:865 2025 R1 IFNET/3/PHY_UPDOWN: Physical state on the interface GigabitEthernet0/0.1 changed to up.
%Mar 21 16:05:33:865 2025 R1 IFNET/5/LINK_UPDOWN: Line protocol state on the interface GigabitEthernet0/0.1 changed to up.
[R1-GigabitEthernet0/0.1]ip address 192.168.1.254 24
[R1-GigabitEthernet0/0.1]qu
[R1]interface g0/0.2
[R1-GigabitEthernet0/0.2]%Mar 21 16:05:42:587 2025 R1 IFNET/3/PHY_UPDOWN: Physical state on the interface GigabitEthernet0/0.2 changed to up.
%Mar 21 16:05:42:587 2025 R1 IFNET/5/LINK_UPDOWN: Line protocol state on the interface GigabitEthernet0/0.2 changed to up.
[R1-GigabitEthernet0/0.2]vlan-type dot1q vid 20
[R1-GigabitEthernet0/0.2]%Mar 21 16:05:48:334 2025 R1 IFNET/3/PHY_UPDOWN: Physical state on the interface GigabitEthernet0/0.2 changed to down.
%Mar 21 16:05:48:334 2025 R1 IFNET/5/LINK_UPDOWN: Line protocol state on the interface GigabitEthernet0/0.2 changed to down.
%Mar 21 16:05:48:335 2025 R1 IFNET/3/PHY_UPDOWN: Physical state on the interface GigabitEthernet0/0.2 changed to up.
%Mar 21 16:05:48:335 2025 R1 IFNET/5/LINK_UPDOWN: Line protocol state on the interface GigabitEthernet0/0.2 changed to up.
[R1-GigabitEthernet0/0.1]ip address 192.168.1.254 24
[R1-GigabitEthernet0/0.1]display ip interface brief
*down: administratively down
(s): spoofing (l): loopback
Interface Physical Protocol IP address/Mask VPN instance Description
GE0/0 up up -- -- --
GE0/0.1 up up 192.168.1.254/24 -- --
GE0/0.2 up up 192.168.2.254/24 -- --
GE0/1 down down -- -- --
GE0/2 down down -- -- --
GE5/0 down down -- -- --
GE5/1 down down -- -- --
GE6/0 down down -- -- --
GE6/1 down down -- -- --
Ser1/0 down down -- -- --
Ser2/0 down down -- -- --
Ser3/0 down down -- -- --
Ser4/0 down down -- -- --
[R1-GigabitEthernet0/0.1]
2.3.在 R1 上查看路由表,会发现已经产生了到达192.168.1.0/24网段和192.168.2.0/24网段的直连路由,出接口分别指向各自子接口,证明路由器已经可以对 Vlan10 和 Vlan20 间的数据进行三层转发了
在R1上
[R1]display ip routing-table
Destinations : 13 Routes : 13
Destination/Mask Proto Pre Cost NextHop Interface
0.0.0.0/32 Direct 0 0 127.0.0.1 InLoop0
127.0.0.0/8 Direct 0 0 127.0.0.1 InLoop0
127.0.0.1/32 Direct 0 0 127.0.0.1 InLoop0
127.255.255.255/32 Direct 0 0 127.0.0.1 InLoop0
192.168.1.0/24 Direct 0 0 192.168.1.254 GE0/0.1 **
192.168.1.254/32 Direct 0 0 127.0.0.1 InLoop0
192.168.1.255/32 Direct 0 0 192.168.1.254 GE0/0.1
192.168.2.0/24 Direct 0 0 192.168.2.254 GE0/0.2 **
192.168.2.254/32 Direct 0 0 127.0.0.1 InLoop0
192.168.2.255/32 Direct 0 0 192.168.2.254 GE0/0.2
224.0.0.0/4 Direct 0 0 0.0.0.0 NULL0
224.0.0.0/24 Direct 0 0 0.0.0.0 NULL0
255.255.255.255/32 Direct 0 0 127.0.0.1 InLoop0
[R1]
3.测试在 PC3 上 Ping PC4 ,可以 Ping 通 PC4
<H3C>ping 192.168.2.1
Ping 192.168.2.1 (192.168.2.1): 56 data bytes, press CTRL_C to break
56 bytes from 192.168.2.1: icmp_seq=0 ttl=254 time=2.594 ms
56 bytes from 192.168.2.1: icmp_seq=1 ttl=254 time=0.969 ms
56 bytes from 192.168.2.1: icmp_seq=2 ttl=254 time=1.074 ms
56 bytes from 192.168.2.1: icmp_seq=3 ttl=254 time=1.313 ms
56 bytes from 192.168.2.1: icmp_seq=4 ttl=254 time=0.842 ms
--- Ping statistics for 192.168.2.1 ---
5 packet(s) transmitted, 5 packet(s) received, 0.0% packet loss
round-trip min/avg/max/std-dev = 0.842/1.358/2.594/0.637 ms
<H3C>%Mar 21 16:09:48:440 2025 H3C PING/6/PING_STATISTICS: Ping statistics for 192.168.2.1: 5 packet(s) transmitted, 5 packet(s) received, 0.0% packet loss, round-trip min/avg/max/std-dev = 0.842/1.358/2.594/0.637 ms.
测试成功