> 文章列表 > 单臂路由实现VLAN间通信

单臂路由实现VLAN间通信

单臂路由实现VLAN间通信

解决物理接口数量有限的问题,可以通过在一个物理接口上配置多个子接口,这些子接口分别对应不同VLAN,这样只需连接一个物理接口即可实现不同VLAN之间的数据通信。
组网需求
如图1所示,交换机下挂三个不同网段的PC,由于此组网中的交换机为二层交换机,无法实现不同VLAN间的三层互通,因此在USG上配置子接口用于实现不同VLAN间的三层互通。同时,出于安全考虑,要求:
VLAN10和VLAN20内的主机能够相互访问。
VLAN30内的主机可以访问VLAN10和VLAN20内的主机,但是VLAN10和VLAN20内的主机都不能访问VLAN30内的主机。

配置思路
1.在USG的接口Eth0/0/0上启用子接口功能,分别对应不同的VLAN,实现不同VLAN间的三层互通。
2.在USG上创建两个不同的安全区域,将各子接口加入不同的安全区域,同时配置域间包过滤策略,实现VLAN间访问控制。其中,Ethernet 0/0/0.10和Ethernet 0/0/0.20属于同一个安全区域,使VLAN10和VLAN20内的主机能够相互访问。
3.在交换机上配置VLAN,并且将接口加入到对应的VLAN中。
4.配置各VLAN内的主机的IP地址和缺省网关,其中默认网关应配置为对应的子接口的IP地址。
操作步骤
1.配置USG。 
# 创建并配置以太网子接口Ethernet 0/0/0.10。

<USG> system-view
[USG] interface Ethernet 0/0/0.10
[USG-Ethernet0/0/0.10] vlan-type dot1q 10
[USG-Ethernet0/0/0.10] ip address 10.1.10.1 24
[USG-Ethernet0/0/0.10] quit

# 创建并配置以太网子接口Ethernet 0/0/0.20。

<USG> system-view
[USG] interface Ethernet 0/0/0.20
[USG-Ethernet0/0/0.20] vlan-type dot1q 20
[USG-Ethernet0/0/0.20] ip address 10.1.20.1 24
[USG-Ethernet0/0/0.20] quit

# 创建并配置以太网子接口Ethernet 0/0/0.30。

<USG> system-view
[USG] interface Ethernet 0/0/0.30
[USG-Ethernet0/0/0.30] vlan-type dot1q 30
[USG-Ethernet0/0/0.30] ip address 10.1.30.1 24
[USG-Ethernet0/0/0.30] quit

# 创建两个安全区域,并将各子接口加入不同的安全区域。

[USG] firewall zone name lan1
[USG-zone-lan1] set priority 60 
[USG-zone-lan1] add interface Ethernet0/0/0.10 
[USG-zone-lan1] add interface Ethernet0/0/0.20 
[USG-zone-lan1] quit[USG] firewall zone name lan2
[USG-zone-lan2] set priority 70 
[USG-zone-lan2] add interface Ethernet0/0/0.30 
[USG-zone-lan2] quit

# 配置域间包过滤策略,使VLAN30内的主机可以访问VLAN10和VLAN20内的主机,但是VLAN10和VLAN20内的主机都不能访问VLAN30内的主机。

[USG] policy interzone lan1 lan2 outbound
[USG-lan2-lan1-outbound] policy 0
[USG-lan2-lan1-outbound-0] policy source 10.1.30.0 0.0.0.255
[USG-lan2-lan1-outbound-0] action permit
[USG-lan2-lan1-outbound-0] quit
[USG-lan2-lan1-outbound] quit[USG] policy interzone lan1 lan2 inbound
[USG-lan2-lan1-inbound] policy 0
[USG-lan2-lan1-inbound-0] policy source 10.1.10.0 0.0.0.255
[USG-lan2-lan1-inbound-0] policy source 10.1.20.0 0.0.0.255
[USG-lan2-lan1-inbound-0] policy destination 10.1.30.0 0.0.0.255
[USG-lan2-lan1-inbound-0] action deny 
[USG-lan2-lan1-inbound-0] quit
[USG-lan2-lan1-inbound] quit

