vrrp虚拟ip地址怎么配置
1. 华为的VRRP怎么配置
VRRP配置
‘配置环境参数’
SwitchA通过E0/24与SwitchC相连,通过E0/23上行
SwitchB通过E0/24与SwitchC相连,通过E0/23上行
交换机SwitchA通过ethernet 0/24与SwitchB的ethernet 0/24连接到SwitchC
SwitchA和SwitchB上分别创建两个虚接口,interface vlan 10和interface 20做为三层接口,其中interface vlan 10分别包含ethernet 0/24端口,interface 20包含ethernet 0/23端口,做为出口。
‘组网需求’
SwitchA和 SwitchB之间做VRRP,interface vlan 10做为虚拟网关接口,Switch A为主设备,允许抢占,SwitchB为从设备,PC1主机的网关设置为VRRP虚拟网关地址192.168.100.1,进行冗余备份。访问远端主机PC2 10.1.1.1/24
2         数据配置步骤
‘两台交换机主备的配置流程’
通常一个网络内的所有主机都设置一条缺省路由,主机发往外部网络的报文将通过缺省路由发往该网关设备,从而实现了主机与外部网络的通信。当该设备发生故障时,本网段内所有以此设备为缺省路由下一跳的主机将断掉与外部的通信。VRRP就是为解决上述问题而提出的,它为具有多播或广播能力的局域网(如以太网)设计。VRRP可以将局域网的一组交换机(包括一个Master即活动交换机和若干个Backup即备份交换机)组织成一个虚拟路由器,这组交换机被称为一个备份组。
虚拟的交换机拥有自己的真实IP地址(这个IP地址可以和备份组内的某个交换机的接口地址相同),备份组内的交换机也有自己的IP地址。局域网内的主机仅仅知道这个虚拟路由器的IP地址(通常被称为备份组的虚拟IP地址),而不知道具体的Master交换机的IP地址以及Backup交换机的IP地址。局域网内的主机将自己的缺省路由下一跳设置为该虚拟路由器的IP地址。于是,网络内的主机就通过这个虚拟的交换机与其它网络进行通信。当备份组内的Master交换机不能正常工作时,备份组内的其它Backup交换机将接替不能正常工作的Master交换机成为新的Master交换机,继续向网络内的主机提供路由服务,从而实现网络内的主机不间断地与外部网络进行通信。
【SwitchA相关配置】
基础配置
1.      创建(进入)vlan10
[SwitchA] vlan 10
2.      将E0/24加入到vlan10
[SwitchA-vlan10] port Ethernet 0/24
3.      创建(进入)vlan20
[SwitchA]vlan 20
4.      将E0/23加入到vlan20
[SwitchA-vlan20]port Ethernet 0/23
5.      创建(进入)vlan20的虚接口
[SwitchA-vlan20]int vlan 20
6.      给vlan20的虚接口配置IP地址
[SwitchA-Vlan-interface20]ip add 11.1.1.1 255.255.255.252
7.      创建(进入)vlan10的虚接口
[SwitchA] interface vlan 10
8.      给vlan10的虚接口配置IP地址
[SwitchA-Vlan-interface10]ip address 192.168.100.2 255.255.255.0
9.      配置一条到对方网段的静态路由
[SwitchA]ip route-static 10.1.1.1 255.255.255.0 11.1.1.2
VRRP配置
1.      创建VRRP组1,虚拟网关为192.168.100.1
[SwitchA-Vlan-interface10]vrrp vrid 1 virtual-ip 192.168.100.1
2.      设置VRRP组优先级为120,缺省为100
[SwitchA-Vlan-interface10]vrrp vrid 1 priority 120
3.      设置为抢占模式
[SwitchA-Vlan-interface10]vrrp vrid 1 preempt-mode
4.      设置监控端口为为interface vlan 20,如果端口Down掉优先级降低30
[SwitchA-Vlan-interface10]vrrp vrid 1 track Vlan-interface 20 reced 30 
【SwitchB相关配置】
基础配置
1.      创建(进入)vlan10
[SwitchB] vlan 10
2.      加E0/24加入到vlan10
[SwitchB-vlan10] port Ethernet 0/24
3.      创建(进入)vlan20
[SwitchB]vlan 20
4.      将E0/23加入到vlan20
[SwitchB-vlan20]port Ethernet 0/23
5.      创建(进入)vlan20的虚接口
[SwitchB-vlan20]int vlan 20
6.      给vlan20的虚接口配置IP地址
[SwitchB-Vlan-interface20]ip add 12.1.1.1 255.255.255.252
7.      创建(进入)vlan10的虚接口
[SwitchB] interface vlan 10
8.      给vlan10的虚接口配置IP地址
[SwitchB-Vlan-interface10]ip address 192.168.100.3 255.255.255.0
9.      配置一条到对方网段的静态路由
[SwitchB]ip route-static 10.1.1.1 255.255.255.0 12.1.1.2
VRRP配置
1.      创建VRRP组1,虚拟网关为192.168.100.1
[SwitchB-Vlan-interface10]vrrp vrid 1 virtual-ip 192.168.100.1
2.      设置为抢占模式
[SwitchB-Vlan-interface10]vrrp vrid 1 preempt-mode
【SwitchC相关配置】
SwitchC在这里起端口汇聚作用,同时允许SwitchA和SwitchB发送心跳报文,可以不配置任何数据。
‘两台交换机负载分担的配置流程’
通过多备份组设置可以实现负荷分担。如交换机A作为备份组1的Master,同时又***备份组2的备份交换机,而交换机B正相反,作为备份组2的Master,并***备份组1的备份交换机。一部分主机使用备份组1作网关,另一部分主机使用备份组2作为网关。这样,以达到分担数据流,而又相互备份的目的。
【SwitchA相关配置】
1.      创建一个VRRP组1。
[SwitchA-vlan-interface10] vrrp vrid 1 virtual-ip 192.168.100.1
2.      设置VRRP组1的优先级比默认值高,保证SwitchA为此组的Master
[SwitchA-vlan-interface10] vrrp vrid 1 priority 150
3.      创建一个VRRP组2,优先级为默认值
[SwitchA-vlan-interface10] vrrp vrid 2 virtual-ip 192.168.100.2
【SwitchB相关配置】
1.      创建一个VRRP组1,优先级为默认值
[SwitchB-vlan-interface10] vrrp vrid 1 virtual-ip 192.168.100.1
2.      创建一个VRRP组2,优先级比默认值高,保证SwitchB为此组的Master
[SwitchB-vlan-interface10] vrrp vrid 2 virtual-ip 192.168.100.2
3.      设置备份组的优先级。
[SwitchB-vlan-interface10] vrrp vrid 2 priority 110
4.      此配置完成以后,SwitchC下面的用户可以部分以VRRP组1的虚地址为网关,一部分用户以VRRP组2的虚地址为网关。
【补充说明】
l         按RFC2338协议要求,VRRP虚地址是不能被PING通的,目前我们在产品具体实现中对其进行了扩展,VRRP虚地址可以被PING通。但是要求在配置VRRP之前在系统视图下先执行如下命令:(例如3526)[Quidway]vrrp ping-enable
l         优先级的取值范围为0到255(数值越大表明优先级越高),但是可配置的范围是1到254。优先级0为系统保留给特殊用途来使用,255则是系统保留给IP地址拥有者。缺省情况下,优先级的取值为100。
3         测试验证
将PC2通过SwitchC上行的两条链路任意断开一条,PC仍然能够正常PING通PC1
2. 华为交换机配置vrrp、mstp综合实验
;
1.PC1的网关ip位于汇聚交换机凳缺A,PC2的网关IP位于汇聚交换机B,默认均为vlan 1;
  
 2.核心交换机A 与核心交换机B 采用VRRP实现高可用,双机互联端口采用二层聚合;
  
 3.核心交换机A 指定为Vlan 194 和 vlan 192 的根桥(bridge root),核心交换机B指定为vlan195 和vlan193的根桥(bridge root);
  
  汇聚层交换机A: 
  
 #生成树的模式选为mstp
  
 stp mode mstp
  
 #进入生成树的配置模式
  
 stp region-configuration
  
  region-name yongfu
  
 #创建实例1,将vlan192、194划到实例1中
  
  instance 1 vlan 192 194 
  
 #创建实例1,将vlan193、195划到实例2中
  
  instance 2 vlan 193 195
  
 #激活配置
  
  active region-configuration
  
 interface Vlanif1
  
 #接入层交换机的网关ip
  
  ip address 10.12.192.254 255.255.255.128
  
 interface Vlanif192
  
  ip address 10.13.192.156 255.255.255.248
  
 interface Ethernet0/0/1
  
  port link-type trunk
  
  port trunk allow-pass vlan 2 to 4094
  
 interface Ethernet0/0/2
  
  port link-type trunk
  
  port trunk allow-pass vlan 2 to 4094
  
 #配置环枣茄辩回接口的IP地址
  
 interface LoopBack0
  
  ip address 1.1.1.1 255.255.255.0
  
 #配置route-id 1.1.1.1
  
 ospf 1 router-id 1.1.1.1
  
  area 0
  
 #宣告直连网络
  
   network 10.13.192.0 0.0.0.255
  
   network 10.12.192.128 0.0.0.127
  
  汇聚层交换机B:纳空 
  
 vlan batch 193
  
 stp mode mstp
  
 stp region-configuration
  
  region-name yongfu
  
  instance 1 vlan 192 194
  
  instance 2 vlan 193 195
  
  active region-configuration
  
 interface Vlanif1
  
 #pc2的网关ip
  
  ip address 10.14.192.126 255.255.255.128
  
 interface Vlanif193
  
  ip address 10.13.193.156 255.255.255.248
  
 interface Ethernet0/0/1
  
  port link-type trunk
  
  port trunk allow-pass vlan 193
  
 interface Ethernet0/0/2
  
  port link-type trunk
  
  port trunk allow-pass vlan 193
  
 #配置ospf,手动设置route-id
  
 ospf 1 router-id 2.2.2.2
  
  area 0
  
 #宣告直连网段
  
   network 10.14.192.0 0.0.0.127
  
   network 10.13.193.152 0.0.0.7
  
  核心交换机lsw1: 
  
 #创建vlan192-195
  
 vlan batch 192 to 195
  
 #指定该交换机为实例1的根网桥(即为vlan 192、194的根桥)
  
 stp instance 1 root primary
  
 #指定该交换机为实例2的根网桥(即为vlan 193、195的备根桥)
  
 stp instance 2 root secondary
  
 #配置mstp生成树协议
  
 stp mode mstp
  
 stp region-configuration
  
  region-name yongfu
  
  instance 1 vlan 192 194
  
  instance 2 vlan 193 195
  
  active region-configuration
  
 interface Vlanif192
  
  ip address 10.13.192.153 255.255.255.248
  
 #配置vrrp协议,vrid为192,虚拟网关地址为10.13.192.155
  
  vrrp vrid 192 virtual-ip 10.13.192.155
  
 #默认优先级是100,现将优先级设置为120,为主网关设备
  
  vrrp vrid 192 priority 120
  
 interface Vlanif193
  
  ip address 10.13.193.153 255.255.255.248
  
 #不配置优先级,默认为100,作为备用网关
  
  vrrp vrid 193 virtual-ip 10.13.193.155
  
 interface Vlanif194
  
  ip address 10.13.194.1 255.255.255.248
  
  vrrp vrid 194 virtual-ip 10.13.194.3
  
  vrrp vrid 194 priority 120
  
 interface Vlanif195
  
  ip address 10.13.195.1 255.255.255.248
  
  vrrp vrid 195 virtual-ip 10.13.195.3
  
 #配置聚合口
  
 interface Eth-Trunk1
  
  port link-type trunk
  
 #放通所有vlan
  
  port trunk allow-pass vlan 2 to 4094
  
 #将接口划分为对应的vlan
  
 interface GigabitEthernet0/0/1
  
  port link-type trunk
  
  port trunk allow-pass vlan 192
  
 interface GigabitEthernet0/0/2
  
  port link-type trunk
  
  port trunk allow-pass vlan 193
  
 #将GigabitEthernet0/0/3、GigabitEthernet0/0/4捆绑成一个聚合口
  
 interface GigabitEthernet0/0/3
  
  eth-trunk 1
  
 interface GigabitEthernet0/0/4
  
  eth-trunk 1
