VLAN配置示例
示例1
PC1与PC3属于 VLAN10
PC2与PC4属于 VLAN20
配置完成后,PC1与PC3能够互通,PC2与PC4能够互通。但PC1与PC2,PC3与PC4不能互通。
PC1 192.168.1.10 255.255.255.0
PC2 192.168.1.20 255.255.255.0
PC3 192.168.1.30 255.255.255.0
PC4 192.168.1.40 255.255.255.0
SW1
<Huawei>system-view
[Huawei]undo info-center enable #关闭信息提示 #若再启用,输入info-center enable命令
Info: Information center is disabled.
#不能添加Hybrid 混合端口,需要将端口模式改为access模式才可以继续
[Huawei]vlan 10
[Huawei-vlan10]port GigabitEthernet 0/0/1
Error: Trunk or Hybrid port(s) can not be added or deleted in this manner.
[Huawei]interface GigabitEthernet 0/0/1
[Huawei-GigabitEthernet0/0/1]port link-type access
[Huawei-GigabitEthernet0/0/1]quit
[Huawei]
[Huawei]interface GigabitEthernet 0/0/2
[Huawei-GigabitEthernet0/0/2]port link-type access
[Huawei-GigabitEthernet0/0/2]quit
[Huawei]vlan 10
[Huawei-vlan10]port GigabitEthernet 0/0/1
[Huawei-vlan10]quit
[Huawei]vlan 20
[Huawei-vlan20]port GigabitEthernet 0/0/2
[Huawei-vlan20]quit
[Huawei]interface GigabitEthernet 0/0/3
[Huawei-GigabitEthernet0/0/3]port link-type trunk #配置端口的链路类型为Trunk类型
[Huawei-GigabitEthernet0/0/3]port trunk all
[Huawei-GigabitEthernet0/0/3]port trunk allow-pass vlan 10 20 #允许指定VLAN通过当前Trunk端口
[Huawei-GigabitEthernet0/0/3]
SW2
<Huawei>system-view
[Huawei]undo info-center enable
[Huawei]interface GigabitEthernet 0/0/2
[Huawei-GigabitEthernet0/0/2]port link-type access
[Huawei-GigabitEthernet0/0/2]quit
[Huawei]interface GigabitEthernet 0/0/3
[Huawei-GigabitEthernet0/0/3]port link-type access
[Huawei-GigabitEthernet0/0/3]quit
[Huawei]vlan 10
[Huawei-vlan10]port GigabitEthernet 0/0/2
[Huawei-vlan10]quit
[Huawei]vlan 20
[Huawei-vlan20]port GigabitEthernet 0/0/3
[Huawei-vlan20]quit
[Huawei]interface GigabitEthernet 0/0/1
[Huawei-GigabitEthernet0/0/1]port link-type trunk
[Huawei-GigabitEthernet0/0/1]port trunk allow-pass vlan 10 20
示例2
配置SW1
<Huawei>system-view
[Huawei]undo info-center enable
[Huawei]interface Vlanif1
[Huawei-Vlanif1]ip address 192.168.1.100 24
[Huawei-Vlanif1] User interface con0 is available
配置SW2
<Huawei>system-view
[Huawei]undo info-center enable
[Huawei]interface Vlanif 2
Error: The VLAN does not exist.
[Huawei]vlan 2
[Huawei-vlan2]quit
[Huawei]interface Vlanif 2
[Huawei-Vlanif2]ip address 192.168.2.200 24
配置路由器
<Huawei>system-view
[Huawei]undo info-center enable
[Huawei]interface GigabitEthernet 0/0/0
[Huawei-GigabitEthernet0/0/0]ip address 192.168.1.111 24
[Huawei-GigabitEthernet0/0/0]quit
[Huawei]
[Huawei]interface GigabitEthernet 0/0/1
[Huawei-GigabitEthernet0/0/1]ip address 192.168.2.222 24
[Huawei-GigabitEthernet0/0/1]
示例3
1.基础配置
PC1 10.1.1.1 255.255.255.0
PC2 10.1.1.2 255.255.255.0
PC3 10.1.1.3 255.255.255.0
PC4 10.1.1.4 255.255.255.0
2.创建VLAN,配置Access接口
开发组属于VLAN 10
运维组属于VLAN 20
SW1,SW2,SW3 分别执行如下命令
<Huawei>system-view
[Huawei]undo info-center enable
[Huawei]vlan 10
[Huawei-vlan10]description R$D
[Huawei-vlan10]quit
[Huawei]vlan 20
[Huawei-vlan20]description Market
3. SW1,SW2配置Access接口,并划分相应的VLAN
SW1
[Huawei]interface Ethernet 0/0/2
[Huawei-Ethernet0/0/2]port link-type access
[Huawei-Ethernet0/0/2]port default vlan 10
[Huawei-Ethernet0/0/2]quit
[Huawei]interface Ethernet 0/0/3
[Huawei-Ethernet0/0/3]port link-type access
[Huawei-Ethernet0/0/3]port default vlan 20
SW2
[Huawei]interface Ethernet 0/0/3
[Huawei-Ethernet0/0/3]port link-type access
[Huawei-Ethernet0/0/3]port default vlan 10
[Huawei-Ethernet0/0/3]quit
[Huawei]interface Ethernet 0/0/4
[Huawei-Ethernet0/0/4]port link-type access
[Huawei-Ethernet0/0/4]port default vlan 20
4.配置Trunk接口
此时PC1 ping不通 PC3
在SW1配置E0/0/1为Trunk口,允许VLAN10和VLAN20通过。
[Huawei]interface Ethernet 0/0/1
[Huawei-Ethernet0/0/1]port link-type trunk
[Huawei-Ethernet0/0/1]port trunk allow-pass vlan 10 20
[Huawei-Ethernet0/0/1]
在SW2配置E0/0/1为Trunk口,允许VLAN10和VLAN20通过。
[Huawei]interface Ethernet 0/0/1
[Huawei-Ethernet0/0/1]port link-type trunk
[Huawei-Ethernet0/0/1]port trunk allow-pass vlan 10 20
[Huawei-Ethernet0/0/1]
在SW3配置GE 0/0/1和0/0/2 配置为Trunk接口,允许所用VLAN通过。
[Huawei]interface GigabitEthernet 0/0/1
[Huawei-GigabitEthernet0/0/1]port link-type trunk
[Huawei-GigabitEthernet0/0/1]port trunk allow-pass vlan all
[Huawei-GigabitEthernet0/0/1]quit
[Huawei]interface gigabitEthernet 0/0/2
[Huawei-GigabitEthernet0/0/2]port link-type trunk
[Huawei-GigabitEthernet0/0/2]port trunk allow-pass vlan all
[Huawei-GigabitEthernet0/0/2]quit
此时PC1pingPC3
示例4
1.分别在S1交换机上,创建VLAN10和VLAN20。(S2也执行此步)
vlan batch 10 20
2.进入进入GigabitEthernet 0/0/2接口,配置接口的链路类型,
然后配置Access类型接口加入VLAN10。GigabitEthernet 0/0/3接口的配置同GigabitEthernet 0/0/2接口
[S1]interface GigabitEthernet0/0/2
[S1-GigabitEthernet0/0/2]port link-type access
[S1-GigabitEthernet0/0/2]port default vlan 10
[S1-GigabitEthernet0/0/2]quit
[S1]
[S1]interface GigabitEthernet0/0/3
[S1-GigabitEthernet0/0/3]port link-type access
[S1-GigabitEthernet0/0/3]port default vlan 10
[S1-GigabitEthernet0/0/3]quit
3.进入GigabitEthernet 0/0/4接口,配置接口的链路类型,然后配置Access类型接口加入VLAN20
[S1]interface GigabitEthernet0/0/4
[S1-GigabitEthernet0/0/4]port link-type access
[S1-GigabitEthernet0/0/4]port default vlan 20
[S1-GigabitEthernet0/0/4]quit
4.进入GigabitEthernet 0/0/1接口,配置接口的链路类型,然后配置Trunk类型接口加入VLAN10和VLAN20
[S1]interface GigabitEthernet0/0/1
[S1-GigabitEthernet0/0/1]port link-type trunk
[S1-GigabitEthernet0/0/1]port trunk allow-pass vlan 10 20
[S1-GigabitEthernet0/0/1]quit
5.S2交换机
<Huawei>system-view
[Huawei]sysname S2
[S2]
[S2]interface GigabitEthernet0/0/2
[S2-GigabitEthernet0/0/2]quit
[S2]vlan batch 10 20
Info: This operation may take a few seconds. Please wait for a moment...done.
[S2]interface GigabitEthernet0/0/2
[S2-GigabitEthernet0/0/2]port link-type access
[S2-GigabitEthernet0/0/2]port default vlan 10
[S2-GigabitEthernet0/0/2]quit
[S2]
[S2]interface GigabitEthernet0/0/3
[S2-GigabitEthernet0/0/3]port link-type access
[S2-GigabitEthernet0/0/3]port default vlan 20
[S2-GigabitEthernet0/0/3]quit
[S2]
[S2]interface GigabitEthernet0/0/1
[S2-GigabitEthernet0/0/1]port link-type trunk
[S2-GigabitEthernet0/0/1]port trunk allow-pass vlan 10 20
[S2-GigabitEthernet0/0/1]quit
PC1 ping PC4
三层交换机可以充当路由器的作用,在LSW2交换机上配置VLAN10和VLAN20的IP地址(网关),实现两台交换机上的VLAN间能够通信。
[S2]interface Vlanif 10
[S2-Vlanif10]ip address 192.168.10.1 24
[S2-Vlanif10]quit
[S2]interface Vlanif 20
[S2-Vlanif20]ip address 192.168.30.1 24
[S2-Vlanif20]quit
[S2]