如下图所示,办公区的主机属于不同的网段192.168.5.0/24和192.168.50.0/24,Device C在收到来自办公区主机的报文时,根据报文的源IP地址,使来自不同网段主机的报文分别在指定的VLAN中传输,其中,来自网段192.168.5.0/24的报文在VLAN 100中传输,来自网段192.168.50.0/24的报文在VLAN 200中传输。
图1-6 基于IP子网的VLAN组网图
(1) 配置Device C
# 配置子网192.168.5.0/24与VLAN 100关联。
[DeviceC] vlan 100
[DeviceC-vlan100] ip-subnet-vlan ip 192.168.5.0 255.255.255.0
[DeviceC-vlan100] quit
# 配置子网192.168.50.0/24与VLAN 200关联。
[DeviceC] vlan 200
[DeviceC-vlan200] ip-subnet-vlan ip 192.168.50.0 255.255.255.0
[DeviceC-vlan200] quit
# 配置端口GigabitEthernet1/0/2为Hybrid端口,允许VLAN 100通过,并且在发送VLAN 100的报文时携带VLAN Tag。
[DeviceC] interface gigabitethernet 1/0/2
[DeviceC-GigabitEthernet1/0/2] port link-type hybrid
[DeviceC-GigabitEthernet1/0/2] port hybrid vlan 100 tagged
[DeviceC-GigabitEthernet1/0/2] quit
# 配置端口GigabitEthernet1/0/3为Hybrid端口,允许VLAN 200通过,并且在发送VLAN 200的报文时携带VLAN Tag。
[DeviceC] interface gigabitethernet 1/0/3
[DeviceC-GigabitEthernet1/0/3] port link-type hybrid
[DeviceC-GigabitEthernet1/0/3] port hybrid vlan 200 tagged
[DeviceC-GigabitEthernet1/0/3] quit
# 配置端口GigabitEthernet1/0/1为Hybrid端口,允许VLAN 100、200通过,并且在发送VLAN 100、200的报文时不携带VLAN Tag。
[DeviceC] interface gigabitethernet 1/0/1
[DeviceC-GigabitEthernet1/0/1] port link-type hybrid
[DeviceC-GigabitEthernet1/0/1] port hybrid vlan 100 200 untagged
# 配置端口GigabitEthernet1/0/1和基于IP子网的VLAN 100、200关联。
[DeviceC-GigabitEthernet1/0/1] port hybrid ip-subnet-vlan vlan 100
[DeviceC-GigabitEthernet1/0/1] port hybrid ip-subnet-vlan vlan 200
[DeviceC-GigabitEthernet1/0/1] quit
(2) 配置Device A和Device B
配置Device A和Device B允许对应VLAN通过,配置过程略。
# 查看所有子网VLAN的信息。
[DeviceC] display ip-subnet-vlan vlan all
VLAN ID: 100
Subnet index IP address Subnet mask
0 192.168.5.0 255.255.255.0
VLAN ID: 200
Subnet index IP address Subnet mask
0 192.168.50.0 255.255.255.0
# 查看端口GigabitEthernet1/0/1关联的子网VLAN的信息。
[DeviceC] display ip-subnet-vlan interface gigabitethernet 1/0/1
Interface: GigabitEthernet1/0/1
VLAN ID Subnet index IP address Subnet mask Status
100 0 192.168.5.0 255.255.255.0 Active
200 0 192.168.50.0 255.255.255.0 Active