华为三层交换机配置基于接口划分vlan
组网需求:汇聚层交换机做为 PC 电脑的网关,
PC3直连 SW2 属于 vlan 2,网关为 vlanif 2 接口地址192.168.2.1/24;
PC4直连 SW2 属于 vlan 3,网关为 vlanif 3 接口地址 192.168.3.1/24;
PC5直连 SW3 属于 vlan 4,网关为 vlanif 4 接口地址 192.168.4.1/24;
通过配置实现各PC 电脑之间的互访通信:
SW3不做配置即可
操作方法
- 01
创建 vlan <SW1> system-view //进入系统模式 [SW1] vlan batch 2 to 5 //批量新建 vlan 2 到 5
- 02
把接口加入相应 vlan,并配置端口属性。 # SW1----SW2---PC,接口配置成 trunk 模式 [SW1] interface GigabitEthernet 0/0/2 [SW1-GigabitEthernet0/0/2] port link-type trunk //链路类型为 trunk 模式[SW1-GigabitEthernet0/0/2] port trunk allow-pass vlan 2 to 3 [SW1-GigabitEthernet0/0/2] quit# SW1---SW3---PC,接口配置成 access 模式 [SW1] interface GigabitEthernet0/0/3 [SW1-GigabitEthernet0/0/3] port link-type access //链路类型为 access[SW1-GigabitEthernet0/0/3] port default vlan 4 [SW1-GigabitEthernet0/0/3] quit
- 03
配置 IP 地址做为 PC 电脑的网关 [SW1] interface Vlanif 2 //进入三层 vlanif2 接口[SW1-Vlanif2] ip address 192.168.2.1 255.255.255.0 //配置 ip 地址 [SW1-Vlanif2] quit //退出 vlanif2 接口 [SW1] interface Vlanif 3 [SW1-Vlanif3] ip address 192.168.3.1 255.255.255.0 [SW1-Vlanif3] quit [SW1] interface Vlanif 4 [SW1-Vlanif4] ip address 192.168.4.1 255.255.255.0 [SW1-Vlanif4] quit
- 04
配置 ip 地址实现和 R 路由器互联 [SW1] interface Vlanif 5 [SW1-Vlanif5] ip address 192.168.5.1 24 //对接 R 路由器的互联 IP 地址配置完成后保存配置 <SW1> save
- 05
创建 vlan<Huawei> system-view //进入系统模式[Huawei] sysname SW2 //修改系统名从 [SW2] vlan batch 2 3 //新建 vlan 2 3接口 透传 vlan# SW2----SW1,接口配置成 trunk 模式 [SW2] interface GigabitEthernet0/0/1 [SW2-GigabitEthernet0/0/1] port link-type trunk //配置链路类型为 trunk [SW2-GigabitEthernet0/0/1] port trunk allow-pass vlan 2 to 3 [SW2-GigabitEthernet0/0/1] quit
- 06
SW2---PC,接口需要配置成 access 模式 [SW2] interface GigabitEthernet0/0/23 //对接 PC1 [SW2-GigabitEthernet0/0/23] port link-type access //链路类型为 access[SW2-GigabitEthernet0/0/23] port default vlan 2 [SW2-GigabitEthernet0/0/23] quit [SW2] interface GigabitEthernet0/0/24 //对接 PC2 [SW2-GigabitEthernet0/0/24] port link-type access [SW2-GigabitEthernet0/0/24] port default vlan 3 [SW2-GigabitEthernet0/0/24] quit <SW2> save
- 07
此时PC3和PC4能够互通,和PC5不能够互通,验证一下