加入VLAN前,需要修改接口的链路类型
一、修改接口的链路类型
接口的链路类型总共有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
二、接口加入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时,一次最多可以输入10个不连续的VLAN或VLAN段,超过10个可以多次使用该命令进行配置。例如:vlan batch 10 15 to 19 25 28 to 30 一共是4个不连续的VLAN段。
四、接口批量加入VLAN
通过端口组可以把接口批量加入VLAN;对于Access接口,还可以在VLAN视图下直接批量将接口加入VLAN。
access接口类型。
通过端口组批量将接口加入VLAN
<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
在VLAN视图下批量将接口加入VLAN<HUAWEI>system-view
[HUAWEI] vlan 10
[HUAWEI-vlan10] port gigabitethernet 1/0/1 to 1/0/5 //批量把端口gigabitethernet1/0/1 to gigabitethernet1/0/5加入VLAN10
注:
执行此操作前,须先将所有要批量加入VLAN的接口的接口类型配置为access。
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 1/0/1
[HUAWEI-GigabitEthernet1/0/1] undo port default vlan
恢复trunk接口的缺省配置。
<HUAWEI>system-view
[HUAWEI] interface gigabitethernet 1/0/1
[HUAWEI-GigabitEthernet1/0/1] undo port trunk pvid vlan
[HUAWEI-GigabitEthernet1/0/1] undo port trunk allow-pass vlan all
[HUAWEI-GigabitEthernet1/0/1] port trunk pvid vlan 1
恢复hybrid接口的缺省配置。
<HUAWEI>system-view
[HUAWEI] interface gigabitethernet 1/0/1
[HUAWEI-GigabitEthernet1/0/1] undo port hybrid pvid vlan
[HUAWEI-GigabitEthernet1/0/1] undo port hybrid vlan all
[HUAWEI-GigabitEthernet1/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
注:
V200R005之前版本,如果VLAN已经绑定VLANIF接口,删除VLAN之前必须使用undo interface vlanif命令删除对应的VLANIF接口。
六、使用Access和Trunk接口连接用户主机
如图所示,PC划分在VLAN 10中,通过接入交换机SwitchA上行接入汇聚交换机SwitchB。
配置接入交换机SwitchA。
<HUAWEI>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。
<HUAWEI>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接口连接用户主机
如图所示,PC划分在VLAN 10中,通过接入交换机SwitchA上行接入汇聚交换机SwitchB。
配置接入交换机SwitchA。
<HUAWEI>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。<HUAWEI>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