了解VLAN间路由
作为一名网络管理员,任务可能包括必须从逻辑上分割一个单一的交换式局域网(LAN),而不必铺设新的电缆和改变现有的网络。VLAN "的概念及其配置将帮助人们轻松地处理手头的任务。
在本文中,我们将了解什么是VLAN间路由,VLAN路由的各种方法,还将建立一个网络配置来了解它的工作原理。
前提条件
作为先决条件,读者必须对基本的网络概念有很好的理解,以及如何使用思科数据包追踪器。
VLAN路由术语
VLAN是交换式局域网上的一个网段,它将网络上的主机从逻辑上组合在一起,而不管它们在网络上的物理位置。Local Area Network (LAN)是在一个小的地理区域内网络设备的物理互连。Layer 3 switch/multilayer switch是一种特殊类型的交换机,它同时执行OSI模型第2层的交换机和第3层的路由器的功能,即它可以转发帧和数据包。Switched Virtual Interface (SVI)是指一个虚拟接口,将网络设备上的VLAN连接到其各自的路由器引擎。Default Gateway是指转发IP数据包的设备,并为其他网络提供一个接入点。例如,一个路由器。Access Point是一种网络设备,连接到路由器或交换机,创建一个无线局域网,并作为路由器和网络用户之间的链接。Switch port指交换机或路由器上可以插入以太网电缆的一个物理开口。Router Interface指的是使路由器连接到网络的路径。
什么是VLAN间路由?
虚拟局域网(VLANS )是交换式局域网上的网络段。VLAN间路由是指不同网段的主机之间的数据包在网络上的移动。
VLANs VLANs使人们更容易对网络进行分段,这反过来又提高了网络的性能,使其更加灵活,因为它们是逻辑连接。
VLAN作为网络上的独立子网。为了将数据包从一个VLAN转移到另一个VLAN,并实现主机之间的通信,我们必须配置VLAN网络。
VLAN间的路由方法
传统的VLAN间路由
在这种方法中,使用多个路由器接口,每个接口连接到不同VLAN的交换机端口。这些接口作为默认网关,当网络需要扩展时,需要增加网线。
因此,增加额外的网线和改善基础设施是比较昂贵的。
棍子上的路由器
在这种方法中,与传统的路由不同,一个物理接口端口被用来在网段之间路由流量。网络管理员不需要创建单独的VLAN接口,如fa0/1 到fa0/10 。
相反,从1到10的所有接口都是用一个接口创建的。这种方法实施起来很简单,用于中小型网络。
使用交换式虚拟接口(SVI)的第3层交换机
目前,这种使用第三层/多层交换机和交换虚拟接口(SVI)的VLAN间路由方法是最受欢迎的。
SVI是为VLAN创建的,它存在于交换机上,为VLAN执行与路由器相同的功能。
第三层交换机很昂贵,主要适用于大型组织网络。
使用Router-On-Stick方法进行VLAN间通信的网络配置
在这篇文章中,我们将学习如何使用Router-on-a-Stick方法配置VLAN间的路由。
考虑一个有4台PC、1台交换机和一台路由器的局域网,如图所示。

