一、实验拓扑
二、概述解释
前面我们学到VLAN,我们知道,同一VLAN的计算机之间是可以进行二层通信的,而不同VLAN的计算机是无法进行通信的。
虽然,不同VLAN不能通信,但并不代表就没办法通信,只不过他们通信的不是在二层,而是在三层通信。
这里就来学习一种方法,使不同VLAN之间通信,叫:单臂路由。
单臂路由(router-on-a-stick)是指在路由器的一个接口上通过配置子接口(或“逻辑接口”,并不存在真正物理接口)的方式,实现原来相互隔离的不同VLAN之间的互联互通。
三、实验
按照上面的拓扑,我们先来配置SW1和SW2
SW1:
[SW1]vlan batch 10 20
#创建VLAN
[SW1]interface g0/0/1
[SW1-GigabitEthernet0/0/1]port link-type a
[SW1-GigabitEthernet0/0/1]port link-type access
[SW1-GigabitEthernet0/0/1]port
[SW1-GigabitEthernet0/0/1]port de
[SW1-GigabitEthernet0/0/1]port default v
[SW1-GigabitEthernet0/0/1]port default vlan 10
[SW1-GigabitEthernet0/0/1]q
#将端口加入VLAN 10
[SW1]int g0/0/2
[SW1-GigabitEthernet0/0/2]port link-type a
[SW1-GigabitEthernet0/0/2]port link-type access
[SW1-GigabitEthernet0/0/2]port default v
[SW1-GigabitEthernet0/0/2]port default vlan 20
[SW1-GigabitEthernet0/0/2]q
#将端口加入VLAN 20
[SW1]int g0/0/10
[SW1-GigabitEthernet0/0/10]port li
[SW1-GigabitEthernet0/0/10]port link-type tr
[SW1-GigabitEthernet0/0/10]port link-type trunk
[SW1-GigabitEthernet0/0/10]port
[SW1-GigabitEthernet0/0/10]port trunk allow-pass v
[SW1-GigabitEthernet0/0/10]port trunk allow-pass vlan all
[SW1-GigabitEthernet0/0/10]q
#交换机之间创建 Trunk端口 并放通vlan
SW2:
[SW2]vlan10
[SW2-vlan10]Q
[SW2]V
[SW2]vlan 20
[SW2-vlan20]
#创建VLAN
[SW2]
[SW2]int g0/0/1
[SW2-GigabitEthernet0/0/1]port li
[SW2-GigabitEthernet0/0/1]port link-t
[SW2-GigabitEthernet0/0/1]port link-type a
[SW2-GigabitEthernet0/0/1]port link-type access
[SW2-GigabitEthernet0/0/1]port de
[SW2-GigabitEthernet0/0/1]port default vlan 10
[SW2-GigabitEthernet0/0/1]q
#将端口加入vlan 10
[SW2]int g0/0/2
[SW2-GigabitEthernet0/0/2]por
[SW2-GigabitEthernet0/0/2]port l
[SW2-GigabitEthernet0/0/2]port link-type ac
[SW2-GigabitEthernet0/0/2]port link-type access
[SW2-GigabitEthernet0/0/2]p
[SW2-GigabitEthernet0/0/2]port default vlan 20
[SW2-GigabitEthernet0/0/2]
#将端口加入vlan 20
[SW2]int g0/0/10
[SW2-GigabitEthernet0/0/10]port link-type tr
[SW2-GigabitEthernet0/0/10]port link-type trunk
[SW2-GigabitEthernet0/0/10]port trunk allow-pass vlan all
#开启trunk
下面,需要在SW1上,对G0/0/11口进行设置,由于需要为vlan 10 20服务,所以接口必须为Trunk,并且必须允许vlan 10 20通过,做到精细放行。如果不精细放行,否则vlan 过多,将会导致路由器压力过大。
[SW1]int g0/0/11
[SW1-GigabitEthernet0/0/11]port link-type trunk
[SW1-GigabitEthernet0/0/11]port trunk all
[SW1-GigabitEthernet0/0/11]port trunk allow-pass v
[SW1-GigabitEthernet0/0/11]port trunk allow-pass vlan 10 20
[SW1-GigabitEthernet0/0/11]di this
#
interface GigabitEthernet0/0/11
port link-type trunk
port trunk allow-pass vlan 10 20
#
return
接下来对路由器进行配置:
做单臂路由,必须要配置子接口
vlan 10
[AR1]int
[AR1]interface g0/0/0.?
<1-4096> GigabitEthernet interface subinterface number
#这里可以看到,子接口的号码可以随便设置,只要在这个范围内都可。
[AR1]interface g0/0/0.10
#我这里就按照拓扑的vlan 号来设置
[AR1-GigabitEthernet0/0/0.10]do
[AR1-GigabitEthernet0/0/0.10]dot1q te
[AR1-GigabitEthernet0/0/0.10]dot1q termination vid 10
#配置VID
[AR1-GigabitEthernet0/0/0.10]arp
[AR1-GigabitEthernet0/0/0.10]arp br
[AR1-GigabitEthernet0/0/0.10]arp broadcast en
[AR1-GigabitEthernet0/0/0.10]arp broadcast enable
#arp broadcast 功能打开 ,在里面配置ip地址
[AR1-GigabitEthernet0/0/0.10]ip add 10.1.10.254 24
#配置IP
May 25 2022 00:22:42-08:00 AR1 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP
on the interface GigabitEthernet0/0/0.10 has entered the UP state.
[AR1-GigabitEthernet0/0/0.10]q
vlan 20
[AR1]int g0/0/0.20
[AR1-GigabitEthernet0/0/0.20]dot
[AR1-GigabitEthernet0/0/0.20]dot1q te
[AR1-GigabitEthernet0/0/0.20]dot1q termination v
[AR1-GigabitEthernet0/0/0.20]dot1q termination vid 20
[AR1-GigabitEthernet0/0/0.20]arp
[AR1-GigabitEthernet0/0/0.20]arp br
[AR1-GigabitEthernet0/0/0.20]arp broadcast en
[AR1-GigabitEthernet0/0/0.20]ip add 10.1.20.254 24
May 25 2022 00:23:49-08:00 AR1 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP
on the interface GigabitEthernet0/0/0.20 has entered the UP state.
[AR1-GigabitEthernet0/0/0.20]
[AR1-GigabitEthernet0/0/0.20]
[AR1-GigabitEthernet0/0/0.20]
[AR1-GigabitEthernet0/0/0.20]q
配置完成,我们查看一下路由表
[AR1]dis ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 10 Routes : 10
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.1.10.0/24 Direct 0 0 D 10.1.10.254 GigabitEthernet
0/0/0.10
10.1.10.254/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0.10
10.1.10.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0.10
10.1.20.0/24 Direct 0 0 D 10.1.20.254 GigabitEthernet
0/0/0.20
10.1.20.254/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0.20
10.1.20.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0.20
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
我们可以看到刚才配置的子接口 直连路由。
四、PC测试互通性