2.配置交换机。 
说明: 
以下配置以Quidway S2300为例进行说明,实际应用中请参考对应交换机的相关文档。
# 创建VLAN10、VLAN20和VLAN30,将Ethernet 0/0/2加入VLAN10,将Ethernet 0/0/3加入VLAN20,将Ethernet 0/0/4加入VLAN30。

[Switch] vlan batch 10 20 30
[Switch] interface ethernet 0/0/2
[Switch-Ethernet0/0/2] port link-type access
[Switch-Ethernet0/0/2] port default vlan 10
[Switch-Ethernet0/0/2] quit
[Switch] interface ethernet 0/0/3
[Switch-Ethernet0/0/3] port link-type access
[Switch-Ethernet0/0/3] port default vlan 20
[Switch-Ethernet0/0/3] quit
[Switch] interface ethernet 0/0/4
[Switch-Ethernet0/0/4] port link-type access
[Switch-Ethernet0/0/4] port default vlan 30
[Switch-Ethernet0/0/4] quit

# 配置接口Ethernet 0/0/1为VLAN Trunk接口,并允许VLAN 10、VLAN20、VLAN30通过。

[Switch] interface Ethernet 0/0/1
[Switch-Ethernet0/0/1] port link-type trunk
[Switch-Ethernet0/0/1] port trunk allow-pass vlan 10 20 30
[Switch-Ethernet0/0/1] quit

3.配置各VLAN内的主机的IP地址和缺省网关。其中: 
VLAN10内主机的缺省网关配置为10.1.10.1/24。
VLAN20内主机的缺省网关配置为10.1.20.1/24。
VLAN30内主机的缺省网关配置为10.1.30.1/24。
结果验证
配置完成后,查看VLAN10、VLAN20、VLAN30的主机能否按要求进行访问。
1.检查VLAN10内的主机是否能够同VLAN20内的主机相互通信。假设VLAN20内存在IP地址为10.1.20.2/24的主机。在VLAN10中的主机上执行ping 10.1.20.2命令,能够ping通VLAN20内的主机。

C:\\>ping 10.1.20.2
Pinging ping 10.1.20.2 with 32 bytes of data:
Reply from ping 10.1.20.2: bytes=32 time<1ms TTL=128
Reply from ping 10.1.20.2: bytes=32 time<1ms TTL=128
Reply from ping 10.1.20.2: bytes=32 time<1ms TTL=128
Reply from ping 10.1.20.2: bytes=32 time<1ms TTL=128
Ping statistics for ping 10.1.20.2  :Packets: Sent = 4,Received =4,Lost = 0 <0% loss>,
Approximates round trip times in milli-seconds:Minimum =0ms,Maximum =0ms,Average =0ms

2.检查VLAN30内的主机是否可以访问VLAN10和VLAN20内的主机。假设VLAN20内存在IP地址为10.1.20.2/24的主机。在VLAN30中的主机上执行ping 10.1.20.2命令,能够ping通VLAN20内的主机。

C:\\>ping 10.1.20.2
Pinging ping 10.1.20.2 with 32 bytes of data:
Reply from ping 10.1.20.2: bytes=32 time<1ms TTL=128
Reply from ping 10.1.20.2: bytes=32 time<1ms TTL=128
Reply from ping 10.1.20.2: bytes=32 time<1ms TTL=128
Reply from ping 10.1.20.2: bytes=32 time<1ms TTL=128
Ping statistics for ping 10.1.20.2  :Packets: Sent = 4,Received =4,Lost = 0 <0% loss>,
Approximates round trip times in milli-seconds:Minimum =0ms,Maximum =0ms,Average =0ms

3.检查VLAN10和VLAN20内的主机是否能访问VLAN30内的主机。假设VLAN30内存在IP地址为10.1.30.2/24的主机。在VLAN10中的主机上执行ping 10.1.30.2命令,将不能ping通VLAN30内的主机。

C:\\>ping 10.1.30.2
Pinging 10.1.30.2 with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Ping statistics for 10.1.30.2:Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),