同一VLAN的终端可以互相通信,但不同VLAN间的终端不能二层互通,要想让不同VLAN间的终端互通,需要借助三层路由,目前有以下两种方式实现:
Dot1q终结:
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
//创建g0/0/0.2子接口
[Huawei]int g0/0/0.2
//Dot1q终结
[Huawei-GigabitEthernet0/0/0.2]dot1q termination vid 2
//关闭Dot1q终结
[Huawei-GigabitEthernet0/0/0.2]undo dot1q termination vid 2
终结子接口报文后,端口收发报文时的规则:
接收报文——剥离报文中的tag后进行三层转发,转发出去的报文是否带tag由出接口决定。
发送报文——将相应的VLAN信息添加到报文中再发送。
注意:
a. 子接口收到的用户报文的tag值应该在命令指定的low-pe-vid和high-pe-vid的范围内,否则将丢弃该报文;
b. 子接口允许通过的VLAN不能在全局下创建,也不能查看该VLAN信息;
c. 该命令是累增式命令,多次配置时,按多次累加生效。
<Huawei>sys
Enter system view, return user view with Ctrl+Z
//创建vlan
[Huawei]vlan batch 2 3
//配置端口e0/0/2
[Huawei]int e0/0/2
//设置接口类型为access
[Huawei-Ethernet0/0/2]port link-type access
//把端口划到VLAN 2
[Huawei-Ethernet0/0/2]port default vlan 2
//配置端口e0/0/3
[Huawei-Ethernet0/0/2]int e0/0/3
[Huawei-Ethernet0/0/3]port link-t access
[Huawei-Ethernet0/0/3]port default vlan 3
//与路由器连接的端口类型要设置成Trunk
[Huawei-Ethernet0/0/3]int e0/0/1
[Huawei-Ethernet0/0/1]port link-t trunk
//放行需要互通的VLAN
[Huawei-Ethernet0/0/1]port trunk allow-pass vlan 2 3
[Huawei-Ethernet0/0/1]q
//添加一个不常用的VLAN给Trunk使用
[Huawei]vlan 99
//把Trunk端口的PVID设置为不常用的VLAN,并取消放行VLAN 1
[Huawei-Ethernet0/0/1]port trunk pvid vlan 99
[Huawei-Ethernet0/0/1]undo port trunk allow-pass vlan 1
三层路由器的配置:
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
创建子接口,子接口端口号尽量与vlan一致
[Huawei]int g0/0/0.2
//给子接口配置IP
[Huawei-GigabitEthernet0/0/0.2]ip add 192.168.1.254 24
//Dot1q终结vlan 2
[Huawei-GigabitEthernet0/0/0.2]dot1q termination vid 2
//开启Dot1q广播功能
[Huawei-GigabitEthernet0/0/0.2]arp broadcast enable
[Huawei-GigabitEthernet0/0/0.2]q
//配置子端口g0/0/0.3
[Huawei]int g0/0/0.3
[Huawei-GigabitEthernet0/0/0.3]ip add 192.168.2.254 24
[Huawei-GigabitEthernet0/0/0.3]dot1q termination vid 3
[Huawei-GigabitEthernet0/0/0.3]arp broadcast enable
//查看路由表
<Huawei>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
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
192.168.1.0/24 Direct 0 0 D 192.168.1.254 GigabitEthernet
0/0/0.2
192.168.1.254/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0.2
192.168.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0.2
192.168.2.0/24 Direct 0 0 D 192.168.2.254 GigabitEthernet
0/0/0.3
192.168.2.254/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0.3
192.168.2.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0.3
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
在PC1上测试:
PC>ping 192.168.1.254
Ping 192.168.1.254: 32 data bytes, Press Ctrl_C to break
From 192.168.1.254: bytes=32 seq=1 ttl=255 time=765 ms
From 192.168.1.254: bytes=32 seq=2 ttl=255 time=94 ms
From 192.168.1.254: bytes=32 seq=3 ttl=255 time=47 ms
From 192.168.1.254: bytes=32 seq=4 ttl=255 time=47 ms
From 192.168.1.254: bytes=32 seq=5 ttl=255 time=47 ms
--- 192.168.1.254 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 47/200/765 ms
PC>ping 192.168.2.2
Ping 192.168.2.2: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 192.168.2.2: bytes=32 seq=2 ttl=127 time=94 ms
From 192.168.2.2: bytes=32 seq=3 ttl=127 time=62 ms
From 192.168.2.2: bytes=32 seq=4 ttl=127 time=94 ms
From 192.168.2.2: bytes=32 seq=5 ttl=127 time=62 ms
--- 192.168.2.2 ping statistics ---
5 packet(s) transmitted
4 packet(s) received
20.00% packet loss
round-trip min/avg/max = 0/78/94 ms
单臂路由的缺点:
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
//先创建VLAN
[Huawei]vlan batch 2 3
//进入VLANIF
[Huawei]int vlanif 2
//给VLANIF配置IP
[Huawei-Vlanif2]ip add 192.168.1.254 24
[Huawei-Vlanif2]q
[Huawei]int vlanif 3
[Huawei-Vlanif3]ip add 192.168.2.254 24
//把端口划到和VLANIF相同的VLAN
[Huawei]int g0/0/2
[Huawei-GigabitEthernet0/0/2]port link-type access
[Huawei-port-group-default]port default vlan 2
[Huawei-port-group-default]q
[Huawei]int g0/0/3
[Huawei-GigabitEthernet0/0/3]port link-type access
[Huawei-GigabitEthernet0/0/3]port default vlan 3
用PC1测试:
PC>ping 192.168.1.254
Ping 192.168.1.254: 32 data bytes, Press Ctrl_C to break
From 192.168.1.254: bytes=32 seq=1 ttl=255 time=109 ms
From 192.168.1.254: bytes=32 seq=2 ttl=255 time=16 ms
From 192.168.1.254: bytes=32 seq=3 ttl=255 time=31 ms
From 192.168.1.254: bytes=32 seq=4 ttl=255 time=16 ms
From 192.168.1.254: bytes=32 seq=5 ttl=255 time<1 ms
--- 192.168.1.254 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 0/34/109 ms
PC>ping 192.168.2.2
Ping 192.168.2.2: 32 data bytes, Press Ctrl_C to break
From 192.168.2.2: bytes=32 seq=1 ttl=127 time=78 ms
From 192.168.2.2: bytes=32 seq=2 ttl=127 time=47 ms
From 192.168.2.2: bytes=32 seq=3 ttl=127 time=47 ms
From 192.168.2.2: bytes=32 seq=4 ttl=127 time=47 ms
From 192.168.2.2: bytes=32 seq=5 ttl=127 time=47 ms
--- 192.168.2.2 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 47/53/78 ms
VLANIF接口的UP条件:
三层交换机的特点:一次路由,多次交换——从一个VLAN第一次访问另一个VLAN,查询三层的路由表,之后再访问同一个VLAN不再查询路由表,而是查询二层的MAC表。
八字真言:交换谋快,路由谋转
三层交换机的注意用途时代替传统路由器作为网络的核心。在没有互联网连接需求,同时需要路由功能的地方,都可以使用三层交换机。在局域网,三层交换机通常作为网络的核心层和汇聚层。