2024-08-23 18:11:58 +08:00
|
|
|
|
# VLAN
|
|
|
|
|
|
|
|
|
|
### 一、VLAN LAN虚拟局域网
|
|
|
|
|
|
|
|
|
|
> 虚拟局域网(Virtual LAN,简称VLAN)是一种将物理上互连的网络在逻辑上划分为多个广播域的技术。通过VLAN,可以在一个物理网络上创建多个独立的逻辑网络,每个逻辑网络可以看作是一个单独的局域网。
|
|
|
|
|
|
|
|
|
|
### 二、为什么使用VLAN
|
|
|
|
|
|
|
|
|
|
- 交换机只能分割冲突域,但是不能分割广播域
|
|
|
|
|
- 随着交换机接口数量的增多,网络中广播增多,会降低网络的传输效率,可以使用VLAN技术分割这个大的广播域
|
|
|
|
|
|
|
|
|
|
### 三、VLAN作用
|
|
|
|
|
|
|
|
|
|
- 分割广播域(主要作用)
|
|
|
|
|
- 带宽利用、降低延迟、提高安全性
|
|
|
|
|
|
|
|
|
|
### 四、VLAN划分方式
|
|
|
|
|
|
|
|
|
|
1. 基于交换机接口的静态划分
|
|
|
|
|
2. 基于主机MAC地址的动态划分
|
|
|
|
|
|
|
|
|
|
### 五、VLAN的基本配置
|
|
|
|
|
|
|
|
|
|
1. 创建vlan
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
[SW1]vlan 2 [2-4094] //创建vlan
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
2. 查看vlan
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
[SW1]display vlan //查看vlan信息
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
3. 删除vlan
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
[SW1]undo vlan 2 //删除vlan2
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
4. 创建多个vlan、删除多个vlan
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
[SW1]vlan batch 10 20 30 //创建多个不连续的vlan
|
|
|
|
|
[SW1]vlan batch 50 to 60 //创建多个连续的vlan
|
|
|
|
|
[SW1]display vlan //查看vlan信息
|
|
|
|
|
[SW1]undo vlan batch 10 20 30 //删除多个不连续vlan
|
|
|
|
|
[SW1]undo vlan batch 50 to 60 //删除多个连续vlan
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 六、端口加入vlan
|
|
|
|
|
|
|
|
|
|
1. **PVID**
|
|
|
|
|
|
|
|
|
|
- PVID:port default VLAN ID,又称为缺省vlan,表示接口所属的vlan
|
|
|
|
|
|
|
|
|
|
每个接口都有一个PVID,缺省情况,交换机所有的接口PVID都是1
|
|
|
|
|
|
|
|
|
|
2. **Access接口模式**
|
|
|
|
|
|
|
|
|
|
- **工作场景**:通常用于交换机连接终端(主机或服务器)
|
|
|
|
|
|
|
|
|
|
- **特点:**
|
|
|
|
|
|
|
|
|
|
同时只能属于一个vlan
|
|
|
|
|
|
|
|
|
|
接收数据帧时,若该帧不带vlan标签,用接口PVID数值做为标签,给数据帧打标签
|
|
|
|
|
|
|
|
|
|
接收数据帧时,若该帧带vlan标签,判断vlan标签和本接口的PVID是否一致,一致接收数据,不一致则丢弃数据。
|
|
|
|
|
|
|
|
|
|
> **注:标准以太网帧及带有****vlan** **标签的数据帧**
|
|
|
|
|
>
|
|
|
|
|
> 1)Vlan数据帧(标准):目标地址+源地址+类型+数据+帧校验序列
|
|
|
|
|
>
|
|
|
|
|
> 2)VLAN数据帧:目的地址+源地址+【Vlan-Tag】+类型+数据+帧校验序列
|
|
|
|
|
|
|
|
|
|
3. **端口加入vlan**
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
[SW1]vlan 2 //创建vlan2
|
|
|
|
|
[SW1]interface GigabitEthernet0/0/1
|
|
|
|
|
[S1-GigabitEthernet0/0/1]port link-type access //接口模式配置为access模式
|
|
|
|
|
[S1-GigabitEthernet0/0/1]port default vlan 2 //接口加入vlan2
|
|
|
|
|
<S1>display vlan
|
|
|
|
|
```
|
|
|
|
|
|
2024-08-26 17:48:53 +08:00
|
|
|
|
### 七、实验
|
2024-08-23 18:11:58 +08:00
|
|
|
|
|
2024-08-26 17:48:53 +08:00
|
|
|
|
1. **实验练习交换机创建vlan并将端口加入vlan**
|
2024-08-23 18:11:58 +08:00
|
|
|
|
|
2024-08-26 17:48:53 +08:00
|
|
|
|
- 需求1:如下图,配置PC1、PC2、PC3、PC4的IP 地址,PC1主机ping 测试连通性
|
2024-08-23 18:11:58 +08:00
|
|
|
|
|
2024-08-26 17:48:53 +08:00
|
|
|
|
![image-20240826093755118](https://picgo-noriu.oss-cn-beijing.aliyuncs.com/Images/image-20240826093755118.png)
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
PC1主机ping 192.168.1.2 192.168.1.3 192.168.1.4
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
- 需求2:如下图创建vlan10 vlan20, (g0/0/1、g0/0/2加入vlan10) (g0/0/3、g0/0/4加入vlan20)
|
|
|
|
|
|
|
|
|
|
![image-20240826093850608](https://picgo-noriu.oss-cn-beijing.aliyuncs.com/Images/image-20240826093850608.png)
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
[S1]vlan batch 10 20
|
|
|
|
|
[S1-vlan10]quit
|
|
|
|
|
[S1]interface GigabitEthernet 0/0/1
|
|
|
|
|
[S1-GigabitEthernet0/0/1]port link-type access
|
|
|
|
|
[S1-GigabitEthernet0/0/1]port default vlan 10
|
|
|
|
|
[S1-GigabitEthernet0/0/1]quit
|
|
|
|
|
[S1]interface GigabitEthernet 0/0/2
|
|
|
|
|
[S1-GigabitEthernet0/0/2]port link-type access
|
|
|
|
|
[S1-GigabitEthernet0/0/2]port default vlan 10
|
|
|
|
|
[S1]interface GigabitEthernet 0/0/3
|
|
|
|
|
[S1-GigabitEthernet0/0/3]port link-type access
|
|
|
|
|
[S1-GigabitEthernet0/0/3]port default vlan 20
|
|
|
|
|
[S1-GigabitEthernet0/0/3]quit
|
|
|
|
|
[S1]interface GigabitEthernet 0/0/4
|
|
|
|
|
[S1-GigabitEthernet0/0/4]port link-type access
|
|
|
|
|
[S1-GigabitEthernet0/0/4]port default vlan 20
|
|
|
|
|
<S1>display vlan查看vlan
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
- 测试
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
PC1不可以ping 通PC3
|
|
|
|
|
PC3可以ping 通PC4
|
|
|
|
|
<S1>display vlan 10显示指定vlan的信息
|
|
|
|
|
<S1>display port vlan显示vlan中包含的接口信息
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 八、VLAN接口类型
|
|
|
|
|
|
|
|
|
|
1. **access接口**
|
|
|
|
|
|
|
|
|
|
2. **Trunk接口**
|
|
|
|
|
|
|
|
|
|
- 作用
|
|
|
|
|
|
|
|
|
|
> 实现跨交换机的相同vlan的通信
|
|
|
|
|
|
|
|
|
|
- 工作场景
|
|
|
|
|
|
|
|
|
|
> 通常用于交换机连接交换机
|
|
|
|
|
|
|
|
|
|
- 特点
|
|
|
|
|
|
|
|
|
|
> 同时可以属于多个vlan,同一时间可以传递多个vlan的数据帧
|
|
|
|
|
>
|
|
|
|
|
> 接收数据帧,检查数据帧中的 vlan标签,判断是否允许这个vlan标签通过,如果允许则接收数据帧,如果不允许则丢弃数据。
|
|
|
|
|
|
|
|
|
|
### 九、Eth-Trunk(链路聚合)
|
|
|
|
|
|
|
|
|
|
1. **Eth-Trunk(链路聚合技术)**
|
|
|
|
|
|
|
|
|
|
- eth-trunk可以把多个独立的物理接口绑定在一起,作为一个大带宽的逻辑接口使用。
|
|
|
|
|
|
|
|
|
|
2. **Eth-Trunk优势**
|
|
|
|
|
|
|
|
|
|
- 增加设备之间的互联带宽
|
|
|
|
|
- 提高设备之间的可靠性
|
|
|
|
|
- 对流量负载均衡,提高链路利用率
|
|
|
|
|
|
|
|
|
|
3. **Eth-Trunk链路聚合模式**
|
|
|
|
|
|
|
|
|
|
1. 手工模式
|
|
|
|
|
2. LACP模式
|
|
|
|
|
|
|
|
|
|
4. **手工模式**
|
|
|
|
|
|
|
|
|
|
- 手工模式下3条活动链路都参与数据转发并分担流量
|
|
|
|
|
|
|
|
|
|
- 当一条链路故障时,在剩余的2条活动链路中分担流量
|
|
|
|
|
|
|
|
|
|
![image-20240826173825369](https://picgo-noriu.oss-cn-beijing.aliyuncs.com/Images/image-20240826173825369.png)
|
|
|
|
|
|
|
|
|
|
5. **Eth-Trunk接口配置流程**
|
|
|
|
|
|
|
|
|
|
1. 创建eth-trunk
|
|
|
|
|
2. 选择链路聚合模式
|
|
|
|
|
3. 在eth-trunk中加入成员接口
|
|
|
|
|
|
|
|
|
|
6. **配置手工模式Eth-trunk**
|
|
|
|
|
|
|
|
|
|
![image-20240826173921031](https://picgo-noriu.oss-cn-beijing.aliyuncs.com/Images/image-20240826173921031.png)
|
|
|
|
|
|
|
|
|
|
- 需求
|
|
|
|
|
|
|
|
|
|
- 对交换机之间的链路进行链路捆绑,增加互联带宽
|
|
|
|
|
- 确保同 VLAN的 PC 之间互通
|
|
|
|
|
|
|
|
|
|
- 配置步骤
|
|
|
|
|
|
|
|
|
|
1. PC配置IP地址
|
|
|
|
|
2. 所有交换机创建vlan10 和vlan20
|
|
|
|
|
3. 交换机和PC互联的接口设置为access ,并加入指定的vlan
|
|
|
|
|
4. 创建Eth-Trunk
|
|
|
|
|
5. 配置Eth-Trunk的工作模式为手工模式
|
|
|
|
|
6. Eth-Trunk中加入成员接口
|
|
|
|
|
|
|
|
|
|
- 配置命令
|
|
|
|
|
|
|
|
|
|
- SW1配置
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
[SW1]vlan batch 10 20
|
|
|
|
|
[SW1]interface G0/0/3
|
|
|
|
|
[SW1-G0/0/3]port link-type access
|
|
|
|
|
[SW1-G0/0/3]port default vlan 10
|
|
|
|
|
[SW1-G0/0/3]interface G0/0/4
|
|
|
|
|
[SW1-G0/0/4]port link-type access
|
|
|
|
|
[SW1-G0/0/4]port default vlan 20
|
|
|
|
|
[SW1]interface eth-trunk 1 //创建并进入 eth-trunk 1
|
|
|
|
|
[SW1-Eth-Trunk1]mode manual load-balance //配置手工模式
|
|
|
|
|
[SW1-Eth-Trunk1]trunkport g0/0/5 //加入成员端口
|
|
|
|
|
[SW1-Eth-Trunk1]trunkport g0/0/6 //加入成员端口
|
|
|
|
|
[SW1-Eth-Trunk1]port link-type trunk //配置 eth-trunk 类型为 trunk
|
|
|
|
|
[SW1-Eth-Trunk1]port trunk allow-pass vlan 10 20 //允许 vlan10和vlan20
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
- SW2配置
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
[SW2]vlan batch 10 20
|
|
|
|
|
[SW2]interface G0/0/3
|
|
|
|
|
[SW2-G0/0/3]port link-type access
|
|
|
|
|
[SW2-G0/0/3]port default vlan 10
|
|
|
|
|
[SW2-G0/0/3]interface G0/0/4
|
|
|
|
|
[SW2-G0/0/4]port link-type access
|
|
|
|
|
[SW2-G0/0/4]port default vlan 20
|
|
|
|
|
[SW2]interface eth-trunk 1
|
|
|
|
|
[SW2-Eth-Trunk1]mode manual load-balance
|
|
|
|
|
[SW2-Eth-Trunk1]trunkport g0/0/1
|
|
|
|
|
[SW2-Eth-Trunk1]trunkport g0/0/2
|
|
|
|
|
[SW2-Eth-Trunk1]port link-type trunk
|
|
|
|
|
[SW2-Eth-Trunk1]port trunk allow-pass vlan 10 20
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
- 验证与测试
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
pc1 ping pc3 通
|
|
|
|
|
pc2 ping pc4 通
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
- 查看配置
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
<SW1>display eth-trunk 1查看链路聚合信息
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
7. **LACP模式**
|
|
|
|
|
|
|
|
|
|
1. LACP模式也称为M:N模式
|
|
|
|
|
2. M条活动链路,N条备份链路
|
|
|
|
|
3. 当活动链路出现故障时,备份链路才进行转发
|
|
|
|
|
|
|
|
|
|
![image-20240826174239665](https://picgo-noriu.oss-cn-beijing.aliyuncs.com/Images/image-20240826174239665.png)
|
|
|
|
|
|
|
|
|
|
8. **LACP模式工作原理**
|
|
|
|
|
|
|
|
|
|
- 确定主动端
|
|
|
|
|
- 确定活动链路
|
|
|
|
|
- LACP抢占功能
|
|
|
|
|
|
|
|
|
|
9. **确定LACP主动端**
|
|
|
|
|
|
|
|
|
|
1. 通过比较两端交换机的系统优先级来确定LACP主动端
|
|
|
|
|
2. 系统优先级数值越小越优先,默认值是32768
|
|
|
|
|
3. 如果系统优先级相同,则比较两端设备的MAC地址,越小越优先
|
|
|
|
|
|
|
|
|
|
10. **确定LACP活动链路**
|
|
|
|
|
|
|
|
|
|
1. 通过系统优先级选举出LACP主动端后,以主动端的接口优先级来选择活动接口
|
|
|
|
|
2. 接口优先级数值越小越优先,默认值是32768
|
|
|
|
|
3. 如果主动端设备的接口优先级相同,则根据接口号的大小来选举活动端口,(接口号越小越优先)
|
|
|
|
|
|
|
|
|
|
11. **配置LACP模式Eth-trunk**
|
|
|
|
|
|
|
|
|
|
![image-20240826174424755](https://picgo-noriu.oss-cn-beijing.aliyuncs.com/Images/image-20240826174424755.png)
|
|
|
|
|
|
|
|
|
|
- 需求
|
|
|
|
|
|
|
|
|
|
> PC1和PC3属于vlan 10、PC2和PC4属于vlan 20
|
|
|
|
|
>
|
|
|
|
|
> 设备之间配置lacp模式的链路聚合,并确保同vlan之间的主机可以互通
|
|
|
|
|
|
|
|
|
|
- 配置步骤
|
|
|
|
|
|
|
|
|
|
1. PC配置IP地址
|
|
|
|
|
2. 所有的交换机都创建vlan10 20
|
|
|
|
|
3. 交换机和pc互联的接口做成access ,并且加入指定的vlan
|
|
|
|
|
4. 设置交换机的lacp 优先级,确定主动端设备
|
|
|
|
|
5. 配置链路聚合
|
|
|
|
|
1. 创建链路聚合组,组号为1
|
|
|
|
|
2. 配置链路聚合的工作模式lacp
|
|
|
|
|
3. 在链路聚合中添加成员接口
|
|
|
|
|
4. 设置接口trunk模式
|
|
|
|
|
5. 设置活动端口(活动链路)的上限阈值为2
|
|
|
|
|
6. 开启lacp 抢占
|
|
|
|
|
|
|
|
|
|
- 配置命令
|
|
|
|
|
|
|
|
|
|
- SW1配置
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
[SW1]vlan batch 10 20
|
|
|
|
|
[SW1]int g0/0/4
|
|
|
|
|
[SW1-GigabitEthernet0/0/4]port link-type access
|
|
|
|
|
[SW1-GigabitEthernet0/0/4]port default vlan 10
|
|
|
|
|
[SW1-GigabitEthernet0/0/4]int g0/0/5
|
|
|
|
|
[SW1-GigabitEthernet0/0/5]port link-type access
|
|
|
|
|
[SW1-GigabitEthernet0/0/5]port default vlan 20
|
|
|
|
|
[SW1-GigabitEthernet0/0/5]quit
|
|
|
|
|
[SW1]lacp priority 100 //配置lacp的系统优先级(越小越优先)
|
|
|
|
|
[SW1]interface eth-trunk 1 //创建链路聚合组1
|
|
|
|
|
[SW1-Eth-Trunk1]mode lacp-static //链路聚合的工作模式是lacp
|
|
|
|
|
[SW1-Eth-Trunk1]trunkport g 0/0/5 to 0/0/7 //在链路聚合组中添加成员接口
|
|
|
|
|
[SW1-Eth-Trunk1]port link-type trunk //设置trunk模式
|
|
|
|
|
[SW1-Eth-Trunk1]port trunk allow-pass vlan 10 20 //允许vlan10 20 流量通过
|
|
|
|
|
[SW1-Eth-Trunk1]max active-linknumber 2 //设置活动端口的上限阈值为2
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
- SW2配置
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
[SW2]vlan batch 10 20
|
|
|
|
|
[SW2]int g0/0/4
|
|
|
|
|
[SW2-GigabitEthernet0/0/4]port link-type access
|
|
|
|
|
[SW2-GigabitEthernet0/0/4]port default vlan 10
|
|
|
|
|
[SW2-GigabitEthernet0/0/4]int g0/0/5
|
|
|
|
|
[SW2-GigabitEthernet0/0/5]port link-type access
|
|
|
|
|
[SW2-GigabitEthernet0/0/5]port default vlan 20
|
|
|
|
|
[SW2-GigabitEthernet0/0/5]quit
|
|
|
|
|
[SW2]int eth-trunk 1
|
|
|
|
|
[SW2-Eth-Trunk1]mode lacp-static
|
|
|
|
|
[SW2-Eth-Trunk1]trunkport g 0/0/1 to 0/0/3
|
|
|
|
|
[SW2-Eth-Trunk1]port link-type trunk
|
|
|
|
|
[SW2-Eth-Trunk1]port trunk allow-pass vlan 10 20
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
- 测试与验证
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
pc1 ping pc3 通
|
|
|
|
|
Pc2 ping pc4 通
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
- 显示链路聚合信息
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
[SW1]display eth-trunk 1 //显示链路聚合信息
|
|
|
|
|
|
|
|
|
|
Preempt Delay Time: 30 //抢占延迟30秒
|
|
|
|
|
System Priority: 100 //系统优先级:100
|
|
|
|
|
Least Active-linknumber: 1 Max Active-linknumber: 2 (最大活跃链路:2)
|
|
|
|
|
Operate status: up (状态:up)
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
ActorPortName Status PortType PortPri PortNo
|
|
|
|
|
GigabitEthernet0/0/1 Selected 1GE 32768 2 (lacp给本段接口分配的序号)
|
|
|
|
|
GigabitEthernet0/0/2 Selected 1GE 32768 3
|
|
|
|
|
GigabitEthernet0/0/3 Unselect 1GE 32768 4
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
> 备注:
|
|
|
|
|
>
|
|
|
|
|
> Selected :被选择的接口
|
|
|
|
|
> Unselect :未被选择的接口
|
|
|
|
|
> PortPri : 端口lacp优先级
|
|
|
|
|
> PortNo : lacp 协议给成员口分配的编号
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
Partner: (本段接口所连接的对端设备接口信息)
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
ActorPortName SysPri SystemID PortPri PortNo
|
|
|
|
|
GigabitEthernet0/0/1 32768 4c1f-ccef-5a42 32768 4 (lacp给对端接口分配的序号)
|
|
|
|
|
GigabitEthernet0/0/2 32768 4c1f-ccef-5a42 32768 5
|
|
|
|
|
GigabitEthernet0/0/3 32768 4c1f-ccef-5a42 32768 6
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
> [SW1-Eth-Trunk1]lacp preempt enable //开启抢占功能
|
|
|
|
|
> [SW1-Eth-Trunk1]lacp preempt delay 10 //配置抢占延迟时间为10秒
|