interface GigabitEthernet0/0/5
  
  port link-type trunk
  
  port trunk allow-pass vlan 2 to 4094
interface GigabitEthernet0/0/6
  
  port link-type trunk
  
  port trunk allow-pass vlan 2 to 4094
  
 #配置ospf,进程号为1,route-id为3.3.3.3
  
 ospf 1 router-id 3.3.3.3
  
  area 0.0.0.0
  
 #宣告直连网段
  
   network 10.13.192.152 0.0.0.7
  
   network 10.13.193.152 0.0.0.7
  
   network 10.13.194.0 0.0.0.7
  
   network 10.13.195.0 0.0.0.7
  
 ip route-static 19.130.107.0 255.255.255.192 10.13.194.5
  
  核心交换机lsw2:(配置与lsw1相似) 
  
  #创建vlan192-195 
  
 vlan batch 192 to 195
  
 stp mode mstp
  
 stp instance 2 root primary
  
 stp instance 1 root secondary
  
 stp region-configuration
  
  region-name yongfu
  
  instance 1 vlan 192 194
  
  instance 2 vlan 193 195
  
  active region-configuration
  
 #配置个接口的ip地址,配置vrrp,设置主、备网关
  
 interface Vlanif192
  
  ip address 10.13.192.154 255.255.255.248
  
  vrrp vrid 192 virtual-ip 10.13.192.155
  
 interface Vlanif193
  
  ip address 10.13.193.154 255.255.255.248
  
  vrrp vrid 193 virtual-ip 10.13.193.155
  
  vrrp vrid 193 priority 120
  
 interface Vlanif194
  
  ip address 10.13.194.2 255.255.255.248
  
  vrrp vrid 194 virtual-ip 10.13.194.3
  
 interface Vlanif195
  
  ip address 10.13.195.2 255.255.255.248
  
  vrrp vrid 195 virtual-ip 10.13.195.3
  
  vrrp vrid 195 priority 120
  
 interface Eth-Trunk1
  
  port link-type trunk
  
  port trunk allow-pass vlan 2 to 4094
  
 interface GigabitEthernet0/0/1
  
  port link-type trunk
  
  port trunk allow-pass vlan 192
  
 interface GigabitEthernet0/0/2
  
  port link-type trunk
  
  port trunk allow-pass vlan 193
  
 interface GigabitEthernet0/0/3
  
  eth-trunk 1
  
 interface GigabitEthernet0/0/4
  
  eth-trunk 1
  
 interface GigabitEthernet0/0/5
  
  port link-type trunk
  
  port trunk allow-pass vlan 2 to 4094
  
 interface GigabitEthernet0/0/6
  
  port link-type trunk
  
  port trunk allow-pass vlan 2 to 4094
  
  交换机lsw14: 
  
 vlan batch 194
  
 stp mode mstp 
  
 stp region-configuration
  
  region-name yongfu
  
  instance 1 vlan 192 194
  
  instance 2 vlan 193 195
  
  active region-configuration
  
 interface Vlanif1
  
  ip address 10.13.192.133 255.255.255.252
  
 interface Vlanif194
  
  ip address 10.13.194.5 255.255.255.248
  
 interface Ethernet0/0/1
  
  port link-type trunk
  
  port trunk allow-pass vlan 194
  
 interface Ethernet0/0/2
  
  port link-type trunk
  
  port trunk allow-pass vlan 194
  
 #配置ospf,进程号为1,route-id 5.5.5.5
  
 ospf 1 router-id 5.5.5.5
  
  area 0.0.0.0
  
   network 10.13.194.0 0.0.0.7
  
   network 10.13.192.132 0.0.0.3
  
 ip route-static 19.130.107.0 255.255.255.0 10.13.192.134
  
  交换机lsw15: 
  
 vlan batch 195
  
 stp mode mstp
  
 stp region-configuration
  
  region-name yongu
  
  instance 1 vlan 192 194
  
  instance 2 vlan 193 195
  
  active region-configuration
  
 interface Vlanif1
  
  ip address 10.13.192.149 255.255.255.252
  
 interface Vlanif195
  
  ip address 10.13.195.5 255.255.255.248
  
 interface Ethernet0/0/1
  
  port link-type trunk
  
  port trunk allow-pass vlan 195
  
 interface Ethernet0/0/2
  
  port link-type trunk
  
  port trunk allow-pass vlan 195
  
 ospf 1 router-id 6.6.6.6
  
  area 0.0.0.0
  
   network 10.13.192.148 0.0.0.3
  
   network 10.13.195.0 0.0.0.7
  
 ip route-static 61.142.211.0 255.255.255.0 10.13.192.150
  
  出口路由器R1: 
  
 interface Ethernet0/0/0
  
  ip address 10.13.192.134 255.255.255.252
  
 interface Ethernet0/0/1
  
  ip address 19.130.107.1 255.255.255.0
  
 ospf 1 router-id 7.7.7.7
  
  area 0.0.0.0
  
   network 10.13.192.132 0.0.0.3
  
   network 19.130.107.0 0.0.0.255
  
 ip route-static 0.0.0.0 0.0.0.0 10.13.192.133
  
  出口路由器R2: 
