三层交换机vlan通信.png

注意点:

        交换机之间接口模式为trunk;

        交换机与PC之间接口模式为access;

        每个交换机都要划分相同的vlan;

S1:

<Huawei>sy
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname S1 # 改名
[S1]undo info-center enable # 关闭消息提示
Info: Information center is disabled.
[S1]interface GigabitEthernet 0/0/1 # 进入端口g0/0/1
[S1-GigabitEthernet0/0/1]port link-type trunk # 设置当前端口为trunk
[S1-GigabitEthernet0/0/1]port trunk allow-pass vlan all # 允许当前端口通过所有vlan
[S1-GigabitEthernet0/0/1]int g0/0/2 # 进入端口g0/0/2
[S1-GigabitEthernet0/0/2]port link-type trunk # 设置当前端口为trunk
[S1-GigabitEthernet0/0/2]port trunk allow-pass vlan all # 允许当前端口通过所有vlan
[S1]vlan batch 10 20 # 创建vlan
Info: This operation may take a few seconds. Please wait for a moment...done.	
[S1]interface Vlanif 10 # 进入vlan10
[S1-Vlanif10]ip address 192.168.199.1 24 # 设置vlan ip地址,作为路由使用
[S1-Vlanif10]quit	
[S1]interface Vlanif 20
[S1-Vlanif20]ip address 192.168.198.1 24
[S1-Vlanif20]quit

S2:

<Huawei>sy
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname S2 # 改名
[S2]	
[S2]undo info-center enable # 关闭消息提示
Info: Information center is disabled.
[S2]vlan batch 10 20 # 创建两个vlan
Info: This operation may take a few seconds. Please wait for a moment...done.
[S2]
[S2]interface Ethernet 0/0/1 # 进入e0/0/1 端口	
[S2-Ethernet0/0/1]port link-type access  # 设置端口模式
[S2-Ethernet0/0/1]port default vlan 10 # 将当前端口划分到vlan 10
[S2-Ethernet0/0/1]quit # 退出当前接口
[S2]
[S2]interface GigabitEthernet 0/0/1 # 进入g0/0/1 接口
[S2-GigabitEthernet0/0/1]port link-type trunk # 和交换机相连的接口要设置为trunk模式	
[S2-GigabitEthernet0/0/1]port trunk allow-pass vlan all # 允许所有vlan通过
[S2]

S3:

<Huawei>sy
[Huawei]sysname S3 # 改名
[S3]
[S3]undo info-center enable # 关闭消息提示
Info: Information center is disabled.
[S3]vlan batch 10 20 # 创建两个vlan
[S3]interface Ethernet 0/0/1 # 进入e0/0/1端口
[S3-Ethernet0/0/1]port link-type access # 设置端口模式
[S3-Ethernet0/0/1]port default vlan 20 # 将e0/0/1端口划分到vlan20
[S3-Ethernet0/0/1]int g0/0/1 # 进入g0/0/1接口
[S3-GigabitEthernet0/0/1]port link-type trunk # 设置接口模式,这个接口接的是路由器要设置为trunk
[S3-GigabitEthernet0/0/1]port trunk allow-pass vlan all # 允许所有vlan通过

然后就可以ping通了。