现在,我们要配置两个VLAN 10和20,PC0和PC1在VLAN10,PC2和PC3在VLAN20。
- PC0的IP地址 - 192.168.1.10
- PC1的IP地址 - 192.168.1.20
- PC2的IP地址 - 192.168.2.10
- PC3的IP地址 - 192.168.2.20
- VLAN10的默认网关 - 192.168.1.1
- VLAN20的默认网关 - 192.168.2.1
第1步
为了将网络细分为两个子网,我们必须在交换机上创建两个VLANS,VLAN10 和VLAN20 。给它们起一个自定义的名字,如VLAN 10 - student 和VLAN 20 - staff 。
为了创建两个VLAN,我们使用config terminal 命令进入配置模式,然后输入VLAN编号,如vlan 10 ,同时输入名称。
Switch>enable !moving from user exec mode to priviledge mode
Switch#config terminal !moving from priviledge mode to global configuration mode
Switch(config)#vlan 10 !assigning vlan number
Switch(config-vlan)#name student !assigns the vlan 10 the name student
Switch(config-vlan)#exit
Switch(config)#vlan 20
Switch(config-vlan)#name staff !assigns vlan 20 the name staff
Switch(config-vlan)#exit
第2步
将交换机端口分配给VLANS。端口fa0/1和fa0/2 作为VLAN10 的访问端口,而端口fa0/3 和fa0/4 作为VLAN20 的访问端口。
我们将使用fa0/5 端口作为中继端口,通过路由器在两个VLANS之间传输流量。
注意: fa 是指用于连接网络主机和交换机或路由器的快速以太网端口。
接入端口fa0/1和fa0/2的配置
Switch>enable !moving from user exec mode to the priviledge mode
Switch#config terminal !moving from priviledge mode to the global configuration mode
Switch(config)#int fa 0/1 !entering the interface port
Switch(config-if)#switchport mode access !making the interface fa0/1 an access port
Switch(config-if)#switchport access vlan 10 !making interface access port for vlan 10
Switch(config-if)#exit !exiting from the interface
Switch(config)#int fa 0/2 !entering the interface port
Switch(config-if)#switchport mode access !making the interface fa0/2 an access port
Switch(config-if)#switchport access vlan 10 !making interface access port for vlan 10
Switch(config-if)#exit !exiting from the interface
在上面的配置中,fa0/1 和fa0/2 被配置为访问端口,使用命令switchport mode access 。
由于它们属于vlan10 ,所以用switchport access vlan 10 命令将它们配置为vlan10 中的访问端口。
访问端口fa0/3和fa0/4的配置
Switch(config)#int fa 0/3 !entering the interface port
Switch(config-if)#switchport mode access !making the interface fa0/3 an access port
Switch(config-if)#switchport access vlan 20 !making interface access port for vlan 10
Switch(config-if)#exit !exiting from the interface
Switch(config)#int fa 0/4 !entering the interface port
Switch(config-if)#switchport mode access !making the interface fa0/4 an access port
Switch(config-if)#switchport access vlan 20 !making interface access port for vlan 10
Switch(config-if)#exit
在上面的配置中,fa0/3 和fa0/4 被配置为访问端口,使用命令switchport mode access 。
由于它们属于vlan20 ,所以使用switchport access vlan 20 命令将它们配置为vlan20 中的访问端口。
中继端口fa0/5的配置
Switch(config)#int fa 0/5 !entering the interface port
Switch(config-if)#switchport mode trunk !making interface a trunk port.
Switch(config-if)#do write !saving the running configurations to start-up file
从上面的代码界面来看,fa0/5 是作为我们的主干端口。为了把它配置为干线端口而不是接入端口,我们在全局接口模式下使用命令switchport mode trunk 。
第3步
使用静态IP寻址,将网络上每台PC的IP地址设置为静态。

第4步
配置路由器,使流量从VLAN10 到VLAN20 。为了使PC能够通信,我们将单个接口细分为许多子接口,每个子接口将作为每个VLAN的默认网关。这将允许两个子网络使用单个接口进行通信。
Router>enable !moving from user exec mode to the priviledge exec mode
Router#config terminal !moving from priviledge exec mode to the global configuration mode
Router(config)#int g0/0 !entering on our physical router interface gigabitEthernet 0/0
Router(config-if)#no shutdown !activating the interface
Router(config-if)#int g0/0.10 !first sub interface for vlan 10 on g0/0
Router(config-subif)#encapsulation dot1q 10 !configuring the sub interface to respond to traffic from vlan 10
Router(config-subif)#ip add 192.168.1.1 255.255.255.0 !configuring the IP address of the sub interface g0/0.10
Router(config-subif)#exit !exiting from the sub interface
Router(config)#int g0/0 !entering our physical router interface
Router(config-if)#no shutdown !activating our physical interface
Router(config-if)#int g0/0.20 !second sub interface for vlan 20 on g0/0
Router(config-subif)#encapsulation dot1q 20 !configuring the sub interface to respond to traffic from vlan 20
Router(config-subif)#ip add 192.168.2.1 255.255.255.0 !configuring the IP address of the sub interface g0/0.20
Router(config-subif)#exit
Router(config)#do write !saving our running configurations into the start-up configuration file
Router(config)#exit
从上面的配置来看,接口g0/0 被细分为两个子接口:g0/0.10 为VLAN10 ,g0/0.20 为VLAN20 。
然后,这两个子接口被分配了IP地址,并作为承载流量的主干端口。
第5步
通过尝试ping不同的PC来测试VLAN之间的连接。
例如,如果我们从VLAN10 中的PC0 来pingVLAN20 中的PC2 ,应该会成功,如下图所示。

结论
对于任何对网络有热情的人来说,VLAN间路由是一个基本概念。它是划分大型局域网和实现网络主机之间通信的方便和更好的方法。