interface Ethernet0/0/0
  
  ip address 10.13.192.150 255.255.255.252
  
 interface Ethernet0/0/1
  
 interface GigabitEthernet0/0/0
  
  ip address 61.142.211.122 255.255.255.0
  
  nat static global 61.142.211.123 inside 10.12.194.1 netmask 255.255.255.255
  
  nat static enable
  
 ospf 1 router-id 8.8.8.8
  
  area 0.0.0.0
  
   network 10.13.192.148 0.0.0.3
  
   network 61.142.211.0 0.0.0.255
  
 ip route-static 0.0.0.0 0.0.0.0 10.13.192.149
3. 请教思科4506核心交换机vrrp及策略路由的配置
RG-S35A(config-if)#ip address 192.168.10.254 255.255.255.0 !配置VLAN10的IP地址 
RG-S35A(config-if)#standby 1 ip 192.168.10.250  !配置虚拟IP 
RG-S35A(config-if)#standby 1 preempt !设为抢占模式 
RG-S35A(config-if)#standby 1 priority 254 !VLAN10的standby优先级设为254 
RG-S35A(config-if)#exit 
RG-S35A(config)#interface vlan 20 !VLAN20的standby不设优先级,默认为100 
RG-S35A(config-if)#ip address 192.168.20.253 255.255.255.0 !配置VLAN20的IP地址 
RG-S35A(config-if)#standby 2 ip 192.168.20.250  !配置虚拟IP 
RG-S35A(config-if)#standby 2 preempt !设为抢占模式 
RG-S35A(config-if)#exit
4. Windows、linux和路由器的网络子接口-虚拟IP
    前段时间在调试时,将外网接入内部局域网,然后使用向日葵远程连接调试。Windows一个网络适配器只能设置一个IP地址,后面才发现可以通过网络子接口来设置虚拟IP,内部网络通过正常的IP地址通信,外部网络通过子接口来进行通信,即一个物理网口上连接两个子网。Windows可以设置网络子接口,笔者就延申到Linux系统上,总结在不同平台设置网络子接口的方法。需要明确的是,虚拟IP的数据还是经过真实的物理网络接口。简而言之,网卡设备都有一个MAC地址,但是却可以有多个网络层IP地址。
  
     本文以Windows10和CentOS8为例。
  
      Windows平台上: 
  
     微软官网对于网络子接口有这样的描述:
  
 1)一个逻辑IP网络正在使用中,并且此计算机需要使用多个IP地址才能在该网络上进行通信。
  
 2)正在使用多个逻辑IP网络,并且此计算机需要一个不同的IP地址才能与每个不同的逻辑IP网络进行通信。
  
     当不使用“常规”选项卡上的“自动获取IP地址”时,才可以使用“高级TCP/IP设置”进行此网络连接,来完成高级IP寻址。在设置里面,Interface metric 接口度量标准(跃点数)可以设置该接口的优先级,接口度量标准的值越小,表示使用该接口的优先级越高。自动度量标准(自动跃点),最高速度的接口具有最低的接口度量值,优先级越高。
                                          
  Linux平台上: 
  
     Linux平台上虚拟ip基本上都用于高可用的架构上,比如keepalived就是通过托管VIP里完成飘逸,可以参考笔者以前的文章-Keepalived让树莓派也可以VIP漂移。其实这一篇文章对于keepalived也会有很好的理解了。看一下文章里面的Keepalived后通过ip addr查看的结果。
                                          
     VRRP协议来通信完成心跳检测,然后使用辅助IP的ip addr add 来添加虚拟IP地址,主用不在线就del掉VIP,然后在从机上add 同样的VIP。为什么不是ifconfig命令呢,那就需要你仔细看看关键信息找区别了,如果你安装了的话可以使用ifconfig来确定是否能够查看到VIP。
  
     接下里我们就看看在Linux中创建虚拟IP有两种方法,分别是:别名IP(IP aliases)和辅助IP(secondary IP addresses)。
  
     1、别名IP是通过ifconfig命令去创建和操作的虚拟ip。
  
  sudo ifconfig enp0s3:1 192.168.31.5 broadcast 192.168.31.255 netmask 255.255.255.0 up
                                          
     删除别名IP,将up改为down。
  
 sudo ifconfig enp0s3:1 192.168.31.5 broadcast 192.168.31.255 netmask 255.255.255.0 down
  
     如果开机就需要别名IP地址的话,需要到/etc/sysconfig/network-scripts目录下新建一个子接口来永久性修改配置文件。将原ifcfg-enp0s3文件复制后,然后修改其中的IP地址信息。
  
     cp ifcfg-enp0s3 ifcfg-enp0s3:1
  
     为了方便也可以将ifconfig命令去创建和操作的虚拟ip的命令加入到开机启动中,详情参考笔者以前的文章-Linux设置脚本开机启动的四种方法。
  
 2、辅助IP是由linux的ip命令去创建和操作的。
  
 sudo  ip addr add 192.168.31.5/24 brd 192.168.31.255 dev enp0s3 label enp0s3:1
                                          
     设置完成后,也可以通过ifconfig来查看。但是如果在命令后面不添加label enp0s3:1的话,那么ifconfig就不能查看了。
  
     删除辅助IP,将add替换成del即可。
  
 sudo  ip addr del 192.168.31.5/24 brd 192.168.31.255 dev enp0s3 label enp0s3:1
  
     辅助IP需要持久化的话,只能将ip命令去创建和操作的虚拟ip的命令加入到开机启动中了。
  
       路由器通信设备: 
  
        路由器接口有限, 一个物理接口可以配置子接口(逻辑接口)的方式来实现一当多的功能。具体配置参考笔者的文章-eNSP模拟实验-单臂路由实现VLAN间通信。
