华为基于接口的典型vlan-适合晋级者
1.配置接入交换机SW2

创建VLAN。

<HUAWEI> system-view
[HUAWEI] sysname SW2 //修改设备的名称为SW2,便于识别
[SW2] vlan batch 2 3 //批量创建VLAN 2和VLAN 3

将接口加入相应VLAN。

[SW2] interface gigabitethernet 1/0/23
[SW2-GigabitEthernet1/0/23] port link-type access //将与PC相连接口的接口类型设置为access
[SW2-GigabitEthernet1/0/23] port default vlan 2 //将PC1划分到VLAN 2
[SW2-GigabitEthernet1/0/23] quit
[SW2] interface gigabitethernet 1/0/24
[SW2-GigabitEthernet1/0/24] port link-type access
[SW2-GigabitEthernet1/0/24] port default vlan 3 //将PC2划分到VLAN 3
[SW2-GigabitEthernet1/0/24] quit
[SW2] interface gigabitethernet 1/0/1
[SW2-GigabitEthernet1/0/1] port link-type trunk //将与汇聚交换机相连接口的接口类型设置为trunk
[SW2-GigabitEthernet1/0/1] port trunk allow-pass vlan 2 3 //透传VLAN 2和VLAN 3到汇聚交换机SW1
[SW2-GigabitEthernet1/0/1] quit

  1. 配置汇聚交换机SW1

    创建VLAN。

    <HUAWEI> system-view
    [HUAWEI] sysname SW1 //修改设备的名称为SW1
    [SW1] vlan batch 2 to 5 //批量创建VLAN 2到VLAN 5

    将连接PC的接口加入相应VLAN。

    [SW1] interface gigabitethernet 1/0/2
    [SW1-GigabitEthernet1/0/2] port link-type trunk //将与SW1相连接口的接口类型设置为trunk
    [SW1-GigabitEthernet1/0/2] port trunk allow-pass vlan 2 3 //透传VLAN 2和VLAN 3
    [SW1-GigabitEthernet1/0/2] quit
    [SW1] interface gigabitethernet 1/0/3
    [SW1-GigabitEthernet1/0/3] port link-type access //将与PC3相连接口的接口类型设置为access
    [SW1-GigabitEthernet1/0/3] port default vlan 4 //将PC3划分到VLAN 4
    [SW1-GigabitEthernet1/0/3] quit

    配置VLANIF接口,作为用户PC的网关。

    [SW1] interface vlanif 2 //创建VLANIF2接口
    [SW1-Vlanif2] ip address 192.168.2.1 24 //配置IP地址,此IP地址是PC1的网关地址
    [SW1-Vlanif2] quit
    [SW1] interface vlanif 3 //创建VLANIF3接口
    [SW1-Vlanif3] ip address 192.168.3.1 24 //配置IP地址,此IP地址是PC2的网关地址
    [SW1-Vlanif3] quit
    [SW1] interface vlanif 4 //创建VLANIF4接口
    [SW1-Vlanif4] ip address 192.168.4.1 24 //配置IP地址,此IP地址是PC3的网关地址
    [SW1-Vlanif4] quit

    将连接路由器的接口加入相应VLAN。

    [SW1] interface gigabitethernet 1/0/1
    [SW1-GigabitEthernet1/0/1] port link-type access //将与路由器相连接口的接口类型设置为access,与路由器通过Untagged方式通信
    [SW1-GigabitEthernet1/0/1] port default vlan 5 //将路由器划分到VLAN 5
    [SW1-GigabitEthernet1/0/1] quit

    配置VLANIF接口,实现和路由器的互连。

    [SW1] interface vlanif 5 //创建VLANIF5接口
    [SW1-Vlanif5] ip address 192.168.5.1 24 //配置IP地址,此IP地址是与路由器对接的IP地址
    [SW1-Vlanif5] quit

  2. 检查配置结果
    PC1、PC2、PC3之间可以相互访问,同时PC都可以和路由器进行通信。
    配置文件
    SW1的配置文件
    #
    sysname SW1
    #
    vlan batch 2 to 5
    #
    interface Vlanif2
    ip address 192.168.2.1 255.255.255.0
    #
    interface Vlanif3
    ip address 192.168.3.1 255.255.255.0
    #
    interface Vlanif4
    ip address 192.168.4.1 255.255.255.0
    #
    interface Vlanif5
    ip address 192.168.5.1 255.255.255.0
    #
    interface GigabitEthernet1/0/1
    port link-type access
    port default vlan 5
    #
    interface GigabitEthernet1/0/2
    port link-type trunk
    port trunk allow-pass vlan 2 to 3
    #
    interface GigabitEthernet1/0/3
    port link-type access
    port default vlan 4
    #
    return

SW2的配置文件
#
sysname SW2
#
vlan batch 2 to 3
#
interface GigabitEthernet1/0/1
port link-type trunk
port trunk allow-pass vlan 2 to 3
#
interface GigabitEthernet1/0/23
port link-type access
port default vlan 2
#
interface GigabitEthernet1/0/24
port link-type access
port default vlan 3
#
return