部署了VLAN的传统交换机不能实现不同VLAN间的二层报文转发,因此必须引入路由技术来实现不同VLAN间的通信。VLAN路由可以通过二层交换机配合路由器来实现,也可以通过三层交换机来实现。
VLAN间路由
所谓的三层交换机指的是携带路由功能的交换机。
VLAN的局限性
VLAN在分割广播域的同时也限制了不同VLAN间的主机进行二层通信的能力。
VLAN路由-每个VLAN一个物理连接
在二层交换机上配置VLAN,每一个VLAN使用一条独占的物理链路连接到路由器的一个接口上。
VLAN路由-单臂路由
将交换机和路由器之间的链路配置为Trunk链路,并且在路由器上创建子接口以支持VLAN路由。
VLAN路由-三层交换
为每个VLAN创建一个VLANIF接口作为网关。
以上就是VLAN间的路由选择,因为比较简单,所以直接使用的华为PPT里面的解释,并且没有加注释。下面是实验:
单臂路由实验
拓扑:
实验拓扑如图所示,配置如下:
基础ip配置已省略,网关地址最后一位均为254。
路由器:
#
interface GigabitEthernet0/0/0.10 //创建子接口
dot1q termination vid 10 // 将子接口划入VLAN(此时是VLAN10)
ip address 192.168.1.254 255.255.255.0 //添加IP地址(此时添加的为网关地址)
arp broadcast enable // 开启ARP广播功能
#
interface GigabitEthernet0/0/0.20
dot1q termination vid 20
ip address 192.168.2.254 255.255.255.0
arp broadcast enable
SW1:
#
interface Ethernet0/0/1
port link-type trunk
port trunk allow-pass vlan 10 20
#
interface Ethernet0/0/2
port link-type access
port default vlan 10
#
interface Ethernet0/0/3
port link-type access
port default vlan 20
#
interface Ethernet0/0/4
port link-type trunk
port trunk allow-pass vlan 10 20
SW2:
#
interface Ethernet0/0/1
port link-type trunk
port trunk allow-pass vlan 10 20
#
interface Ethernet0/0/2
port link-type access
port default vlan 10
#
interface Ethernet0/0/3
port link-type access
port default vlan 20
#
在路由器上查看ip路由表:
图中标出为目的网段,此时是直连网段。
实验测试:
抓包显示:
此时是在路由器接口上进行抓包,前面有提过,主机收到的数据包是不带tag的。
三层交换实验
实验拓扑:
基础ip配置不变,实现的功能为不同VLAN间可以互通,相同VLAN可以互通。
配置如下:
SW1:
#
interface Vlanif10 //创建虚拟接口(可当成路由器上的物理接口看待)
ip address 192.168.1.254 255.255.255.0 //添加ip地址(此时为网关地址)
#
interface Vlanif20
ip address 192.168.2.254 255.255.255.0
#
interface MEth0/0/1
#
interface Ethernet0/0/1
port link-type trunk
port trunk allow-pass vlan 10 20
#
interface Ethernet0/0/2
port link-type access
port default vlan 10
#
interface Ethernet0/0/3
port link-type access
port default vlan 20
#
SW2:
#
interface Ethernet0/0/1
port link-type trunk
port trunk allow-pass vlan 10 20
#
interface Ethernet0/0/2
port link-type access
port default vlan 10
#
interface Ethernet0/0/3
port link-type access
port default vlan 20
#
实验结果:
查看路由表: