首先创建拓扑
编辑交换机配置
<Huawei>sy
Enter system view, return user view with Ctrl+Z.
[Huawei]undo info-center en 关闭命令提示
Info: Information center is disabled.
[Huawei]sy sw1 修改名字
[sw1]vlan batch 10 20 创建vlan10,20
Info: This operation may take a few seconds. Please wait for a moment...done.
[sw1]int e0/0/2 进入接口
[sw1-Ethernet0/0/2]port link-type access 设置接口类型为access
[sw1-Ethernet0/0/2]port defa vlan 10 给接口划分vlan
[sw1-Ethernet0/0/2]int e0/0/1
[sw1-Ethernet0/0/1]port link-type access
[sw1-Ethernet0/0/1]port defa vlan 20
[sw1-Ethernet0/0/1]int g0/0/1
[sw1-GigabitEthernet0/0/1]port link-type trunk 设置接口类型为trunk
[sw1-GigabitEthernet0/0/1]port trunk all vlan all 允许所有vlan通过
路由器配置
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]undo info-center en 关闭命令提示
Info: Information center is disabled.
[Huawei]sys r1 修改名字
[r1]int g0/0/0.1 进入子接口
[r1-GigabitEthernet0/0/0.1]vlan-type dot1q 10 default 配置vlan10
[r1-GigabitEthernet0/0/0.1]ip add 192.168.10.254 24 配置vlan10网关
[r1-GigabitEthernet0/0/0.1]int g0/0/0.2
[r1-GigabitEthernet0/0/0.2]vlan-type dot1q 20 default
[r1-GigabitEthernet0/0/0.2]ip add 192.168.20.254 24
pc配置
进行验证
上述代码多数是简写,大家可以按Tab键补全,如有不懂可以私信博主