VLAN间通信的三种方法
vlanif接口
最常用,又叫虚拟接口,这种方式一般使用三层交换机实现,它包含路由模块和交换模块,交换模块可以实现剥离和添加VLAN标签,路由模块实现路由功能
VLANif接口 为各自vlan的网关
#
interface Vlanif10
ip address 192.168.10.254 255.255.255.0
#
interface Vlanif20
ip address 192.168.20.254 255.255.255.0
#
interface GigabitEthernet0/0/1
port link-type access
port default vlan 10
#
interface GigabitEthernet0/0/2
port link-type access
port default vlan 20
#生成相应的直连路由
192.168.10.0/24 Direct 0 0 D 192.168.10.254 Vlanif10
192.168.10.254/32 Direct 0 0 D 127.0.0.1 Vlanif10
192.168.20.0/24 Direct 0 0 D 192.168.20.254 Vlanif20
192.168.20.254/32 Direct 0 0 D 127.0.0.1 Vlanif20
路由器子接口
这种方法一般使用在交换机和路由器相连的场景,因为路由器接口很少,交换机的接口多,划分VLAN多。
路由器识别不了交换机的VLAN标签,子接口可以实现剥离VLAN标签
缺省情况下(华为),终结子接口没有使能ARP广播功能。终结子接口不能转发广播
报文,在收到广播报文后它们直接把该报文丢弃。为了允许终结子接口能转发广播报文,
可以通过在子接口上执行此命令。
R1
#
interface GigabitEthernet0/0/0.10
dot1q termination vid 10
ip address 192.168.10.254 255.255.255.0
arp broadcast enable
#
interface GigabitEthernet0/0/0.20
dot1q termination vid 20
ip address 192.168.20.254 255.255.255.0
arp broadcast enable
SW2
#
interface Ethernet0/0/1
port link-type trunk
port trunk allow-pass vlan 10 20
#
interface Ethernet0/0/2
#
interface Ethernet0/0/3
port link-type access
port default vlan 10
#
interface Ethernet0/0/4
port link-type access
port default vlan 20
#生成相应的直连路由
<R1>display ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 6 Routes : 6
Destination/Mask Proto Pre Cost Flags NextHop Interface
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
192.168.10.0/24 Direct 0 0 D 192.168.10.254 GigabitEthernet
0/0/0.10
192.168.10.254/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0.10
192.168.20.0/24 Direct 0 0 D 192.168.20.254 GigabitEthernet
0/0/0.20
192.168.20.254/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0.20
路由器物理接口
这种方法很少使用,因为,因为路由器接口很少,交换机的接口多,划分VLAN多。
划分多少个VLAN,路由器交换机相连就要用多少根线
SW1
#
interface Ethernet0/0/5
port link-type access
port default vlan 50
#
interface Ethernet0/0/6
port link-type access
port default vlan 60
#
interface Ethernet0/0/7
port link-type access
port default vlan 50
#
interface Ethernet0/0/8
port link-type access
port default vlan 60
R1
#
interface GigabitEthernet0/0/0
ip address 192.68.10.254 255.255.255.0
#
interface GigabitEthernet0/0/1
ip address 192.68.20.254 255.255.255.0