Example for Assigning VLANs Based on IP Subnets
Networking Requirements
A data center network has multiple services, including office services, production services, and disaster recovery services. Each service uses a unique IP subnet. To facilitate management, packets of the same service must be transmitted in the same VLAN, and packets of different services be transmitted in different VLANs.
In Figure 5-24, the switch connects to the office server, production server, and disaster recovery server on different network segments. Different services need to be assigned to different VLANs and distributed to different remote networks.
Configuration Roadmap
- Create VLANs and determine which VLAN each service belongs to.
Associate IP subnets with VLANs so that VLANs of packets can be determined based on the source IP addresses or specified network segments.
- Add interfaces to VLANs so that packets of the IP subnet-based VLANs can pass through the interfaces.
- Enable IP subnet-based VLAN assignment.
Procedure
- Create VLANs.
# Create VLAN 100, VLAN 200, and VLAN 300 on the Switch.
<HUAWEI> system-view [~HUAWEI] sysname Switch [*HUAWEI] commit [~Switch] vlan batch 100 200 300 [*Switch] commit
- Configure interfaces.
# Set the link type of 10GE1/0/5, 10GE1/0/6, and 10GE1/0/7 to hybrid and add it to VLAN 100, VLAN 200, and VLAN 300 respectively in untagged mode. And enable IP subnet-based VLAN assignment on 10GE1/0/5, 10GE1/0/6, and 10GE1/0/7.
[~Switch] interface 10ge 1/0/5 [~Switch-10GE1/0/5] port link-type hybrid [*Switch-10GE1/0/5] port hybrid untagged vlan 100 [*Switch-10GE1/0/5] port hybrid pvid vlan 100 [*Switch-10GE1/0/5] ip-subnet-vlan enable [*Switch-10GE1/0/5] quit [*Switch] interface 10ge 1/0/6 [*Switch-10GE1/0/6] port link-type hybrid [*Switch-10GE1/0/6] port hybrid untagged vlan 200 [*Switch-10GE1/0/6] port hybrid pvid vlan 200 [*Switch-10GE1/0/6] ip-subnet-vlan enable [*Switch-10GE1/0/6] quit [*Switch] interface 10ge 1/0/7 [*Switch-10GE1/0/7] port link-type hybrid [*Switch-10GE1/0/7] port hybrid untagged vlan 300 [*Switch-10GE1/0/7] port hybrid pvid vlan 300 [*Switch-10GE1/0/7] ip-subnet-vlan enable [*Switch-10GE1/0/7] quit [*Switch] commit
# Add 10GE1/0/2 of the Switch to VLAN 100.
[~Switch] interface 10ge 1/0/2 [~Switch-10GE1/0/2] port link-type trunk [*Switch-10GE1/0/2] port trunk allow-pass vlan 100 [*Switch-10GE1/0/2] quit [*Switch] commit
# Add 10GE1/0/3 of the Switch to VLAN 200.
[~Switch] interface 10ge 1/0/3 [~Switch-10GE1/0/3] port link-type trunk [*Switch-10GE1/0/3] port trunk allow-pass vlan 200 [*Switch-10GE1/0/3] quit [*Switch] commit
# Add 10GE1/0/4 of the Switch to VLAN 300.
[~Switch] interface 10ge 1/0/4 [~Switch-10GE1/0/4] port link-type trunk [*Switch-10GE1/0/4] port trunk allow-pass vlan 300 [*Switch-10GE1/0/4] quit [*Switch] commit
- Configure IP subnet-based VLAN assignment.
# Associate IP subnet 192.168.1.2/24 with VLAN 100.
[~Switch] vlan 100 [~Switch-vlan100] ip-subnet-vlan 1 ip 192.168.1.2 24 [*Switch-vlan100] quit
# Associate IP subnet 192.168.2.2/24 with VLAN 200.
[*Switch] vlan 200 [*Switch-vlan200] ip-subnet-vlan 1 ip 192.168.2.2 24 [*Switch-vlan200] quit
# Associate IP subnet 192.168.3.2/24 with VLAN 300.
[*Switch] vlan 300 [*Switch-vlan300] ip-subnet-vlan 1 ip 192.168.3.2 24 [*Switch-vlan300] quit [*Switch] commit
- Verify the configuration.
Run the display ip-subnet-vlan vlan all command on the Switch. The following information is displayed:
[~Switch] display ip-subnet-vlan vlan all IP-subnet-VLAN count: 3 total count: 3 ---------------------------------------------------------------- VLAN Index IpAddress SubnetMask Priority ---------------------------------------------------------------- 100 1 192.168.1.2 255.255.255.0 0 200 1 192.168.2.2 255.255.255.0 0 300 1 192.168.3.2 255.255.255.0 0 ----------------------------------------------------------------
The product service, office service, and disaster recovery service can only be transmitted in the production center, campus office network, and disaster recovery data center respectively.
Configuration Files
Configuration file of the Switch
# sysname Switch # vlan batch 100 200 300 # vlan 100 ip-subnet-vlan 1 ip 192.168.1.2 255.255.255.0 # vlan 200 ip-subnet-vlan 1 ip 192.168.2.2 255.255.255.0 # vlan 300 ip-subnet-vlan 1 ip 192.168.3.2 255.255.255.0 # interface 10GE1/0/2 port link-type trunk port trunk allow-pass vlan 100 device transceiver 10GBASE-COPPER # interface 10GE1/0/3 port link-type trunk port trunk allow-pass vlan 200 device transceiver 10GBASE-COPPER # interface 10GE1/0/4 port link-type trunk port trunk allow-pass vlan 300 device transceiver 10GBASE-COPPER # interface 10GE1/0/5 port link-type hybrid port hybrid pvid vlan 100 port hybrid untagged vlan 100 ip-subnet-vlan enable device transceiver 10GBASE-COPPER # interface 10GE1/0/6 port link-type hybrid port hybrid pvid vlan 200 port hybrid untagged vlan 200 ip-subnet-vlan enable device transceiver 10GBASE-COPPER # interface 10GE1/0/7 port link-type hybrid port hybrid pvid vlan 300 port hybrid untagged vlan 300 ip-subnet-vlan enable device transceiver 10GBASE-COPPER # return