单臂路由实验
实验拓扑图
实验需求
- 按照图示为 PC_3 和 PC_4 配置 IP 地址和网关
- PC_3 属于 Vlan10,PC_4 属于 Vlan20,配置单臂路由实现 Vlan10 和 Vlan20 三层互通
- PC_3 和 PC_4 可以互通
1.按照图示为 PC_3 和 PC_4 配置 IP 地址和网关
2.PC_3 属于 Vlan10,PC_4 属于 Vlan20,配置单臂路由实现 Vlan10 和 Vlan20 三层互通
分析:
用单臂路由实现 Vlan 间三层互通,需要把 SW1 连接 R2 的接口配置为 Trunk,并允许 Vlan10 和 Vlan20 通过
R2 连接 SW1 的接口上要开启子接口,分别作为 Vlan10 和 Vlan20 的网关。这里规划 g0/0.1 子接口作为 Vlan10 的网关,IP 地址就是192.168.1.254/24,g0/0.2 子接口作为 Vlan20 的网关,IP 地址就是192.168.2.254/24
R2 的子接口上为了能够识别 SW1的 Trunk 端口发送的 802.1Q 帧,还需要开启 dot1q 识别并绑定相应 Vlan。根据上述分析,g0/0.1 子接口绑定 Vlan10,g0/0.2 子接口绑定 Vlan20
(1)在 SW2 上创建 Vlan10 和 Vlan20,并把 g1/0/1 接口加入 Vlan10,把 g1/0/2 接口加入 Vlan20
[SW1]vlan 10
[SW1-vlan10]port g1/0/2
[SW1-vlan10]vlan 20
[SW1-vlan20]port g1/0/3
(2)把 SW2 的 g1/0/3 接口配置为 Trunk,并允许 Vlan10 和 Vlan20 通过
[SW1]int g1/0/1
[SW1-GigabitEthernet1/0/1]port link-type trunk
[SW1-GigabitEthernet1/0/1]port trunk permit vlan 10 20
查看g1/0/3接口是否被设置为Trunk
[SW1-GigabitEthernet1/0/1]dis th
#
interface GigabitEthernet1/0/1
port link-mode bridge
port link-type trunk
port trunk permit vlan 1 10 20
combo enable fiber
#
return
(3)在 R1 上创建子接口 g0/0.1,开启 dot1q 识别,绑定到 Vlan10,并配置 IP 地址 192.168.1.254/24
[R2]int g0/0.1
[R2-GigabitEthernet0/0.1]%Jul 21 17:12:16:083 2025 R2 IFNET/3/PHY_UPDOWN: Physical state on the interface GigabitEthernet0/0.1 changed to up.
%Jul 21 17:12:16:084 2025 R2 IFNET/5/LINK_UPDOWN: Line protocol state on the interface GigabitEthernet0/0.1 changed to up.
[R2-GigabitEthernet0/0.1]vlan-type dot1q vid 10
[R2-GigabitEthernet0/0.1]%Jul 21 17:12:33:344 2025 R2 IFNET/3/PHY_UPDOWN: Physical state on the interface GigabitEthernet0/0.1 changed to down.
%Jul 21 17:12:33:344 2025 R2 IFNET/5/LINK_UPDOWN: Line protocol state on the interface GigabitEthernet0/0.1 changed to down.
%Jul 21 17:12:33:344 2025 R2 IFNET/3/PHY_UPDOWN: Physical state on the interface GigabitEthernet0/0.1 changed to up.
%Jul 21 17:12:33:344 2025 R2 IFNET/5/LINK_UPDOWN: Line protocol state on the interface GigabitEthernet0/0.1 changed to up.
[R2-GigabitEthernet0/0.1]ip ad 192.168.1.254 24
(4)在 R1 上创建子接口 0/0.2,开启 dot1q 识别,绑定到 Vlan20,并配置 IP 地址192.168.2.254/24
[R2]int g0/0.2
[R2-GigabitEthernet0/0.2]%Jul 21 17:12:59:079 2025 R2 IFNET/3/PHY_UPDOWN: Physical state on the interface GigabitEthernet0/0.2 changed to up.
%Jul 21 17:12:59:079 2025 R2 IFNET/5/LINK_UPDOWN: Line protocol state on the interface GigabitEthernet0/0.2 changed to up.
[R2-GigabitEthernet0/0.2]vlan-type dot1q vid 20
[R2-GigabitEthernet0/0.2]%Jul 21 17:13:10:517 2025 R2 IFNET/3/PHY_UPDOWN: Physical state on the interface GigabitEthernet0/0.2 changed to down.
%Jul 21 17:13:10:517 2025 R2 IFNET/5/LINK_UPDOWN: Line protocol state on the interface GigabitEthernet0/0.2 changed to down.
%Jul 21 17:13:10:517 2025 R2 IFNET/3/PHY_UPDOWN: Physical state on the interface GigabitEthernet0/0.2 changed to up.
%Jul 21 17:13:10:518 2025 R2 IFNET/5/LINK_UPDOWN: Line protocol state on the interface GigabitEthernet0/0.2 changed to up.
[R2-GigabitEthernet0/0.2]ip ad 192.168.2.254 24
查看路由表
[R2]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 上查看路由表,会发现已经产生了到达192.168.1.0/24网段和192.168.2.0/24网段的直连路由,出接口分别指向各自子接口,证明路由器已经可以对 Vlan10 和 Vlan20 间的数据进行三层转发了
3.PC_3 和 PC_4 可以互通
PC3:
<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=8.113 ms
56 bytes from 192.168.2.1: icmp_seq=1 ttl=254 time=4.215 ms
56 bytes from 192.168.2.1: icmp_seq=2 ttl=254 time=5.246 ms
56 bytes from 192.168.2.1: icmp_seq=3 ttl=254 time=2.950 ms
56 bytes from 192.168.2.1: icmp_seq=4 ttl=254 time=4.914 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 = 2.950/5.088/8.113/1.705 ms
<H3C>%Jul 21 17:17:04:602 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 = 2.950/5.088/8.113/1.705 ms.
PC4:
<H3C>ping 192.168.1.1
Ping 192.168.1.1 (192.168.1.1): 56 data bytes, press CTRL_C to break
56 bytes from 192.168.1.1: icmp_seq=0 ttl=254 time=3.260 ms
56 bytes from 192.168.1.1: icmp_seq=1 ttl=254 time=4.228 ms
56 bytes from 192.168.1.1: icmp_seq=2 ttl=254 time=4.467 ms
56 bytes from 192.168.1.1: icmp_seq=3 ttl=254 time=3.068 ms
56 bytes from 192.168.1.1: icmp_seq=4 ttl=254 time=13.012 ms
--- Ping statistics for 192.168.1.1 ---
5 packet(s) transmitted, 5 packet(s) received, 0.0% packet loss
round-trip min/avg/max/std-dev = 3.068/5.607/13.012/3.741 ms
<H3C>%Jul 21 17:16:57:296 2025 H3C PING/6/PING_STATISTICS: Ping statistics for 192.168.1.1: 5 packet(s) transmitted, 5 packet(s) received, 0.0% packet loss, round-trip min/avg/max/std-dev = 3.068/5.607/13.012/3.741 ms.