一、实验拓扑图
二、配置实验
1、交换机配置
<Huawei>system-view
[Huawei]sysname SWA
[SWA]vlan batch 2 3
交换机改名,新建vlan 2 和 vlan 3
[SWA]interface Eth0/0/1
[SWA-Ethernet0/0/1]port link-type access
[SWA-Ethernet0/0/1]port default vlan 2
[SWA-Ethernet0/0/1]q
[SWA]interface Eth0/0/11
[SWA-Ethernet0/0/11]port link-type access
[SWA-Ethernet0/0/11]port default vlan 3
[SWA-Ethernet0/0/11]q
把交换机端口添加到对应的vlan中
[SWA]interface GigabitEthernet 0/0/1
[SWA-GigabitEthernet0/0/1]port link-type trunk
[SWA-GigabitEthernet0/0/1]port trunk allow-pass vlan 2 3
[SWA-GigabitEthernet0/0/1]q
[SWA]
把g0/0/1端口设置为trunk,并允许vlan 2和vlan 3通过
2、路由器配置
<Huawei>system-view
[Huawei]sysname RA
更改路由器名字
[RA]interface GigabitEthernet 0/0/1.1
[RA-GigabitEthernet0/0/1.1]dot1q termination vid 2
[RA-GigabitEthernet0/0/1.1]ip address 192.168.1.254 24
[RA-GigabitEthernet0/0/1.1]arp broadcast enable
[RA-GigabitEthernet0/0/1.1]q
[RA]interface GigabitEthernet 0/0/1.2
[RA-GigabitEthernet0/0/1.2]dot1q termination vid 3
[RA-GigabitEthernet0/0/1.2]ip address 192.168.2.254 24
[RA-GigabitEthernet0/0/1.2]arp broadcast enable
[RA-GigabitEthernet0/0/1.2]
创建子接口,把pc的网关设置为子接口的IP地址,同时对应vlan
三、测试通信
成功通信