1.拓扑图如下
PC1的设置如下:
在未配置VLAN之前,PC1可以ping通PC3,PC2可以ping通PC4(因为同一网段)
2.SW1和SW4配置VLAN
<Huawei>system-view
[Huawei]undo info-center enable //关闭提示信息
[Huawei]sysname SW1
[SW1]vlan batch 10 20
[SW1]interface GigabitEthernet 0/0/1
[SW1-GigabitEthernet0/0/1]port link-type access
[SW1-GigabitEthernet0/0/1]port default vlan 10
[SW1-GigabitEthernet0/0/1]int g0/0/2
[SW1-GigabitEthernet0/0/2]port link-type access
[SW1-GigabitEthernet0/0/2]port default vlan 20
[SW1-GigabitEthernet0/0/2]int g0/0/24
[SW1-GigabitEthernet0/0/24]port link-type trunk
[SW1-GigabitEthernet0/0/24]port trunk allow-pass vlan 10 20
<Huawei>system-view
[Huawei]sysname SW4
[SW4]undo info-center enable
[SW4]vlan batch 10 20
[SW4]interface g0/0/1
[SW4-GigabitEthernet0/0/1]port link-type access
[SW4-GigabitEthernet0/0/1]port default vlan 10
[SW4-GigabitEthernet0/0/1]int g0/0/2
[SW4-GigabitEthernet0/0/2]port link-type access
[SW4-GigabitEthernet0/0/2]port default vlan 20
[SW4-GigabitEthernet0/0/2]int g0/0/24
[SW4-GigabitEthernet0/0/24]port link-type trunk
[SW4-GigabitEthernet0/0/24]port trunk allow-pass vlan 10 20
配完后,PC1和PC2,PC3,PC4都不通(原因,SW2和SW3未配VLAN)
3.配置SW2交换机
<Huawei>system-view
[Huawei]undo info-center enable
[Huawei]sysname SW2
[SW2]vlan 100
[SW2]interface GigabitEthernet 0/0/24
[SW2-GigabitEthernet0/0/24]port link-type dot1q-tunnel
[SW2-GigabitEthernet0/0/24]port default vlan 100
[SW2-GigabitEthernet0/0/24]int g0/0/23
[SW2-GigabitEthernet0/0/23]port link-type trunk
[SW2-GigabitEthernet0/0/23]port trunk allow-pass vlan 100
4.配置SW3交换机
<Huawei>system-view
[Huawei]un in en
[Huawei]sysname SW3
[SW3]vlan 100
[SW3]interface GigabitEthernet 0/0/23
[SW3-GigabitEthernet0/0/23]port link-type trunk
[SW3-GigabitEthernet0/0/23]port trunk allow-pass vlan 100
[SW3-GigabitEthernet0/0/23]int g0/0/24
[SW3-GigabitEthernet0/0/24]port link-type dot1q-tunnel
[SW3-GigabitEthernet0/0/24]port default vlan 100
验证:PC1可以ping通PC3,PC2可以ping通PC4
5. PC1不间断pingPC3,PC2不间断pingPC4,在SW2端口0/0/23上抓包,可以发现对应的VLAN
5.1 如下图,10.1.1.2发向10.1.1.3的数据包中,内层VLAN为10,外层VLAN为100.
5.2如下图,10.1.2.2发向10.1.2.3的数据包中,内层VLAN为20,外层VLAN为100.