Switch Vlan实战

不同Vlan下实现网络互相通信

1
2
3
4
5
6
7
2种方式,进入接口操作
1. trunk
port link-type trunk
port trunk allow-pass vlan 10 20

2. pvid
port trunk pvid vlan 20 # 剥掉vlan 20数据标签进行转发
逻辑拓扑

命令配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<HuaWei>system-view            #切换系统视图
[Huawei]sysname test #将交换机命名为test
[test]vlan 10 #创建vlan 10
[test-vlan10]description test #为vlan 10描述为test
[test-vlan10]quit #退出

#接口配置
[test]interface Ethernet0/0/1 #进入e0/0/1接口
[test-Ethernet0/0/1]port link-type access #将e0/0/1接口链路类型设置为access
[test-Ethernet0/0/1]port default vlan 10 #将e0/0/1接口划分至vlan 10中
[test-Ethernet0/0/1]quit #退出

[test]interface e0/0/2 #进入e0/0/2接口;Ethernet0/0/2可简写
[test-Ethernet0/0/2]port link-type access #将e0/0/2接口链路类型设置为access
[test-Ethernet0/0/2]port default vlan 10 #将e0/0/2接口划分至vlan 10中
[test-Ethernet0/0/2]quit #退出

[test]interface e0/0/3 #进入e0/0/3接口
[test-Ethernet0/0/3]port link-type trunk #将e0/0/3接口链路类型设置为trunk
[test-Ethernet0/0/3]port trunk allow-pass vlan 10 #只允许vlan10数据通过



[test-Ethernet0/0/3]display port vlan #查看端口信息
Port Link Type PVID Trunk VLAN List
-------------------------------------------------------------------------------
Ethernet0/0/1 access 10 -
Ethernet0/0/2 access 10 -
Ethernet0/0/3 trunk 1 1 10
Ethernet0/0/4 hybrid 1 -
Ethernet0/0/5 hybrid 1 -
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<Huawei>system-view            #切换至系统视图
[Huawei]sysname technology #将交换机命名为technology
[technology]vlan 20 #创建vlan 20
[technology-vlan20]description technology #vlan 20描述为technology
[technology-vlan20]quit #退出

#接口配置
[technology]interface e0/0/1 #进入e0/0/1接口
[technology-Ethernet0/0/1]port link-type access #链路类型为access
[technology-Ethernet0/0/1]port default vlan 20 #划分至vlan 20
[technology-Ethernet0/0/1]quit #退出

[technology]interface e0/0/2 #进入e0/0/2接口
[technology-Ethernet0/0/2]port link-type access #链路类型为access
[technology-Ethernet0/0/2]port default vlan 20 #划分至vlan 20
[technology-Ethernet0/0/2]quit #退出

[technology]interface e0/0/3 #进入e0/0/3接口
[technology-Ethernet0/0/3]port link-type trunk #链路类型为trunk
[technology-Ethernet0/0/3]port trunk allow-pass vlan 20 #只允许vlan 20数据通过
[technology-Ethernet0/0/3]quit #退出

[technology]display port vlan #查询端口信息
Port Link Type PVID Trunk VLAN List
-------------------------------------------------------------------------------
Ethernet0/0/1 access 20 -
Ethernet0/0/2 access 20 -
Ethernet0/0/3 trunk 1 1 20
Ethernet0/0/4 hybrid 1 -
  • 测试

    1
    此时PC1和PC3之间是无法互相访问的
  • 配置pvid

    1
    2
    3
    4
    5
    6
    7
    8
    9
    SW1:
    [test]interface e0/0/3 #进入e0/0/3接口
    [test-Ethernet0/0/3]port trunk pvid vlan 10 #剥掉vlan 10数据标签进行转发
    [test-Ethernet0/0/3]display this #查询e0/0/3接口配置
    #
    interface Ethernet0/0/3
    port link-type trunk
    port trunk pvid vlan 10
    port trunk allow-pass vlan 10
1
2
3
4
SW2:
<technology>system-view #切换系统视图
[technology]interface e0/0/3 #进入接口视图
[technology-Ethernet0/0/3]port trunk pvid vlan 20 #剥掉vlan 20数据标签进行转发
  • 原理
1
2
3
4
5
6
- 在交换机内部端口间的通信,是必须带VLAN ID的,必须带标签!
- 默认情况,所有端口都在VLAN 1中,即所有端口 PVID = 1
- PVID 一个端口可以属于多个VLAN,但只能有一个PVID
- acess端口收到不带tag的帧,打上pvid,进入交换机
- trunk端口,收到不带tag的帧,打上pvid,进入交换机
- trunk端口,发送 vid=PVID 的帧,剥离tag后发送,此时,该帧就变成网卡可以识别的帧
配置pvid后验证
1
pc1可以和pc3互通

也可以在trunk allow里继续添加需要允许的vlan

-------------本文结束感谢您的阅读-------------
原创技术分享,感谢您的支持。