目录
1. vlan的概念
1.2 以太网帧的格式:
2.vlan类型
2.1 vlan转发规则
3. vlan的实际应用
3.1 简单的vlan划分通信
3.2 VLAN的划分方式
3.2.1 基于MAC地址的vlan划分
3.2.2 基于IP地址子网的划分
3.2.3 基于协议类型的子网划分
3.2.4 基于策略的vlan划分
3.3 vlan的进一步应用(结合路由器)
3.3.1 单臂路由解决方案配置
3.3.2通过三层交换机实现vlan间路由(现在的主流方案)
vlan(Virtual Local Area Network)即虚拟局域网,是将一个物理的局域网在逻辑上划分成多个广播域的技术。通过在交换机上配置VLAN,可以实现在同一个VLAN内的用户可以进行二层互访,而不同VLAN间的用户被二层隔离。这样既能够隔离广播域,又能够提升网络的安全性。
vlan帧
在现有的交换网络环境中,以太网的帧有两种格式:
没有加上VLAN标记的以太网帧(untagged frame);有VLAN标记的以太网帧(tagged frame)
vlan分为四种类型:
①access 在交换机与PC之间,接入链路,单独绑定一个vlan
②trunk 在交换机与交换机之间,主干链路,允许多个vlan通过
③hybrid 混杂模式,适用于access和trunk
④dot1q
PC并不能识别vlan标签,在交换机传递帧给PC时,需要将vlan标签剥离。在交换机间传输则不需要剥离vlan标签。交换机根据不同的vlan标签转发给相应的vlan。
Access口只有一个untagged list;Trunk口有tagged list和一个untagged list(为端口的PVID);Hybrid口有tagged list和多个untagged list。
Access口转发规则:
Access端口接收到帧时,如果该帧不包含Tag,则打上端口的PVID标记;如果该帧包含Tag,则与接收端口的vlan ID比较,若相同,则接收并进行转发;若不相同,则直接丢弃。
Access端口发送帧时,农历标签进行转发
Trunk端口转发规则:
Trunk端口接收到帧时,如果该帧不包含Tag,将打上端口的PVID标记(默认为VLAN 1 );如果 该帧包含Tag(例如vlan 10),则不改变。
Trunk端口发送帧时,该帧的VLAN ID在Trunk允许通过的VALN列表中,如果与端口的PVID相同,则在剥离Tag后发送(vlan 1,本征vlan );如果不同,则直接发送(比如vlan20,已打tag),不做处理;
Trunk接口的入方向:
①Trunk接口收到一个无标签的数据帧,会打上接口PVID的vlan标签
②Trunk接口收到一个带标签的数据帧,将标签中的VLAN ID和端口允许通过的VALN列表作比对,如果允许通过则接收该数据帧;否则,丢弃该数据帧
Trunk接口的出方向:
①Trunk端口转发一个带标签的数据帧,将标签中的VLAN ID和允许通过的VLAN列表(tagged list)进行比对,如果允许通过则转发该数据帧(如果在tagged list里,则不剥离标签转发;如果在untagged list里面,则剥离标签进行转发);否则,丢弃该数据帧。(注:如果Trunk端口不允许一个vlan通过,那么该Trunk端口也不会出现在vlan的MAC地址表中,华为设备端口默认只通过vlan 1 )
access口和trunk口可以有一个属于untagglist的vlan,hybrid口可以有多个属于untagglist的vlan
实验目的:配置PC1与PC3为vlan 1,PC2与PC4为vlan2(各个PC默认vlan为1)
配置交换机
[SW]vlan batch 20 to 30
[sw1]int e0/0/1
[sw1-Ethernet0/0/1]port link-type access
[sw1-Ethernet0/0/1]display port vlan active
T=TAG U=UNTAG
-------------------------------------------------------------------------------
Port Link Type PVID VLAN List
-------------------------------------------------------------------------------
Eth0/0/1 access 1 U: 1
Eth0/0/2 hybrid 1 U: 1
Eth0/0/3 hybrid 1 U: 1
Eth0/0/4 hybrid 1 U: 1
[sw1-Ethernet0/0/1]int e0/0/3
[sw1-Ethernet0/0/3]port link-type access
[sw1-Ethernet0/0/3]dis port vlan acti
Jul 12 2020 00:05:25-08:00 sw1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 8, the c
hange loop count is 0, and the maximum number of records is 40
T=TAG U=UNTAG
-------------------------------------------------------------------------------
Port Link Type PVID VLAN List
-------------------------------------------------------------------------------
Eth0/0/1 access 1 U: 1
Eth0/0/2 hybrid 1 U: 1
Eth0/0/3 access 1 U: 1
Eth0/0/4 hybrid 1 U: 1
[sw1-Ethernet0/0/3]int e0/0/2
[sw1-Ethernet0/0/2]port link-type access
[sw1-Ethernet0/0/2]
Jul 12 2020 00:06:45-08:00 sw1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 9, the c
hange loop count is 0, and the maximum number of records is 4095.
[sw1-Ethernet0/0/2]port default vlan 2
[sw1-Ethernet0/0/2]dis vlan
The total number of vlans is : 13
--------------------------------------------------------------------------------
U: Up; D: Down; TG: Tagged; UT: Untagged;
MP: Vlan-mapping; ST: Vlan-stacking;
#: ProtocolTransparent-vlan; *: Management-vlan;
--------------------------------------------------------------------------------
VID Type Ports
--------------------------------------------------------------------------------
1 common UT:Eth0/0/1(U) Eth0/0/3(U) Eth0/0/4(U) Eth0/0/5(D)
Eth0/0/6(D) Eth0/0/7(D) Eth0/0/8(D) Eth0/0/9(D)
Eth0/0/10(D) Eth0/0/11(D) Eth0/0/12(D) Eth0/0/13(D)
Eth0/0/14(D) Eth0/0/15(D) Eth0/0/16(D) Eth0/0/17(D)
Eth0/0/18(D) Eth0/0/19(D) Eth0/0/20(D) Eth0/0/21(D)
Eth0/0/22(D) GE0/0/1(D) GE0/0/2(D)
2 common UT:Eth0/0/2(U)
[sw1-Ethernet0/0/2]int e0/0/4
[sw1-Ethernet0/0/4]port link-type access
[sw1-Ethernet0/0/4]port default vlan
Jul 12 2020 00:07:25-08:00 sw1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 11, the
change loop count is 0, and the maximum number of records is 4095.
^
Error:Incomplete command found at '^' position.
[sw1-Ethernet0/0/4]port default vlan 2
[sw1-Ethernet0/0/4]q
[sw1]dis vlan
The total number of vlans is : 13
--------------------------------------------------------------------------------
U: Up; D: Down; TG: Tagged; UT: Untagged;
MP: Vlan-mapping; ST: Vlan-stacking;
#: ProtocolTransparent-vlan; *: Management-vlan;
--------------------------------------------------------------------------------
VID Type Ports
--------------------------------------------------------------------------------
1 common UT:Eth0/0/1(U) Eth0/0/3(U) Eth0/0/5(D) Eth0/0/6(D)
Eth0/0/7(D) Eth0/0/8(D) Eth0/0/9(D) Eth0/0/10(D)
Eth0/0/11(D) Eth0/0/12(D) Eth0/0/13(D) Eth0/0/14(D)
Eth0/0/15(D) Eth0/0/16(D) Eth0/0/17(D) Eth0/0/18(D)
Eth0/0/19(D) Eth0/0/20(D) Eth0/0/21(D) Eth0/0/22(D)
GE0/0/1(D) GE0/0/2(D)
2 common UT:Eth0/0/2(U) Eth0/0/4(U)
效果图:PC1 ping 其它主机
查看各个vlan的MAC地址表
[sw1]display mac-address vlan 1
MAC address table of slot 0:
-------------------------------------------------------------------------------
MAC Address VLAN/ PEVLAN CEVLAN Port Type LSP/LSR-ID
VSI/SI MAC-Tunnel
-------------------------------------------------------------------------------
5489-9865-31e4 1 - - Eth0/0/3 dynamic 0/-
5489-98f2-60a9 1 - - Eth0/0/1 dynamic 0/-
-------------------------------------------------------------------------------
Total matching items on slot 0 displayed = 2
[sw1]display mac-address vlan 2
MAC address table of slot 0:
-------------------------------------------------------------------------------
MAC Address VLAN/ PEVLAN CEVLAN Port Type LSP/LSR-ID
VSI/SI MAC-Tunnel
-------------------------------------------------------------------------------
5489-98dd-5903 2 - - Eth0/0/2 dynamic 0/-
5489-98e5-16b3 2 - - Eth0/0/4 dynamic 0/-
-------------------------------------------------------------------------------
Total matching items on slot 0 displayed = 2
[sw1]int e0/0/1
[sw1-Ethernet0/0/1]port link-type trunk
[sw1-Ethernet0/0/1]display port vlan active
T=TAG U=UNTAG
-------------------------------------------------------------------------------
Port Link Type PVID VLAN List
-------------------------------------------------------------------------------
Eth0/0/1 trunk 1 U: 1
Eth0/0/2 access 2 U: 2
Eth0/0/3 access 1 U: 1
Eth0/0/4 access 2 U: 2
[sw1-Ethernet0/0/1]port trunk allow-pass vlan all
[sw1-Ethernet0/0/1]display port vlan active
T=TAG U=UNTAG
-------------------------------------------------------------------------------
Port Link Type PVID VLAN List
-------------------------------------------------------------------------------
Eth0/0/1 trunk 1 U: 1
T: 2 20 to 30
Eth0/0/2 access 2 U: 2
Eth0/0/3 access 1 U: 1
Eth0/0/4 access 2 U: 2
[sw1-Ethernet0/0/1]port trunk pvid vlan 21
[sw1-Ethernet0/0/1]dis port vlan active
T=TAG U=UNTAG
-------------------------------------------------------------------------------
Port Link Type PVID VLAN List
-------------------------------------------------------------------------------
Eth0/0/1 trunk 21 U: 21
T: 1 to 2 20 22 to 30
Eth0/0/2 access 2 U: 2
Eth0/0/3 access 1 U: 1
Eth0/0/4 access 2 U: 2
拓扑图:
实验目的:PC1与PC2与PC3互相通信(若要实现PC1与PC2不能相互通信,将vlan20从g0/0/2口中的untagged去除,将vlan 10从g0/0/3中的untagged去除)
SW1配置:
vlan batch 10 20 30
interface GigabitEthernet0/0/1
port link-type trunk
port trunk allow-pass vlan 10 20 30
interface GigabitEthernet0/0/2
port hybrid pvid vlan 10
port hybrid untagged vlan 10 20 30
interface GigabitEthernet0/0/3
port hybrid pvid vlan 20
undo port hybrid vlan 1
port hybrid untagged vlan 10 20 30
SW2配置:
vlan batch 10 20 30
interface GigabitEthernet0/0/1
undo port hybrid vlan 1
port hybrid tagged vlan 10 20 30
interface GigabitEthernet0/0/2
port hybrid pvid vlan 30
undo port hybrid vlan 1
port hybrid untagged vlan 10 20 30
效果图:
拓扑图
实验目的:实现PC1与PC2不能通信,PC1、PC2可以与PC3通信
SW1的配置
interface GigabitEthernet0/0/2
port hybrid pvid vlan 10
undo port hybrid vlan 1
port hybrid untagged vlan 10 30
interface GigabitEthernet0/0/1
port link-type trunk
port trunk allow-pass vlan 10 20 30
SW2的配置
interface GigabitEthernet0/0/1
undo port hybrid vlan 1
port hybrid tagged vlan 10 20 30
interface GigabitEthernet0/0/2
port hybrid pvid vlan 30
undo port hybrid vlan 1
port hybrid untagged vlan 10 20 30
效果图:PC1 ping其它主机
注意:
stp disable 关闭生成树(会造成环路)
clear configuration int g0/0/2 清除该接口下的配置,清除以后该接口状态为down,需要undo shutdown 来up
display ip interface brief 查看三层端口
display interface brief 查看所有端口
portswitch 改成二层口
静态(基于端口的手工指定)和动态(MAC\ip subnet\protocol\policy)
vlan 10
mac-vlan mac-address 0000-0000-0001 priority 5
[sw1-vlan10]int g0/0/2
[sw1-GigabitEthernet0/0/2]mac-vlan enable
[sw1-vlan10]ip-subnet-vlan 1 ip 10.1.2.0 24 priority 1
[sw1-vlan20]ip-subnet-vlan 1 ip 10.1.3.0 24 priority 1
[sw1-vlan20]int g0/0/2
[sw1-GigabitEthernet0/0/2]ip-subnet-vlan enable
[sw1-GigabitEthernet0/0/2]vlan precedence ? 调整优先级,默认MAC地址划分优于IP子网划分
ip-subnet-vlan IP-subnet VLAN precedence
mac-vlan MAC VLAN precedence
[sw1-vlan10]protocol-vlan mode ?
ethernetii-etype The protocol type of EthernetII
llc The protocol type of LLC (Logical Link Control)
snap-etype The protocol type of SNAP(Sub-Network Access Protocol)
[sw1-vlan10]protocol-vlan mode en
[sw1-vlan10]protocol-vlan mode en
[sw1-vlan10]protocol-vlan mode enth
[sw1-vlan10]protocol-vlan mode eth
[sw1-vlan10]protocol-vlan mode ethernetii-etype 806
[sw1-vlan10]
Jul 13 2020 00:00:15-08:00 sw1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 34, the
change loop count is 0, and the maximum number of records is 4095.
[sw1-vlan10]protocol-vlan mode ethernetii-etype 800
Error: Invalid Ethernet type value. If encapsulation is ethernetii or SNAP, 0x08
00,0x809b,0x8137 and 0x86dd are not allowed, please specify another.
[sw1-vlan10]policy-vlan mac-address 0000-0000-0001 ip 10.1.2.0 interface g0/0/2
拓扑图:
配置:
interface GigabitEthernet0/0/0.10
dot1q termination vid 10
ip address 10.1.1.1 255.255.255.0
arp broadcast enable
interface GigabitEthernet0/0/0.20
dot1q termination vid 20
ip address 10.1.2.1 255.255.255.0
arp broadcast enable
交换机配置
vlan batch 10 20
interface GigabitEthernet0/0/1
port link-type trunk
port trunk allow-pass vlan 10 20
interface GigabitEthernet0/0/2
port link-type access
port default vlan 10
interface GigabitEthernet0/0/3
port link-type access
port default vlan 20
效果图:
三层交换机通过什么方式判断是二层转发还是三层转发?
答案:如果数据帧的MAC地址等于自己接口MAC,说明数据帧是给自己的;如果目的MAC不是自己的接口MAC,需要做二层转发(同一网段做二层交换)
拓扑图:
[SW1]port-group group-member GigabitEthernet 0/0/1 GigabitEthernet 0/0/3 针对多个端口进行配置
[SW1]port link-type access 操作一次即代表组内全操作,命名行界面会出现与组员数量相同的命令行
[SW2]port default vlan 10
interface GigabitEthernet0/0/2
port link-type access
port default vlan 20
interface Vlanif10
ip address 10.1.1.1 255.255.255.0
interface Vlanif20
ip address 10.1.2.1 255.255.255.0
效果图: