不同vlan间的通信简单配置的三种方式解析

不同vlan之间通信的原理 在划分vlan后,不同vlan之间不能直接进行二层通信。如果要实现vlan间通信,可以采取以下3种方案之一。
1.三层vlanif接口方案
这是一种通过计算机网络体系结构中第三层(网络层)来实现vlan间通信的解决方案。每个vlan都可以配置一个三层vlanif逻辑接口,而这些vlanif接口就作为对应vlan内部用户主机的缺省网关,通过三层交换机内部的ip路由功能可以实现同一交换机上不同vlan的三层互通,不同交换机上不同vlan间的三层互通需要配置各vlanif接口所在网段间的路由。
该方案除s1700系列外,其他所有华为s系列交换机均支持。
在图6-20所示的网络中,device交换机上划分了两个vlan:vlan2和vlan3。可通过如下配置实现vlan间互通。
(1)在device上创建两个vlanif接口并配置vlanif接口的ip地址,但这两个vlanif接口对应的ip地址不能在同一网段。
(2)将各vlan中的用户设备缺省网关设置为所属vlan对应vlanif接口的ip地址。
现在仅以位于vlan 2中的主机a向位于vlan 3中的主机c发起通信为例,介绍通过vlanif接口进行vlan间三层互通的基本原理。具体通信流程如下。
(1)在主机a向主机c发送的数据包到了网络层后,主机a先将包中的目的ip地址-主机c的ip地址和自己所在网段进行比较。
(2)发现主机c和自己不在同一个子网,于是主机a以广播方式在本子网内发送一个arp请求帧,其目的是查寻自己的网关-vlanif2接口的mac地址。
(3)vlanif2接口经过与arp请求帧中的目的ip地址进行比较,发现自己的ip地址与其一致,接收该arp请求帧,然后以单播方式向主机a返回一个arp应答帧,帧中的源mac地址即为vlanif2的mac地址。
(4)在主机a接收由vlanif2接口返回的arp应答帧后从中学习到了vlanif2接口的mac地址。
(5)主机a利用所获得的网关vlanif2接口的mac地址,重新进行数据帧封装,把帧中的目的mac改为vlanif2接口mac地址,目的ip仍为主机c的ip地址,然后发送给网关-vlanif2接口。
(6)device交换机在收到该数据帧后进行三层转发,发现帧中的目的ip地址--主机c的ip地址为直连路由,数据帧直接通过该主机的网关-vlanif3接口进行转发。
(7)vlanif3接口作为vlan 3内主机的网关,在收到数据帧后如果已有主机c的ip地址与mac地址映射表,则直接发送给主机c,否则vlanif3接口先在vlan 3内以广播方式发送一个arp请求帧,查寻主机c的mac地址。
(8)主机c在收到arp广播帧后向vlanif3接口返回一个arp应答帧。
(9)vlanif3接口在收到主机c发来的arp应答帧后再次进行数据帧封装,把帧中的目的mac地址改为主机c的真实mac地址(其他不变),然后把主机a发来的数据帧发送给主机c。这样主机a之后要发给c的数据帧都先发送给网关,由网关-vlanif3接口做三层转发。
主机c与主机a之间的通信原理一样,最终实现vlan间的三层互通。
2.三层以太网子接口方案
三层以太网子接口是一种同时具备三层以太网物理接口和二层以太网物理接口双重特性的逻辑接口。即它具有三层以太网物理接口的三层路由功能,同时又具有二层以太网物理接口封装vlan标签的特性。通过三层以太网子接口就可以实现不同vlan间的三层互通,也就是我们通常所说的“单臂路由”,在三层交换机和路由器中均可实现。
该方案仅5700hi和5710ei子系列、s7700、s9300和s9700系列华为交换机支持。
如图6-21所示,devicea为支持配置子接口的三层设备,deviceb为二层交换设备。lan通过deviceb的二层以太网接口与devicea的三层以太网接口相连。连接在deviceb上的用户主机被划分到两个vlan:vlan2和vlan3。这时可通过如下配置实现vlan间互通。
(1)在devicea与deviceb相连的三层以太网接口上创建两个子接口port1.1和port1.2,并配置802.1q封装与vlan2和vlan3分别对应。
(2)为以上这两个子接口配置与各自所属vlan对应网段的ip地址。
(3)将deviceb与devicea相连的二层以太网接口类型配置为trunk或hybrid类型,并同时允许vlan2和vlan3的帧通过。
(4)将vlan 2和vlan 3中的用户设备的缺省网关设置为所属vlan对应三层以太网子接口的ip地址。
现在同样以主机a向主机c发起通信为例介绍三层以太网子接口的vlan间通信方案的基本原理(其实基本过程与前面介绍的vlanif接口vlan间通信方案是一样的,只不过这里的网关是各vlan所对应的子接口)。具体流程如下。
(1)在主机a向主机c发送的数据包到了网络层后,主机a先将包中的目的ip地址-主机c的ip地址和自己所在网段进行比较。
(2)发现主机c和自己不在同一个子网,于是主机a以广播方式在本子网内发送一个arp请求帧,其目的是查寻自己的网关vlan 2对应的port1.1子接口的mac地址。
(3)port1.1子接口经过与arp请求帧中的目的ip地址进行比较,发现自己的ip地址与其一致,接收该arp请求帧,然后以单播方式向主机a返回一个arp应答帧,帧中的源mac地址即为port1.1子接口的mac地址。
(4)主机a接收由port1.1子接口返回的arp应答帧后从中学习到该子接口的mac地址。
(5)主机a利用所获得的网关port1.1子接口的mac地址,重新封装数据帧,把目的mac地址改为port1.1子接口mac,目的ip仍为主机c的ip地址,然后发送给网关port1.1子接口。
(6)devicea交换机在收到该数据帧后进行三层转发,发现其目的ip地址-主机c的ip地址为直连路由,数据帧直接通过该主机的网关-vlan 3对应port1.2子接口进行转发。
(7)port1.2子接口作为vlan 3内主机的网关,在收到数据帧后如果已有主机c的ip地址与mac地址映射表,则直接发送给主机c,否则port1.2子接口先在vlan 3内以广播方式发送一个arp请求帧,查寻主机c的mac地址。
(8)主机c在收到arp广播帧后向port1.2子接口返回一个arp应答帧。
(9)port1.2子接口在收到主机c的arp应答帧后,再次进行数据帧封装,把帧中的目的mac地址改为主机c的真实mac地址(其他不变),然后就把主机a发来的数据帧发送给主机c。这样主机a之后要发给c的数据帧都先发送给网关,由网关-port1.2子接口做三层转发。
主机c与主机a之间的通信原理一样,最终实现vlan间的三层互通。
3.vlan switch方案
通过vlan switch(vlan交换)也可以实现不同vlan间的通信。vlan交换是一种按照vlan标签进行数据转发的技术,需要预先在网络中的各交换机上建立一条静态转发路径。当交换机接收到符合转发条件的vlan数据后,根据vlan交换表将报文直接转发到相应的出接口,无需查看mac地址表,提高了转发效率及安全性,可有效地避免mac地址攻击及广播风暴。
该方案仅在s7700、s9300、s9300e和s9700等华为高端s系列交换机中支持。
vlan交换功能如下。
(1)添加外层vlan标签功能,即vlan switch stack-vlan功能。
(2)在不同接口之间转换外层vlan标签,即vlan switch switch-vlan功能。
vlan switch stack-vlan功能与vlan stacking(vlan堆叠,将在下章介绍)功能类似,也是一种针对用户不同vlan封装外层vlan标签的二层技术。与vlan stacking功能的差异如表6-11所示。
表6-11 vlan switch功能与vlan stacking功能比较
vlan switch switch-vlan功能与vlan mapping(vlan映射,将在下章具体介绍)功能类似,也可以实现不同vlan间的通信。与vlan mapping功能的差异如表6-12所示。
表6-12 vlan switch功能与vlan mapping功能比较
1.单臂路由(图) 环境:一台路由器,一台二层交换机,两台pc机
二层交换机的配置
一般模式:
switch》
输入enable进入特权模式:
switch》enable
输入configure terminal进入全局配置模式:
switch#configure terminal
enter configuration commands, one per line. end with cntl/z.
创建vlan 10 和 vlan 20:
switch(config)#vlan 10
switch(config-vlan)#vlan 20
switch(config-vlan)# exit
进入接口配置模式:
switch(config)#interface fastethernet 0/1
把0/1变成trunk口(默认是access口)
switch(config-if)#switchport mode trunk
%lineproto-5-updown: line protocol on interface fastethernet0/1, changed state to down
%lineproto-5-updown: line protocol on interface fastethernet0/1, changed state to up
switch(config-if)#exit
进入接口配置模式分别把对应的接口,加入对应的vlan:
switch(config)#interface fastethernet 1/1
switch(config-if)#switchport mode access
switch(config-if)#switchport access vlan 10
switch(config-if)#interface fastethernet 2/1
switch(config-if)#switchport mode access
switch(config-if)#switchport access vlan 20
到此而层交换机配置完毕!
路由器的配置:
router》
router》enable
router#configure terminal
enter configuration commands, one per line. end with cntl/z.
router(config)#inter fas 0/0
router(config-if)#no ip address
router(config-if)#no shutdown
注意:单臂路由的配置父接口一定要no shutdown
%link-5-changed: interface fastethernet0/0, changed state to up
%lineproto-5-updown: line protocol on interface fastethernet0/0, changed state to up
router(config-if)#exit
router(config)#int fas 0/0.10
%link-5-changed: interface fastethernet0/0.10, changed state to up
%lineproto-5-updown: line protocol on interface fastethernet0/0.10, changed state to up
router(config-subif)#encapsulation dot1q 10
注意:在配置ip时一定要先封装802.1q协议
router(config-subif)#ip address 192.168.10.1 255.255.255.0
router(config-subif)#no shutdown
router(config-subif)#int fas 0/0.20
%link-5-changed: interface fastethernet0/0.20, changed state to up
%lineproto-5-updown: line protocol on interface fastethernet0/0.20, changed state to up
router(config-subif)#ip address 192.168.20.1 255.255.255.0
% configuring ip routing on a lan subinterface is only allowed if that
subinterface is already configured as part of an ieee 802.10, ieee 802.1q,
or isl vlan.
router(config-subif)#encapsulation dot1q 20
router(config-subif)#ip address 192.168.20.1 255.255.255.0
router(config-subif)#no shutdown
router(config-subif)#
查看路由表:
router#show ip route
codes: c - connected, s - static, i - igrp, r - rip, m - mobile, b - bgp
d - eigrp, ex - eigrp external, o - ospf, ia - ospf inter area
n1 - ospf nssa external type 1, n2 - ospf nssa external type 2
e1 - ospf external type 1, e2 - ospf external type 2, e - egp
i - is-is, l1 - is-is level-1, l2 - is-is level-2, ia - is-is inter area
* - candidate default, u - per-user static route, o - odr
p - periodic downloaded static route
gateway of last resort is not set
c 192.168.10.0/24 is directly connected, fastethernet0/0.10
c 192.168.20.0/24 is directly connected, fastethernet0/0.20
router#
pc0的配置:
ip 192.168.10.10
netmask 255.255.255.0
gateway 192.168.10.1
pc1的配置:
ip 192.168.20.20
netmask 255.255.255.0
gateway 192.168.20.1
2.使用svi实现vlan间的通信(图) 环境:一台三层交换机,两台pc机
三层交换机的配置:
switch》enable
switch#configure terminal
enter configuration commands, one per line. end with cntl/z.
创建vlan 10 20
switch(config)#vlan 10
switch(config-vlan)#vlan 20
switch(config-vlan)#exit
配置svi接口ip
switch(config)#interface vlan 10
%link-5-changed: interface vlan10, changed state to up
switch(config-if)#ip address 192.168.10.1 255.255.255.0
switch(config-if)#no shutdown
switch(config-if)#interface vlan 20
%link-5-changed: interface vlan20, changed state to up
switch(config-if)#ip address 192.168.20.1 255.255.255.0
switch(config-if)#no shutdown
switch(config-if)#exit
改变接口模式并加入vlan
switch(config)#interface fastethernet 0/1
switch(config-if)#switchport mode access
switch(config-if)#switchport access vlan 10
%lineproto-5-updown: line protocol on interface vlan10, changed state to up
switch(config-if)#interface fastethernet 0/2
switch(config-if)#switchport mode access
switch(config-if)#switchport access vlan 20
%lineproto-5-updown: line protocol on interface vlan20, changed state to up
switch(config-if)#
看三层交换机的路由表:
switch#show ip route
codes: c - connected, s - static, i - igrp, r - rip, m - mobile, b - bgp
d - eigrp, ex - eigrp external, o - ospf, ia - ospf inter area
n1 - ospf nssa external type 1, n2 - ospf nssa external type 2
e1 - ospf external type 1, e2 - ospf external type 2, e - egp
i - is-is, l1 - is-is level-1, l2 - is-is level-2, ia - is-is inter area
* - candidate default, u - per-user static route, o - odr
p - periodic downloaded static route
gateway of last resort is not set
c 192.168.10.0/24 is directly connected, vlan10
c 192.168.20.0/24 is directly connected, vlan20
switch#
两主机的配置与单臂路由中两主机的配置一样
3.跨交换机实现vlan间的通信(图) 环境:一台三层交换机,两台二层交换机,两台pc机
三层交换机的配置(sw3)
switch》enable
switch#configure terminal
enter configuration commands, one per line. end with cntl/z.
创建vlan 10 、 20 并设置ip
switch(config)#vlan 10
switch(config-vlan)#vlan 20
switch(config-vlan)#exit
switch(config)#interface vlan 10
%link-5-changed: interface vlan10, changed state to up
switch(config-if)#ip address 192.168.10.1 255.255.255.0
switch(config-if)#no shutdown
switch(config-if)#interface vlan 20
%link-5-changed: interface vlan20, changed state to up
switch(config-if)#ip address 192.168.20.1 255.255.255.0
switch(config-if)#no shutdown
switch(config-if)#exit
设置接口模式并加入相应的vlan(注意trunk口的设置)
switch(config)#interface fastethernet 0/1
switch(config-if)#switchport mode trunk
switch(config-if)#interface fastethernet 0/1
switch(config-if)#switchport access vlan 10
%lineproto-5-updown: line protocol on interface vlan10, changed state to up
switch(config)#interface fastethernet 0/2
switch(config-if)#switchport mode trunk
switch(config-if)#interface fastethernet 0/2
switch(config-if)#switchport access vlan 20
%lineproto-5-updown: line protocol on interface vlan20, changed state to up
switch#
看路由表
switch#show ip route
codes: c - connected, s - static, i - igrp, r - rip, m - mobile, b - bgp
d - eigrp, ex - eigrp external, o - ospf, ia - ospf inter area
n1 - ospf nssa external type 1, n2 - ospf nssa external type 2
e1 - ospf external type 1, e2 - ospf external type 2, e - egp
i - is-is, l1 - is-is level-1, l2 - is-is level-2, ia - is-is inter area
* - candidate default, u - per-user static route, o - odr
p - periodic downloaded static route
gateway of last resort is not set
c 192.168.10.0/24 is directly connected, vlan10
c 192.168.20.0/24 is directly connected, vlan20
sw21的配置
switch》enable
switch#configure terminal
enter configuration commands, one per line. end with cntl/z.
switch(config)#vlan 10
switch(config-vlan)#exit
switch(config)#interface fastethernet 0/1
switch(config-if)#switchport mode trunk
%lineproto-5-updown: line protocol on interface fastethernet0/1, changed state to down
%lineproto-5-updown: line protocol on interface fastethernet0/1, changed state to up
switch(config-if)#interface fastethernet 1/1
switch(config-if)#switchport mode access
switch(config-if)#switchport access vlan 10
switch(config-if)#exit
switch(config)#
sw22的配置
switch》
switch》en
switch#
switch#configure ter
enter configuration commands, one per line. end with cntl/z.
switch(config)#inter fas 1/1
switch(config-if)#switchport mode trunk
%lineproto-5-updown: line protocol on interface fastethernet1/1, changed state to down
%lineproto-5-updown: line protocol on interface fastethernet1/1, changed state to up
switch(config-if)#switchport mode access
switch(config-if)#inter fas 2/1
switch(config-if)#switchport mode trunk
%lineproto-5-updown: line protocol on interface fastethernet2/1, changed state to down
%lineproto-5-updown: line protocol on interface fastethernet2/1, changed state to up
switch(config-if)#exit
switch(config)#vlan 20
switch(config-vlan)#inter fas 1/1
switch(config-if)#switchport access vlan 20
switch(config-if)#
注意:两交换机之间的链接是trunk链路
4.以上配置在模拟器上都可实现
在模拟器上配置其中pc图片
上述三种方式pc机的配置都一样
验证:

led不同封装方法造成的影响
Linux内核的编译和运行
金升阳科技发布元器件100%国产化的DC/DC电源模块产品
蜂窝物联茶叶种植智能管理系统
ADI产品线
不同vlan间的通信简单配置的三种方式解析
柯泰光芯发布窄脉冲晶圆量产测试机台VMP9000
高通与苹果同时在官网发布声明宣布正式达成全面和解协议
荣耀8、荣耀V9对比评测:华为荣耀8、荣耀V9怎么样?配置、设计、价格大比拼!
29部万圣节恐怖短片进驻VRrOOm
DRAM的价格下跌和需求疲软 或将持续到2019年第三季度
一分钟告诉你!智能家居安防系统中有哪五大优势?
锡膏保存期限是多久?
中国国家电网打破了输电电压、距离和功率的世界纪录
Quartz中编码中用到的几个对象
意法半导体在深圳举办首届工业峰会
胆前级制作,vacuum tube preamplifier
方案|基于飞凌FETMX8MP-C核心板实现的商用车智能驾驶终端
电容中的穿心电容是什么意思?电容的充放电电路图及其原理
怎样用CMOS集成电路制作家用电器开关