接口加入VLAN
接口加入VLAN之前,需要在接口上设置对应的链路类型。具体请参见“修改接口的链路类型”。
- Access接口加入VLAN <HUAWEI> system-view [HUAWEI] interface gigabitethernet0/0/1 [HUAWEI-GigabitEthernet0/0/1] port link-type access //设置接口的链路类型为Access [HUAWEI-GigabitEthernet0/0/1] port default vlan 10 //把接口GigabitEthernet0/0/1加入VLAN 10
- Trunk接口加入VLAN <HUAWEI> system-view [HUAWEI] interface gigabitethernet0/0/1 [HUAWEI-GigabitEthernet0/0/1] port link-type trunk //设置接口的链路类型为Trunk [HUAWEI-GigabitEthernet0/0/1] port trunk allow-pass vlan 10 //把接口GigabitEthernet0/0/1加入VLAN 10
- Hybrid接口加入VLAN <HUAWEI> system-view [HUAWEI] interface gigabitethernet0/0/1 [HUAWEI-GigabitEthernet0/0/1] port link-type hybrid //设置接口的链路类型为Hybrid [HUAWEI-GigabitEthernet0/0/1] port hybrid tagged vlan 10 //接口GigabitEthernet0/0/1以Tagged方式加入VLAN 10 [HUAWEI-GigabitEthernet0/0/1] port hybrid untagged vlan 20 //接口GigabitEthernet0/0/1以Untagged方式加入VLAN 20
- QinQ接口加入VLAN <HUAWEI> system-view [HUAWEI] interface gigabitethernet0/0/1 [HUAWEI-GigabitEthernet0/0/1] port link-type dot1q-tunnel //设置接口的链路类型为QinQ [HUAWEI-GigabitEthernet0/0/1] port default vlan 10 //接口GigabitEthernet0/0/1加入VLAN 10
批量创建VLAN
系统视图下执行命令vlan batch,批量创建VLAN。
- 批量创建10个连续的VLAN:VLAN11到VLAN20。 <HUAWEI> system-view [HUAWEI] vlan batch 11 to 20
- 批量创建10不连续的VLAN:VLAN10、VLAN15到VLAN19、VLAN25、VLAN28到VLAN30。 <HUAWEI> system-view [HUAWEI] vlan batch 10 15 to 19 25 28 to 30
接口批量加入VLAN
通过端口组,可以把接口批量加入VLAN。
- access接口类型。 <HUAWEI> system-view [HUAWEI] port-group pg1 //创建端口组pg1 [HUAWEI-port-group-pg1] group-member gigabitethernet1/0/1 to gigabitethernet1/0/5 //把接口gigabitethernet1/0/1到gigabitethernet1/0/5加入端口组 [HUAWEI-port-group-pg1] port link-type access //批量修改端口gigabitethernet1/0/1 to gigabitethernet1/0/5的链路类型为access [HUAWEI-port-group-pg1] port default vlan 10 //批量把端口gigabitethernet1/0/1 to gigabitethernet1/0/5加入VLAN10
- trunk接口类型。 <HUAWEI> system-view [HUAWEI] port-group pg1 //创建端口组pg1 [HUAWEI-port-group-pg1] group-member gigabitethernet1/0/1 to gigabitethernet1/0/5 //把接口gigabitethernet1/0/1到gigabitethernet1/0/5加入端口组 [HUAWEI-port-group-pg1] port link-type trunk //批量修改端口gigabitethernet1/0/1 to gigabitethernet1/0/5的链路类型为trunk [HUAWEI-port-group-pg1] port trunk allow-pass vlan 10 20 //批量把端口gigabitethernet1/0/1 to gigabitethernet1/0/5加入VLAN10和VLAN20
- hybrid接口类型。 <HUAWEI> system-view [HUAWEI] port-group pg1 //创建端口组pg1 [HUAWEI-port-group-pg1] group-member gigabitethernet1/0/1 to gigabitethernet1/0/5 //把接口gigabitethernet1/0/1到gigabitethernet1/0/5加入端口组 [HUAWEI-port-group-pg1] port link-type hybrid //批量修改端口gigabitethernet1/0/1 to gigabitethernet1/0/5的链路类型为hybrid [HUAWEI-port-group-pg1] port hybrid tagged vlan 10 //批量把端口gigabitethernet1/0/1 to gigabitethernet1/0/5以tagged方式加入VLAN10 [HUAWEI-port-group-pg1] port hybrid untagged vlan 20 //批量把端口gigabitethernet1/0/1 to gigabitethernet1/0/5 以untagged方式加入VLAN20
恢复接口下VLAN的缺省配置
接口下VLAN的缺省配置包括接口的PVID和接口缺省加入VLAN1。
- 恢复access接口的缺省配置。 <HUAWEI> system-view [HUAWEI] interface gigabitethernet 0/0/1 [HUAWEI-GigabitEthernet0/0/1] undo port default vlan
- 恢复trunk接口的缺省配置。 <HUAWEI> system-view [HUAWEI] interface gigabitethernet 0/0/1 [HUAWEI-GigabitEthernet0/0/1] undo port trunk pvid vlan [HUAWEI-GigabitEthernet0/0/1] undo port trunk allow-pass vlan all [HUAWEI-GigabitEthernet0/0/1] port trunk pvid vlan 1
- 恢复hybrid接口的缺省配置。 <HUAWEI> system-view [HUAWEI] interface gigabitethernet 0/0/1 [HUAWEI-GigabitEthernet0/0/1] undo port hybrid pvid vlan [HUAWEI-GigabitEthernet0/0/1] undo port hybrid vlan all [HUAWEI-GigabitEthernet0/0/1] port hybrid untagged vlan 1
删除VLAN
设备支持删除批量VLAN和删除单个VLAN两种方式。
- 删除单个VLAN10。 <HUAWEI> system-view [HUAWEI] undo vlan 10
- 删除批量VLAN10到VLAN20。 <HUAWEI> system-view [HUAWEI] undo vlan batch 10 to 20
修改接口的链路类型
接口的链路类型总共有4种,分别为:Access、Trunk、Hybrid、Dot1q-tunnel。不同版本,接口类型的修改方法不同。
- V200R005及后续版本:直接执行命令port link-type { access | trunk | hybrid | dot1q-tunnel },然后根据提示输入“y”或“n”。当接口上VLAN的配置为缺省配置时,不会出现提示信息,会直接修改链路类型。
- 若输入“y”后回车,设备会自动删除接口上VLAN的非默认配置,然后设置接口的链路类型为指定的类型。
- 若输入“n”后回车,设备不做任何处理,保持当前的链路类型和接口上的VLAN配置不变。
- 例如:将接口类型修改为Hybrid。
<HUAWEI> system-view [HUAWEI] interface gigabitethernet0/0/1 [HUAWEI-GigabitEthernet0/0/1] port link-type hybrid Warning: This command will delete VLANs on this port. Continue?[Y/N]:y Info: This operation may take a few seconds. Please wait for a moment...done.
- V200R005以前版本:当接口上VLAN的缺省配置为默认加入VLAN 1,并且PVID为VLAN 1,可以执行命令port link-type { access | trunk | hybrid | dot1q-tunnel },修改接口类型。
- 将接口类型修改为Access <HUAWEI> system-view [HUAWEI] interface gigabitethernet0/0/1 [HUAWEI-GigabitEthernet0/0/1] port link-type access [HUAWEI-GigabitEthernet0/0/1] port default vlan 10 //设置接口的PVID为VLAN 10,并同时将VLAN 10加入接口
- 将接口类型修改为Trunk <HUAWEI> system-view [HUAWEI] interface gigabitethernet0/0/1 [HUAWEI-GigabitEthernet0/0/1] port link-type trunk [HUAWEI-GigabitEthernet0/0/1] port trunk pvid vlan 10 //设置接口的PVID为VLAN 10 [HUAWEI-GigabitEthernet0/0/1] port trunk allow-pass vlan 2 10 20 //将VLAN 2、VLAN 10和VLAN 20加入接口
- 将接口类型修改为Hybrid <HUAWEI> system-view [HUAWEI] interface gigabitethernet0/0/1 [HUAWEI-GigabitEthernet0/0/1] port link-type hybrid [HUAWEI-GigabitEthernet0/0/1] port hybrid pvid vlan 10 //设置接口的PVID为VLAN 10 [HUAWEI-GigabitEthernet0/0/1] port hybrid untagged vlan 2 10 //将接口以Untagged方式加入VLAN 2和VLAN 10 [HUAWEI-GigabitEthernet0/0/1] port hybrid tagged vlan 20 //将接口以Tag方式加入VLAN 20
- 将接口类型修改为Dot1q-tunnel <HUAWEI> system-view [HUAWEI] interface gigabitethernet0/0/1 [HUAWEI-GigabitEthernet0/0/1] port link-type dot1q-tunnel [HUAWEI-GigabitEthernet0/0/1] port default vlan 10 //设置接口的PVID为VLAN 10,对该接口收到的所有数据报文统一封装一层VLAN为10的Tag
在修改链路类型时,如果接口上VLAN的配置不是缺省值,会出现以下提示信息:Error: Please renew the default configurations.
此时需要先把接口上VLAN的配置恢复为缺省值,然后再修改链路类型。
- 恢复Access或Dot1q-tunnel接口上VLAN的缺省配置 <HUAWEI> system-view [HUAWEI] interface gigabitethernet0/0/1 [HUAWEI-GigabitEthernet0/0/1] undo port default vlan
- 恢复Trunk接口上VLAN的缺省配置 <HUAWEI> system-view [HUAWEI] interface gigabitethernet0/0/1 [HUAWEI-GigabitEthernet0/0/1] undo port trunk pvid vlan [HUAWEI-GigabitEthernet0/0/1] undo port trunk allow-pass vlan all [HUAWEI-GigabitEthernet0/0/1] port trunk allow-pass vlan 1
- 恢复Hybrid接口上VLAN的缺省配置 <HUAWEI> system-view [HUAWEI] interface gigabitethernet0/0/1 [HUAWEI-GigabitEthernet0/0/1] undo port hybrid pvid vlan [HUAWEI-GigabitEthernet0/0/1] undo port hybrid vlan all [HUAWEI-GigabitEthernet0/0/1] port hybrid untagged vlan 1
- 使用Access和Trunk接口连接用户主机
- # 配置接入交换机SwitchA。 <SwitchA> system-view [SwitchA] vlan batch 10 //如果不适用batch,会进入VLAN视图,需要执行quit命令退出该视图 [SwitchA] interface gigabitethernet0/0/1 [SwitchA-GigabitEthernet0/0/1] port link-type trunk //设置接口的链路类型为Trunk [SwitchA-GigabitEthernet0/0/1] port trunk allow-pass vlan 10 //把接口GigabitEthernet0/0/1加入VLAN 10 [SwitchA-GigabitEthernet0/0/1] quit [SwitchA] interface gigabitethernet0/0/2 [SwitchA-GigabitEthernet0/0/2] port link-type access //设置接口的链路类型为Access [SwitchA-GigabitEthernet0/0/2] port default vlan 10 //把接口GigabitEthernet0/0/2加入VLAN 10 [SwitchA-GigabitEthernet0/0/2] quit
- # 配置汇聚交换机SwitchB。 <SwitchB> system-view [SwitchB] vlan batch vlan 10 //如果不适用batch,会进入VLAN视图,需要执行quit命令退出该视图 [SwitchB] interface gigabitethernet0/0/1 [SwitchB-GigabitEthernet0/0/1] port link-type trunk //设置接口的链路类型为Trunk [SwitchB-GigabitEthernet0/0/1] port trunk allow-pass vlan 10 //把接口GigabitEthernet0/0/1加入VLAN 10 [SwitchB-GigabitEthernet0/0/1] quit
使用Hybrid接口连接用户主机
- # 配置接入交换机SwitchA。 <SwitchA> system-view [SwitchA] vlan batch 10 //如果不适用batch,会进入VLAN视图,需要执行quit命令退出该视图 [SwitchA] interface gigabitethernet0/0/1 [SwitchA-GigabitEthernet0/0/1] port link-type hybrid //设置接口的链路类型为Hybrid [SwitchA-GigabitEthernet0/0/1] port hybrid tagged vlan 10 //把接口GigabitEthernet0/0/1以Tagged方式加入VLAN 10 [SwitchA-GigabitEthernet0/0/1] quit [SwitchA] interface gigabitethernet0/0/2 [SwitchA-GigabitEthernet0/0/2] port link-type hybrid //设置接口的链路类型为Hybrid [SwitchA-GigabitEthernet0/0/2] port hybrid pvid vlan 10 //设置接口的PVID为VLAN 10 [SwitchA-GigabitEthernet0/0/2] port hybrid untagged vlan 10 //把接口GigabitEthernet0/0/2以Untagged方式加入VLAN 10 [SwitchA-GigabitEthernet0/0/2] quit
- # 配置汇聚交换机SwitchB。 <SwitchB> system-view [SwitchB] vlan batch 10 //如果不适用batch,会进入VLAN视图,需要执行quit命令退出该视图 [SwitchB] interface gigabitethernet0/0/1 [SwitchB-GigabitEthernet0/0/1] port link-type hybrid //设置接口的链路类型为Hybrid [SwitchB-GigabitEthernet0/0/1] port hybrid tagged vlan 10 //把接口GigabitEthernet0/0/1以Tagged方式加入VLAN 10 [SwitchB-GigabitEthernet0/0/1] quit