965 lines
34 KiB
Markdown
965 lines
34 KiB
Markdown
# VRRP
|
||
|
||
### 一、VRRP概述
|
||
|
||
1. **VRRP 是什么**
|
||
- VRRP:虚拟路由器冗余协议
|
||
- 通过把几台路由设备联合组成一台虚拟的路由设备,将虚拟路由设备的IP地址作为用户的默认网关实现与外部网络通信
|
||
- 当网关设备发生故障时,VRRP能够选举新的网关设备承担数据流量,从而保障网络的可靠性,保障网络不中断
|
||
2. **VRRP的作用**
|
||
- 实现多个物理网关的冗余备份
|
||
- 实现数据转发的负载分担
|
||
3. **VRRP组成员角色**
|
||
1. 主路由器:Master →负责承担数据报文转发任务
|
||
2. 备份路由器:Backup →负责监控主路由器状态
|
||
3. 虚拟路由器 :Virtual → 又称VRRP备份组,虚拟路由器的IP地址作为局域网中主机的默认网关
|
||
4. **VRRP主备角色选择原则**
|
||
1. 首先比较优先级,优先级大的为master
|
||
2. 如果优先级一致,其次比较ip地址,IP地址大的为master
|
||
5. **VRRP需知**
|
||
- 在一个VRRP备份组中,Master设备有且仅有一个
|
||
- VRRP协议包括两个版本:VRRPv2和VRRPv3
|
||
- VRRPv2仅适用于IPv4网络,VRRPv3适用于IPv4和IPv6两种网络
|
||
- VRRP协议报文封装在IP报头的后面,协议号是112
|
||
- VRRP通告报文源地址为主路由器物理接口的IP地址(不是虚拟IP地址),目的地址是224.0.0.18
|
||
|
||
### 二、VRRP名词解释
|
||
|
||
1. VRRP路由器:凡是运行VRRP协议的路由器,都叫VRRP路由器
|
||
|
||
2. 虚拟路由器:又称VRRP备份组
|
||
|
||
3. Master路由器:承担数据转发任务的路由器
|
||
|
||
4. Backup路由器:备份路由器
|
||
|
||
5. VRID:虚拟路由器的标识,又称备份组组号
|
||
|
||
6. 虚拟IP地址:Virtual IP :虚拟路由器的IP地址,即:局域网内主机的默认网关地址
|
||
|
||
7. 虚拟MAC地址::虚拟MAC地址根据虚拟路由器VRID生成的
|
||
|
||
> &:一个虚拟路由器拥有一个虚拟MAC地址
|
||
> 如果VRID是1: 虚拟MAC地址就是: 00-00-5E-00-01-01
|
||
> 如果VRID是5: 虚拟MAC地址就是: 00-00-5E-00-01-05
|
||
> 如果VRID是233: 虚拟MAC地址就是: 00-00-5E-00-01-E9
|
||
> (10进制的233==16进制的E9)
|
||
|
||
### 三、VRRP工作过程
|
||
|
||
1. VRRP备份组中的设备根据优先级选举出Master-主路由器
|
||
2. Master-主路由器发送免费ARP报文,将虚拟MAC地址通知给与它连接的设备,承担数据转发任务
|
||
3. Master-主路由器周期性发送VRRP通告报文(三层心跳报文)
|
||
4. 通告报文发送的周期时间:默认情况下是1秒
|
||
5. 通告报文发送的目的地址是组播地址:224.0.0.18
|
||
6. Backup-备份路由器监控主路由器状态,在3倍的"发送周期"+偏移时间后,如果无法收到主路由器发送的VRRP 通告报文,备份路由器升级为“新的Master-主路由器”,新的Master-路由器会立即发送免费ARP报文,刷新与它连接设备中的MAC表项,从而把用户流量引到新的Master设备上来。
|
||
7. 原Master设备故障恢复时,首先切换至Backup状态
|
||
- 如果原Master已开启抢占模式,并且对比优先级,发现自己的优先级高,则主动将自己切换成Master。
|
||
- 如果原Master没有开启抢占模式,即便优先级高,也不会进行抢占,依然保持Backup状态
|
||
|
||
### 四、VRRP热备实验
|
||
|
||
![image-20240829194938326](https://picgo-noriu.oss-cn-beijing.aliyuncs.com/Images/image-20240829194938326.png)
|
||
|
||
- **需求**
|
||
|
||
- 公司部署VRRP,虚拟网关:192.168.1.254
|
||
- 让R1成为master-主路由器,承担用户数据转发任务
|
||
- 让R2成为backup-备份路由器,监视主路由器
|
||
- 实现PC1/PC2 和PC3能够互联互通,流量默认走R1
|
||
- 当R1设备故障后,流量默认走R2
|
||
|
||
- **配置步骤**
|
||
|
||
1. 配置PC的接口IP地址
|
||
2. 配置vlan,接口加入vlan
|
||
3. 配置路由器的接口IP地址
|
||
4. 配置vrrp
|
||
5. 配置静态路由和浮动路由
|
||
|
||
- **配置命令**
|
||
|
||
- 第一步:配置PC的IP地址,掩码,网关
|
||
|
||
- 第二步:创建vlan10 接口加入vlan10
|
||
|
||
```
|
||
[SW1]vlan 10
|
||
[SW1-vlan10]quit
|
||
[SW1]port-group group-member g0/0/1 to g0/0/4
|
||
[SW1-port-group]port link-type access
|
||
[SW1-port-group]port default vlan 10
|
||
```
|
||
|
||
- 第三步:配置路由器的接口的IP地址
|
||
|
||
```
|
||
[R1]int g0/0/0
|
||
[R1-G0/0/0]ip add 192.168.1.251 24
|
||
[R1-G0/0/0]int g0/0/1
|
||
[R1-G0/0/1]ip add 192.168.13.1 24
|
||
```
|
||
|
||
```
|
||
[R2]int g0/0/0
|
||
[R2-G0/0/0]ip add 192.168.1.252 24
|
||
[R2-G0/0/0]int g0/0/1
|
||
[R2-G0/0/1]ip add 192.168.23.1 24
|
||
```
|
||
|
||
```
|
||
[R3]int g0/0/0
|
||
[R3-G0/0/0]ip add 192.168.13.3 24
|
||
[R3-G0/0/0]int g0/0/1
|
||
[R3-G0/0/1]ip add 192.168.23.3 24
|
||
[R3-G0/0/1]int g0/0/2
|
||
[R3-G0/0/2]ip add 192.168.3.254 24
|
||
```
|
||
|
||
- 第四步:配置VRRP
|
||
|
||
```
|
||
[R1]int g0/0/0
|
||
[R1-G0/0/0]vrrp vrid 1 virtual-ip 192.168.1.254 :在接口下开启vrrp功能,创建备份组1;定义虚拟网关为:192.168.1.254
|
||
[R1-G0/0/0]vrrp vrid 1 priority 130 :配置R1在备份组1中的优先级为130;让R1成为备份组1中master-主路由器
|
||
[R2]int g0/0/0
|
||
[R2-G0/0/0]vrrp vrid 1 virtual-ip 192.168.1.254 :在接口下开启vrrp功能,创建备份组1;定义虚拟网关地址为“ 192.168.1.254
|
||
```
|
||
|
||
- 第五步:R1和R2配置去往192.168.3.0/24网段的静态路由
|
||
|
||
```
|
||
[R1]ip route-static 192.168.3.0 24 192.168.13.3
|
||
[R2]ip route-static 192.168.3.0 24 192.168.23.3
|
||
```
|
||
|
||
- 第六步:R3配置去往192.168.1.0/24的浮动路由
|
||
|
||
```
|
||
[R3]ip route-static 192.168.1.0 24 192.168.13.1
|
||
[R3]ip route-static 192.168.1.0 24 192.168.23.1 preference 70
|
||
```
|
||
|
||
- 验证
|
||
|
||
```
|
||
ping 192.168.3.1
|
||
tracert 192.168.3.1 :流量走R1
|
||
```
|
||
|
||
*注释*
|
||
|
||
```
|
||
<R1>display vrrp :显示vrrp信息
|
||
G0/0/0 | Virtual Router 1 :vrrp备份组所在的接口,和备份组组号
|
||
State : Master :当前路由器R1的状态是master
|
||
Virtual IP : 192.168.1.254 :vrrp备份组的虚拟IP
|
||
Master IP : 192.168.1.251 :主路由器的物理接口IP地址
|
||
PriorityRun : 130 :当前运行的优先级是130
|
||
PriorityConfig : 130 :配置的优先级是130
|
||
MasterPriority : 130 :主路由器的优先级是130
|
||
Preempt : YES Delay Time : 0 s :抢占模式:开启, 抢占延迟:0秒
|
||
TimerRun : 1 s :主路由器发送vrrp报文的间隔时间
|
||
TimerConfig : 1 s :主路由器发送vrrp报文的配置时间
|
||
Auth type : NONE : 认证:无
|
||
Virtual MAC : 0000-5e00-0101 :虚拟IP所对应的虚拟MAC地址
|
||
Check TTL : YES :检查TTL :开启
|
||
Config type : normal-vrrp :vrrp类型: 普通
|
||
Backup-forward : disabled :备份设备转发流量:不转发
|
||
Create time : 2023-09-26 14:35:08 :vrrp备份组创建的时间
|
||
Last change time : 2023-09-26 15:5 :vrrp备份组最后1次状态变化的时间
|
||
[R1]display vrrp brief
|
||
Total:1 Master:1 Backup:0 Non-active:0
|
||
VRID State Interface Type Virtual IP
|
||
----------------------------------------------------------------
|
||
1 Master GE0/0/0 Normal 192.168.1.254
|
||
```
|
||
|
||
### 五、VRRP上行链路跟踪(上行端口监控)
|
||
|
||
![image-20240829195437411](https://picgo-noriu.oss-cn-beijing.aliyuncs.com/Images/image-20240829195437411.png)
|
||
|
||
- 需求
|
||
|
||
```
|
||
PC1和PC2互联互通
|
||
1)R1/R2部署VRRP备份组,组号为1
|
||
2)R1的VRRP优先级为130,R1是主路由器
|
||
3)R2的VRRP优先级为100,R2是备份路由器
|
||
4)PC1和PC2互通,流量走R1-主路由器
|
||
5)R1连接R3的上行链路突发故障,导致网络中断,为了避免网络中断,要让R2升级为主设备,承担流量转发
|
||
```
|
||
|
||
- 配置步骤
|
||
|
||
1. 第一步:配置PC的IP地址,掩码,网关
|
||
2. 第二步:配置交换机vlan ,接口加vlan
|
||
3. 第三步:R1/R2配置接口IP地址,配置VRRP
|
||
- 让R1成为主设备,R2成为备份设备
|
||
4. 第四步:R1/R2/R3配置静态路由
|
||
1. 配置R3的接口IP地址
|
||
2. R1/R2 配置去往192.168.2.0/24网段的路由,下一跳为R3的接口IP地址
|
||
3. R3配置去往192.168.1/24 网段的路由,下一跳为R1
|
||
4. R3配置去往192.168.1/24 网段的路由,下一跳为R2
|
||
5. 第五步:验证VRRP
|
||
6. 第六步:模拟R1上行链路故障,让R2升级为主网关
|
||
|
||
- 配置命令
|
||
|
||
- 第一步:配置PC的IP地址,掩码,网关
|
||
|
||
- 第二步:配置vlan,接口加入vlan
|
||
|
||
- SW1配置
|
||
|
||
```
|
||
[SW1]vlan 10
|
||
[SW1-vlan10]quit
|
||
[SW1]port-group group-member g0/0/1 to g0/0/3
|
||
[SW1-port-group]port link-type access
|
||
[SW1-port-group]port default vlan 10
|
||
```
|
||
|
||
- 第三步:R1/R2配置接口IP地址,配置VRRP
|
||
|
||
> 让R1成为主设备,R2成为备份设备
|
||
|
||
- R1配置
|
||
|
||
```
|
||
[Huawei]sys R1
|
||
[R1]int g0/0/0
|
||
[R1-G0/0/0]ip address 192.168.1.251 24
|
||
[R1-G0/0/0]vrrp vrid 1 virtual-ip 192.168.1.254
|
||
[R1-G0/0/0]vrrp vrid 1 priority 130
|
||
[R1-G0/0/0]int g0/0/1
|
||
[R1-G0/0/1]ip address 192.168.13.1 24
|
||
```
|
||
|
||
- R2配置
|
||
|
||
```
|
||
[Huawei]sys R2
|
||
[R2]int g0/0/0
|
||
[R2-G0/0/0]ip address 192.168.1.252 24
|
||
[R2-G0/0/0]vrrp vrid 1 virtual-ip 192.168.1.254
|
||
[R2-G0/0/0]int g0/0/2
|
||
[R2-G0/0/2]ip address 192.168.23.1 24
|
||
```
|
||
|
||
- 第四步:R1/R2/R3配置静态路由
|
||
|
||
> 1. 配置R3的接口IP地址
|
||
> 2. R1/R2 配置去往192.168.2.0/24网段的路由,下一跳为R3的接口IP地址
|
||
> 3. R3配置去往192.168.1/24 网段的路由,下一跳为R1
|
||
> 4. R3配置去往192.168.1/24 网段的路由,下一跳为R2
|
||
|
||
- R1配置
|
||
|
||
```
|
||
[R1]ip route-static 192.168.2.0 24 192.168.13.3
|
||
```
|
||
|
||
- R2配置
|
||
|
||
```
|
||
[R2]ip route-static 192.168.2.0 24 192.168.23.3
|
||
```
|
||
|
||
- R3配置
|
||
|
||
```
|
||
[Huawei]sys R3
|
||
[R3]int g0/0/1
|
||
[R3-G0/0/1]ip address 192.168.13.3 24
|
||
[R3-G0/0/1]int g0/0/2
|
||
[R3-G0/0/2]ip address 192.168.23.3 24
|
||
[R3-G0/0/2]int g0/0/0
|
||
[R3-G0/0/0]ip address 192.168.2.254 24
|
||
[R3-Gt0/0/0]quit
|
||
[R3]ip route-static 192.168.1.0 24 192.168.13.1
|
||
[R3]ip route-static 192.168.1.0 24 192.168.23.1
|
||
```
|
||
|
||
- 第五步:验证VRRP
|
||
|
||
```
|
||
<R1>display vrrp //查看详细信息
|
||
<R1>display vrrp brief //查看简要信息
|
||
PC1 -->ping 192.168.2.1
|
||
PC1 -->tracert 192.168.2.1 //验证数据报文是否经主路由器转发
|
||
```
|
||
|
||
- 第六步:模拟R1上行链路故障,让R2升级为主网关
|
||
|
||
- R1配置备注
|
||
|
||
```
|
||
R1的g0/0/1口故障,但是R1的g0/0/0口依然是UP的
|
||
所以只要R1的g0/0/0是UP的,R1就依然可以发送VRRP通告报文,R1依然是Master
|
||
所以主机的数据报文依然转发给R1,但是R1的g0/0/1接口down掉了
|
||
所以R1和外部设备R3的链路也就终端了,无法进行数据转发,
|
||
最终导致公司内网网络瘫痪
|
||
```
|
||
|
||
*如何解决这个问题?*
|
||
|
||
> 使用VRRP上行端口跟踪
|
||
|
||
- 配置命令如下
|
||
|
||
```
|
||
[R1-G0/0/0]vrrp vrid 1 track int G0/0/1 reduced 50
|
||
```
|
||
|
||
> 这条配置命令表示: VRRP持续监控R1的g0/0/1口的状态,如果R1的g0/0/1接口状态为down 那么VRRP的优先级就减去50。
|
||
>
|
||
> 如果原来VRRP优先级为130,那么g0/0/1口down掉后,优先级就为130-50=80,R1的VRRP优先级为80 低于R2的优先级100
|
||
>
|
||
> 所以R2经过选举,最终抢占成为新的Master设备,承担流量转发任务
|
||
|
||
- 测试验证
|
||
|
||
> 把R1的上行链路接口g0/0/1 shutdown 掉,验证R2是否会升级为 master
|
||
|
||
### 六、VRRP负载分担
|
||
|
||
![image-20240829200454597](https://picgo-noriu.oss-cn-beijing.aliyuncs.com/Images/image-20240829200454597.png)
|
||
|
||
- **需求**
|
||
|
||
- R1/R2部署VRRP,创建两个VRRP备份组,分别为组1和组2
|
||
- 在备份组1中为R1为Master-主路由器、R2为Backup-备份路由器
|
||
- 在备份组2中为R2为Master-主路由器、R1为Backup-备份路由器
|
||
- PC1和Server1通信,数据默认通过备份组1中的R1-Master转发,如果R1故障,依靠备份组1内的R2转发
|
||
- PC2和Server1通信,数据默认通过备份组2中的R2-Master转发,如果R2故障,依靠备份组2内的R1转发
|
||
|
||
- **配置步骤**
|
||
|
||
- 第一步:配置PC和server的IP地址,掩码,网关
|
||
- 第二步:配置交换机vlan ,接口加vlan
|
||
- 第三步:R1/R2配置接口IP地址,配置VRRP
|
||
1. 创建备份组1
|
||
- 配置备份组1的虚拟IP地址为:192.168.1.254
|
||
- 让R1成为备份组1的Master-主路由器,R2成为备份组1的Back-备份路由器
|
||
- 在R1中配置备份组1的上行接口跟踪,当上行接口down的时候,优先级减去50
|
||
2. 创建备份组2
|
||
- 设置备份组2的虚拟IP地址为:192.168.1.253
|
||
- 让R2成为备份组2的Master-主路由器,R1成为备份组2的Back-备份路由器
|
||
- 在R2中配置备份组2的上行接口跟踪,当上行接口down的时候,优先级减去50
|
||
- 第四步:R1/R2/R3配置静态路由
|
||
1. 配置R3的接口IP地址
|
||
2. R3配置去往192.168.1/24 网段的路由,下一跳为R1
|
||
3. R3配置去往192.168.1/24 网段的路由,下一跳为R2
|
||
4. R1/R2 配置去往192.168.2.0/24网段的路由,下一跳为R3的接口IP地址
|
||
- 第五步:验证VRRP
|
||
- PC1 ping server1 验证数据依靠那个设备转发
|
||
- PC2 ping server1 验证数据依靠那个设备转发
|
||
|
||
- **配置命令**
|
||
|
||
- 第一步:配置PC和server的IP地址,掩码,网关
|
||
|
||
- 第二步:配置交换机vlan ,接口加vlan
|
||
|
||
- SW1配置
|
||
|
||
```
|
||
[SW1]vlan 10
|
||
[SW1-vlan10]quit
|
||
[SW1]port-group group-member g0/0/1 to g0/0/4
|
||
[SW1-port-group]port link-type access
|
||
[SW1-port-group]port default vlan 10
|
||
```
|
||
|
||
- 第三步:R1/R2配置接口IP地址,配置VRRP
|
||
|
||
- R1配置
|
||
|
||
```
|
||
[R1]int g0/0/1
|
||
[R1-G0/0/1]ip address 192.168.13.1 24
|
||
[R1-G0/0/1]int g0/0/0
|
||
[R1-G0/0/0]ip address 192.168.1.251 24
|
||
[R1-G0/0/0]vrrp vrid 1 virtual-ip 192.168.1.254
|
||
[R1-G0/0/0]vrrp vrid 1 priority 130
|
||
[R1-G0/0/0]vrrp vrid 1 track int g0/0/1 reduced 50
|
||
[R1-G0/0/0]vrrp vrid 2 virtual-ip 192.168.1.253
|
||
```
|
||
|
||
- R2配置
|
||
|
||
```
|
||
[R2]int g0/0/2
|
||
[R2-G0/0/2]ip address 192.168.23.1 24
|
||
[R2-G0/0/2]int g0/0/0
|
||
[R2-G0/0/0]ip address 192.168.1.252 24
|
||
[R2-G0/0/0]vrrp vrid 1 virtual-ip 192.168.1.254
|
||
[R2-G0/0/0]vrrp vrid 2 virtual-ip 192.168.1.253
|
||
[R2-G0/0/0]vrrp vrid 2 priority 130
|
||
[R2-G0/0/0]vrrp vrid 2 track int g0/0/2 reduced 50
|
||
```
|
||
|
||
- 第四步:R1/R2/R3配置静态路由
|
||
|
||
- R3配置
|
||
|
||
```
|
||
[R3]int g0/0/0
|
||
[R3-G0/0/0]ip address 192.168.2.254 24
|
||
[R3-Gi0/0/0]int g0/0/1
|
||
[R3-G0/0/1]ip address 192.168.13.3 24
|
||
[R3-G0/0/1]int g0/0/2
|
||
[R3-G0/0/2]ip address 192.168.23.3 24
|
||
[R3-G0/0/2]quit
|
||
[R3]ip route-static 192.168.1.0 24 192.168.13.1
|
||
[R3]ip route-static 192.168.1.0 24 192.168.23.1 preference 70
|
||
```
|
||
|
||
- R1配置静态路由
|
||
|
||
```
|
||
[R1]ip route-static 192.168.2.0 24 192.168.13.3
|
||
```
|
||
|
||
- R2配置静态路由
|
||
|
||
```
|
||
[R2]ip route-static 192.168.2.0 24 192.168.23.3
|
||
```
|
||
|
||
- 第五步:验证VRRP
|
||
|
||
```
|
||
PC1>tracert 192.168.2.1
|
||
1 192.168.1.251 31 ms 47 ms 47 ms
|
||
2 192.168.13.3 31 ms 47 ms 47 ms
|
||
3 192.168.2.1 63 ms 46 ms 47 ms
|
||
```
|
||
|
||
```
|
||
PC2>tracert 192.168.2.1
|
||
1 192.168.1.252 32 ms 47 ms 46 ms
|
||
2 192.168.23.3 47 ms 32 ms 62 ms
|
||
3 192.168.2.1 47 ms 47 ms 31 ms
|
||
```
|
||
|
||
### 七、在交换机中部署VRRP
|
||
|
||
1. VRRP负载分担 - 多VLAN环境
|
||
|
||
![image-20240831101221398](https://picgo-noriu.oss-cn-beijing.aliyuncs.com/Images/image-20240831101221398.png)
|
||
|
||
- **需求**
|
||
|
||
1. PC1属于vlan10 ,PC2属于vlan20
|
||
2. vlan10的主网关是SW1,备份网关是SW2,vlan10的数据流量默认由SW1转发
|
||
3. vlan20的主网关是SW2,备份网关是SW1,vlan20的数据流量默认由SW2转发
|
||
|
||
- **配置步骤**
|
||
|
||
- 第一步:配置PC和server的IP地址,掩码,网关
|
||
|
||
- 第二步:在sw10交换机
|
||
|
||
1. 创建vlan 10/20
|
||
2. 与PC互联的接口,配置access模式,并加入指定的vlan
|
||
3. 与交换机互联的接口配置trunk模式
|
||
|
||
- 第三步:SW1和SW2配置VRRP负载均衡
|
||
|
||
1. SW1交换机配置
|
||
|
||
- 在SW1中创建vlan 10/20/13
|
||
- 配置vlanif10的IP:192.168.10.251/24
|
||
- 配置vlanif20的IP:192.168.20.251/24
|
||
- 配置vlanif13的IP:192.168.13.1/24
|
||
- SW1和R3互联的接口g0/0/1加入vlan13
|
||
- SW1和SW10互联的接口配置为trunk
|
||
|
||
****
|
||
|
||
- 在SW1交换机的vlanif10虚接口下,配置VRRP
|
||
- 在vlanif10虚接口下创建备份组10的,并配置虚拟IP:192.168.10.254
|
||
- 配置备份组10的优先级为130
|
||
- 让SW1成为备份组10的Master-->让SW1成为vlan10的主网关
|
||
- 在备份组10中配置上行接口跟踪,当上行接口down的时候,优先级减去50
|
||
|
||
****
|
||
|
||
- 在SW1交换机的vlanif20虚接口下,配置VRRP
|
||
- 在vlanif20虚接口下创建备份组20的,并配置虚拟IP:192.168.20.254
|
||
- 让SW1成为备份组20的Backup-->SW1是vlan20的备份网关
|
||
|
||
2. SW2交换机配置
|
||
|
||
- 在SW2中创建vlan 10/20/23
|
||
- 配置vlanif10的IP:192.168.10.252/24
|
||
- 配置vlanif20的IP:192.168.20.252/24
|
||
- 配置vlanif23的IP:192.168.23.1/24
|
||
- SW2和R3互联的接口g0/0/1加入vlan23
|
||
- SW2和SW10互联的接口配置为trunk
|
||
|
||
****
|
||
|
||
- 在SW2交换机的vlanif10虚接口下,配置VRRP
|
||
- 在vlanif10虚接口下创建备份组10的,并配置虚拟IP:192.168.10.254
|
||
- 让SW2成为备份组10的Backup--SW2是vlan10的备份网关
|
||
|
||
****
|
||
|
||
- 在SW2交换机的vlanif20虚接口下,配置VRRP
|
||
- 在vlanif20虚接口下创建备份组20的,并配置虚拟IP:192.168.20.254
|
||
- 配置备份组20的优先级为130
|
||
- 让SW2成为备份组20的Master-->让SW2成为vlan20的主网关
|
||
- 在备份组20中配置上行接口跟踪,当上行接口down的时候,优先级减去50
|
||
|
||
- 第四步:SW1/SW2/R3配置静态路由
|
||
|
||
1. 配置R3的接口IP地址
|
||
2. R3配置去往192.168.10/24 网段的路由,下一跳为SW1
|
||
3. R3配置去往192.168.10/24 网段的路由,下一跳为SW2
|
||
4. R3配置去往192.168.20/24 网段的路由,下一跳为SW1
|
||
5. R3配置去往192.168.20/24 网段的路由,下一跳为SW2
|
||
6. SW1/SW2 配置去往192.168.2.0/24网段的路由,下一跳为R3的接口IP地址
|
||
|
||
- 第五步:验证VRRP
|
||
|
||
- PC1 ping server1 验证vlan10的数据依靠SW1转发
|
||
- PC2 ping server1 验证vlan20的数据依靠SW2转发
|
||
|
||
- **配置命令**
|
||
|
||
- 第一步:配置PC和server的IP地址,掩码,网关
|
||
|
||
- 第二步:在sw10交换机
|
||
|
||
- SW10配置
|
||
|
||
```
|
||
[SW10]vlan batch 10 20
|
||
[SW10]int g0/0/1
|
||
[SW10-G0/0/1]port link-type access
|
||
[SW10-G0/0/1]port default vlan 10
|
||
[SW10-G0/0/1]int g0/0/2
|
||
[SW10-G0/0/2]port link-type access
|
||
[SW10-G0/0/2]port default vlan 20
|
||
[SW10-G0/0/2]quit
|
||
[SW10]port-group group-member g0/0/3 g0/0/4
|
||
[SW10-port-group]port link-type trunk
|
||
[SW10-port-group]port trunk allow-pass vlan all
|
||
```
|
||
|
||
- 第三步:SW1和SW2配置VRRP负载均衡
|
||
|
||
- SW1配置
|
||
|
||
```
|
||
[SW1]vlan batch 10 20 13
|
||
[SW1]int g0/0/1
|
||
[SW1-G0/0/1]port link-type access
|
||
[SW1-G0/0/1]port default vlan 13
|
||
[SW1-G0/0/1]quit
|
||
[SW1]int vlanif 13
|
||
[SW1-Vlanif13]ip address 192.168.13.1 24
|
||
[SW1-Vlanif13]int vlanif 10
|
||
[SW1-Vlanif10]ip address 192.168.10.251 24
|
||
[SW1-Vlanif10]vrrp vrid 10 virtual-ip 192.168.10.254
|
||
[SW1-Vlanif10]vrrp vrid 10 priority 130
|
||
[SW1-Vlanif10]vrrp vrid 10 track int g0/0/1 reduced 50
|
||
[SW1-Vlanif10]int vlanif 20
|
||
[SW1-Vlanif20]ip address 192.168.20.251 24
|
||
[SW1-Vlanif20]vrrp vrid 20 virtual-ip 192.168.20.254
|
||
[SW1-Vlanif20]quit
|
||
[SW1]int g0/0/2
|
||
[SW1-G0/0/2]port link-type trunk
|
||
[SW1-G0/0/2]port trunk allow-pass vlan all
|
||
```
|
||
|
||
- SW2配置
|
||
|
||
```
|
||
[SW2]vlan batch 10 20 23
|
||
[SW2]int g0/0/1
|
||
[SW2-G0/0/1]port link-type access
|
||
[SW2-G0/0/1]port default vlan 23
|
||
[SW2-G0/0/1]quit
|
||
[SW2]int vlanif 23
|
||
[SW2-Vlanif23]ip address 192.168.23.1 24
|
||
[SW2-Vlanif23]int vlanif 10
|
||
[SW2-Vlanif10]ip address 192.168.10.252 24
|
||
[SW2-Vlanif10]vrrp vrid 10 virtual-ip 192.168.10.254
|
||
[SW2-Vlanif10]int vlanif 20
|
||
[SW2-Vlanif20]ip address 192.168.20.252 24
|
||
[SW2-Vlanif20]vrrp vrid 20 virtual-ip 192.168.20.254
|
||
[SW2-Vlanif20]vrrp vrid 20 priority 130
|
||
[SW2-Vlanif20]vrrp vrid 20 track int g0/0/1 reduced 50
|
||
[SW2-Vlanif20]quit
|
||
[SW2]int g0/0/2
|
||
[SW2-G0/0/2]port link-type trunk
|
||
[SW2-G0/0/2]port trunk allow-pass vlan all
|
||
```
|
||
|
||
- 第四步:SW1/SW2/R3配置静态路由
|
||
|
||
- R1配置
|
||
|
||
```
|
||
[R1]int g0/0/0
|
||
[R1-G0/0/0]ip address 192.168.2.254 24
|
||
[R1-G0/0/0]int g0/0/1
|
||
[R1-G0/0/1]ip address 192.168.13.3 24
|
||
[R1-G0/0/1]int g0/0/2
|
||
[R1-G0/0/2]ip address 192.168.23.3 24
|
||
[R1-G0/0/2]quit
|
||
[R1]ip route-static 192.168.10.0 24 192.168.13.1
|
||
[R1]ip route-static 192.168.10.0 24 192.168.23.1 preference 70
|
||
[R1]ip route-static 192.168.20.0 24 192.168.13.1 preference 70
|
||
[R1]ip route-static 192.168.20.0 24 192.168.23.1
|
||
```
|
||
|
||
- SW1配置
|
||
|
||
```
|
||
[SW1]ip route-static 192.168.2.0 24 192.168.13.3
|
||
```
|
||
|
||
- SW2配置
|
||
|
||
```
|
||
[SW2]ip route-static 192.168.2.0 24 192.168.23.3
|
||
```
|
||
|
||
- 第五步:验证VRRP
|
||
|
||
- PC1 ping server1 验证vlan10的数据依靠SW1转发
|
||
|
||
```
|
||
PC1>tracert 192.168.2.1
|
||
1 192.168.10.251 47 ms 32 ms 46 ms
|
||
2 192.168.13.3 63 ms 62 ms 79 ms
|
||
3 192.168.2.1 62 ms 63 ms 62 ms
|
||
```
|
||
|
||
- PC2 ping server1 验证vlan20的数据依靠SW2转发
|
||
|
||
```
|
||
PC2>tracert 192.168.2.1
|
||
1 192.168.20.252 109 ms 47 ms 31 ms
|
||
2 192.168.23.3 110 ms 78 ms 78 ms
|
||
3 192.168.2.1 94 ms 78 ms 93 ms
|
||
```
|
||
|
||
- SW1
|
||
|
||
```
|
||
[SW1]display vrrp brief
|
||
VRID State Interface Type Virtual IP
|
||
----------------------------------------------------------------
|
||
10 Master Vlanif10 Normal 192.168.10.254
|
||
20 Backup Vlanif20 Normal 192.168.20.254
|
||
----------------------------------------------------------------
|
||
Total:2 Master:1 Backup:1 Non-active:0
|
||
```
|
||
|
||
- SW2
|
||
|
||
```
|
||
[SW2]display vrrp brief
|
||
VRID State Interface Type Virtual IP
|
||
----------------------------------------------------------------
|
||
10 Backup Vlanif10 Normal 192.168.10.254
|
||
20 Master Vlanif20 Normal 192.168.20.254
|
||
----------------------------------------------------------------
|
||
Total:2 Master:1 Backup:1 Non-active:0
|
||
```
|
||
|
||
### 八、VRRP+MSTP联动
|
||
|
||
![image-20240831103113797](https://picgo-noriu.oss-cn-beijing.aliyuncs.com/Images/image-20240831103113797.png)
|
||
|
||
- **需求**
|
||
|
||
1. PC1属于vlan10 ,PC2属于vlan20
|
||
2. vlan10的主网关是SW1,备份网关是SW2,vlan10的数据流量默认由SW1转发
|
||
3. vlan20的主网关是SW2,备份网关是SW1,vlan20的数据流量默认由SW2转发
|
||
4. SW1和SW2部署MSTP和VRRP,既要实现负载分担,又要互为备份
|
||
|
||
- **配置步骤**
|
||
|
||
- 第一步:配置PC和server的IP地址,掩码,网关
|
||
|
||
- 第二步:在sw3交换机
|
||
|
||
- 创建vlan 10/20
|
||
- 与PC互联的接口,配置access模式,并加入指定的vlan
|
||
- 与交换机互联的接口配置trunk模式
|
||
- 配置MSTP
|
||
|
||
- 第三步:SW1和SW2配置VRRP和MSTP
|
||
|
||
- SW1交换机配置
|
||
|
||
1. 在SW1中创建vlan 10/20/13
|
||
2. 配置vlanif10的IP:192.168.10.251/24
|
||
3. 配置vlanif20的IP:192.168.20.251/24
|
||
4. 配置vlanif13的IP:192.168.13.1/24
|
||
5. SW1和R3互联的接口g0/0/1加入vlan13
|
||
6. SW1和SW10互联的接口配置为trunk
|
||
|
||
****
|
||
|
||
1. 在SW1交换机的vlanif10虚接口下,配置VRRP
|
||
2. 在vlanif10虚接口下创建备份组10的,并配置虚拟IP:192.168.10.254
|
||
3. 配置备份组10的优先级为130
|
||
4. 让SW1成为备份组10的Master-->让SW1成为vlan10的主网关
|
||
5. 在备份组10中配置上行接口跟踪,当上行接口down的时候,优先级减去50
|
||
|
||
****
|
||
|
||
1. 在SW1交换机的vlanif20虚接口下,配置VRRP
|
||
2. 在vlanif20虚接口下创建备份组20的,并配置虚拟IP:192.168.20.254
|
||
3. 让SW1成为备份组20的Backup-->SW1是vlan20的备份网关
|
||
|
||
****
|
||
|
||
1. SW1配置MSTP,让SW1成为vlan10的主根,成为vlan20的备根
|
||
|
||
- SW2交换机配置
|
||
|
||
1. 在SW2中创建vlan 10/20/23
|
||
2. 配置vlanif10的IP:192.168.10.252/24
|
||
3. 配置vlanif20的IP:192.168.20.252/24
|
||
4. 配置vlanif23的IP:192.168.23.1/24
|
||
5. SW2和R3互联的接口g0/0/1加入vlan23
|
||
6. SW2和SW10互联的接口配置为trunk
|
||
|
||
****
|
||
|
||
1. 在SW2交换机的vlanif10虚接口下,配置VRRP
|
||
2. 在vlanif10虚接口下创建备份组10的,并配置虚拟IP:192.168.10.254
|
||
3. 让SW2成为备份组10的Backup--SW2是vlan10的备份网关
|
||
|
||
****
|
||
|
||
1. 在SW2交换机的vlanif20虚接口下,配置VRRP
|
||
2. 在vlanif20虚接口下创建备份组20的,并配置虚拟IP:192.168.20.254
|
||
3. 配置备份组20的优先级为130
|
||
4. 让SW2成为备份组20的Master-->让SW2成为vlan20的主网关
|
||
5. 在备份组20中配置上行接口跟踪,当上行接口down的时候,优先级减去50
|
||
|
||
****
|
||
|
||
1. SW2配置MSTP,让SW2成为vlan20的主根,成为vlan10的备根
|
||
|
||
- 第四步:SW1/SW2/R3配置静态路由
|
||
|
||
1. 配置R3的接口IP地址
|
||
2. R3配置去往192.168.10/24 网段的路由,下一跳为SW1
|
||
3. R3配置去往192.168.10/24 网段的路由,下一跳为SW2
|
||
4. R3配置去往192.168.20/24 网段的路由,下一跳为SW1
|
||
5. R3配置去往192.168.20/24 网段的路由,下一跳为SW2
|
||
6. SW1/SW2 配置去往192.168.2.0/24网段的路由,下一跳为R3的接口IP地址
|
||
|
||
- 第五步:验证VRRP
|
||
|
||
- PC1 ping server1 验证vlan10的数据依靠SW1转发
|
||
- PC2 ping server1 验证vlan20的数据依靠SW2转发
|
||
|
||
- **配置命令**
|
||
|
||
- 第一步:配置PC和server的IP地址,掩码,网关
|
||
|
||
- 第二步:在sw3交换机
|
||
|
||
- SW3配置
|
||
|
||
```
|
||
[SW3]vlan batch 10 20
|
||
[SW3]int g0/0/1
|
||
[SW3-GigabitEthernet0/0/1]port link-type access
|
||
[SW3-GigabitEthernet0/0/1]port default vlan 10
|
||
[SW3-GigabitEthernet0/0/1]int g0/0/2
|
||
[SW3-GigabitEthernet0/0/2]port link-type access
|
||
[SW3-GigabitEthernet0/0/2]port default vlan 20
|
||
[SW3-GigabitEthernet0/0/2]quit
|
||
[SW3]port-group group-member g0/0/3 g0/0/4
|
||
[SW3-port-group]port link-type trunk
|
||
[SW3-port-group]port trunk allow-pass vlan all
|
||
[SW3-port-group]quit
|
||
[SW3]stp region-configuration
|
||
[SW3-mst-region] region-name ntd
|
||
[SW3-mst-region] instance 10 vlan 10
|
||
[SW3-mst-region] instance 20 vlan 20
|
||
[SW3-mst-region] active region-configuration
|
||
```
|
||
|
||
- 第三步:SW1和SW2配置VRRP和MSTP和静态路由
|
||
|
||
- SW1配置
|
||
|
||
```
|
||
[SW1]vlan batch 10 20
|
||
[SW1]int g0/0/2
|
||
[SW1-GigabitEthernet0/0/2]port link-type trunk
|
||
[SW1-GigabitEthernet0/0/2]port trunk allow-pass vlan all
|
||
[SW1-GigabitEthernet0/0/2]quit
|
||
[SW1]vlan batch 13
|
||
[SW1]int vlanif 10
|
||
[SW1-Vlanif10]ip address 192.168.10.251 24
|
||
[SW1-Vlanif10]int vlanif 20
|
||
[SW1-Vlanif20]ip address 192.168.20.251 24
|
||
[SW1-Vlanif20]int vlanif 13
|
||
[SW1-Vlanif13]ip address 192.168.13.1 24
|
||
[SW1-Vlanif13]quit
|
||
[SW1]int vlanif10
|
||
[SW1-Vlanif10]vrrp vrid 10 virtual-ip 192.168.10.254
|
||
[SW1-Vlanif10]vrrp vrid 10 priority 130
|
||
[SW1-Vlanif10]vrrp vrid 10 track int g0/0/1 reduced 50
|
||
[SW1-Vlanif10]int vlanif 20
|
||
[SW1-Vlanif20]vrrp vrid 20 virtual-ip 192.168.20.254
|
||
[SW1-Vlanif20]quit
|
||
[SW1]int g0/0/1
|
||
[SW1-GigabitEthernet0/0/1]port link-type access
|
||
[SW1-GigabitEthernet0/0/1]port default vlan 13
|
||
[SW1-GigabitEthernet0/0/1]quit
|
||
[SW1]ip route-static 192.168.2.0 24 192.168.13.3
|
||
[SW1]stp region-configuration //配置MSTP
|
||
[SW1-mst-region]region-name ntd
|
||
[SW1-mst-region]instance 10 vlan 10
|
||
[SW1-mst-region]instance 20 vlan 20
|
||
[SW1-mst-region]active region-configuration
|
||
[SW1-mst-region]quit
|
||
[SW1]stp instance 10 priority 4096 //让SW1成为vlan10的主根
|
||
[SW1]stp instance 20 priority 8192 //让SW1成为vlan20的备根
|
||
[SW1]int g0/0/24
|
||
[SW1-GigabitEthernet0/0/24]port link-type trunk
|
||
[SW1-GigabitEthernet0/0/24]port trunk allow-pass vlan all
|
||
```
|
||
|
||
- SW2的配置
|
||
|
||
```
|
||
[SW2]vlan batch 10 20 23
|
||
[SW2]int g0/0/2
|
||
[SW2-GigabitEthernet0/0/2]port link-type trunk
|
||
[SW2-GigabitEthernet0/0/2]port trunk allow-pass vlan all
|
||
[SW2-GigabitEthernet0/0/2]quit
|
||
[SW2]int vlanif 10
|
||
[SW2-Vlanif10]ip address 192.168.10.252 24
|
||
[SW2-Vlanif10]vrrp vrid 10 virtual-ip 192.168.10.254
|
||
[SW2-Vlanif10]int vlanif20
|
||
[SW2-Vlanif20]ip address 192.168.20.252 24
|
||
[SW2-Vlanif20]vrrp vrid 20 virtual-ip 192.168.20.254
|
||
[SW2-Vlanif20]vrrp vrid 20 priority 130
|
||
[SW2-Vlanif20]vrrp vrid 20 track int g0/0/1 reduced 50
|
||
[SW2-Vlanif20]quit
|
||
[SW2]int vlanif 23
|
||
[SW2-Vlanif23]ip address 192.168.23.1 24
|
||
[SW2-Vlanif23]int g0/0/1
|
||
[SW2-GigabitEthernet0/0/1]port link-type access
|
||
[SW2-GigabitEthernet0/0/1]port default vlan 23
|
||
[SW2-GigabitEthernet0/0/1]quit
|
||
[SW2]ip route-static 192.168.2.0 24 192.168.23.3
|
||
[SW2]stp region-configuration
|
||
[SW2-mst-region] region-name ntd
|
||
[SW2-mst-region] instance 10 vlan 10
|
||
[SW2-mst-region] instance 20 vlan 20
|
||
[SW2-mst-region] active region-configuration
|
||
[SW2-mst-region]quit
|
||
[SW2]stp instance 10 priority 8192
|
||
[SW2]stp instance 20 priority 4096
|
||
[SW2]int g0/0/24
|
||
[SW2-GigabitEthernet0/0/24]port link-type trunk
|
||
[SW2-GigabitEthernet0/0/24]port trunk allow-pass vlan all
|
||
```
|
||
|
||
- 第四步:R3配置静态路由
|
||
|
||
- R1的配置
|
||
|
||
```
|
||
[R1]int g0/0/0
|
||
[R1-GigabitEthernet0/0/0]ip address 192.168.2.254 24
|
||
[R1-GigabitEthernet0/0/0]int g0/0/1
|
||
[R1-GigabitEthernet0/0/1]ip address 192.168.13.3 24
|
||
[R1-GigabitEthernet0/0/1]int g0/0/2
|
||
[R1-GigabitEthernet0/0/2]ip address 192.168.23.3 24
|
||
[R1-GigabitEthernet0/0/2]quit
|
||
[R1]ip route-static 192.168.10.0 24 192.168.13.1
|
||
[R1]ip route-static 192.168.10.0 24 192.168.23.1 preference 70
|
||
[R1]ip route-static 192.168.20.0 24 192.168.23.1
|
||
[R1]ip route-static 192.168.20.0 24 192.168.13.1 preference 70
|
||
```
|
||
|
||
- 第五步:验证
|
||
|
||
- VRRPPC1 ping server1 验证连通性
|
||
- PC1 tracert server1 验证数据转发路径
|
||
- PC2 ping server1 验证连通性
|
||
- PC2 tracert server1 验证数据转发路径
|
||
|
||
> 故障模拟:断开SW1的上行链路,验证数据转发路径断开SW1的下行链路,验证数据转发路径
|
||
|
||
### 九、知识总结
|
||
|
||
1. **VRRP**:虚拟路由器冗余协议
|
||
2. **VRRP的作用**:预防单点(单网关)故障,实现网关备份
|
||
3. **VRRP是公有协议,协议号是112,工作在网络层,数据报文封装在IP报头后面**
|
||
4. **VRRP的角色**
|
||
- master-主网关设备 backup-备份网关设备 虚拟路由器
|
||
- master: 负责转发用户数据
|
||
- backup: 监控主网关设备
|
||
- 虚拟路由器的IP地址:用户主机的网关地址
|
||
5. **VRRP的报文**
|
||
- 报文名字: VRRP通告报文,也称三层的心跳报文
|
||
- 报文怎么发: 周期性发送,每1秒发送一个报文
|
||
- 报文谁来发: master设备来发送这个VRRP通告
|
||
- 报文源IP: 报文的源IP:master设备物理接口IP地址
|
||
- 报文目的IP: 报文的目的地址:组播地址:224.0.0.18
|
||
- 报文中包含那些重要信息 : vrid 优先级 虚拟IP地址
|
||
6. **VRRP备份组**
|
||
- vrid : 备份组的组号, 也叫虚拟路由器标识符
|
||
- 在一个备份组中只有一个虚拟路由器,也只有一台master设备
|
||
- 在一个备份组中有虚拟IP地址,那么需不需要有虚拟MAC地址
|
||
7. **VRRP虚拟MAC**
|
||
- 虚拟MAC地址地址: 00005e0001-根据备份组号
|
||
- 如果备份组的组号是10 00005e0001-0a
|
||
8. **Master设备是如何选举的呢?**
|
||
- priority : 优先级
|
||
- 是根据优先级来选举的,优先级值范围: 0-255 默认值是100 数值越大越优先
|
||
- 如果优先级一致,则比较配置vrrp的那个物理接口的IP地址,IP地址越大越好
|
||
9. **VRRP的状态**
|
||
1. 初始化
|
||
2. 活动状态:master
|
||
3. 备份状态:backup
|
||
10. **VRRP主备选举**
|
||
1. 配置完vrrp的时候,设备的状态是 初始化
|
||
2. 如果设备的优先级低于255,则进入backup,然后在切换到master状态
|
||
3. 两台设备通过比较vrrp报文,来进行主备选举
|
||
4. 然后优先级高的成为master ,优先级低的成为backup
|
||
11. **VRRP主备切换**
|
||
- 第一种情况
|
||
1. master设备的vrrp的配置被人为的删除
|
||
2. master设备会发送一个优先级为0的vrrp报文
|
||
3. backup设备收到优先级为0的vrrp报文后,在等待一个偏移时间后,会升级为新的master
|
||
4. 切换的等待时间: 偏移时间: 256-优先级/256=0.5秒左右
|
||
- 第二种情况
|
||
1. master设备故障了,无法发送vrrp报文
|
||
2. backup设备等待 master_down 定时器超时后,(3倍的发送周期+偏移时间)
|
||
3. backup设备升级为新的master设备
|
||
4. 切换的等待时间,是3.5秒左右 (master-down定时器+偏移时间)
|
||
12. **两个定时器**
|
||
- VRRP通告报文-发送间隔定时器: 1秒
|
||
- master-down 定时器( 主路由器故障定时器):
|
||
- 3倍的发送间隔定时器:3秒 + 偏移时间: 256-优先级/256
|
||
- 256-130=126/256:0.49秒
|
||
- VRRP抢占模式:模式开启
|
||
13. **VRRP工作过程**
|
||
1. vrrp备份组中选举出master设备
|
||
2. master设备,发送用户数据,并且每隔1秒发送一个vrrp通告报文
|
||
3. backup设备,监控master设备
|
||
4. 如果master设备故障,则进行主备切换
|
||
5. 如果master设备故障恢复,并且开启抢占模式,则进行主备回切
|
||
|