VRRP(虚拟路由器冗余协议)是一种选择协议,它可以把一个虚拟路由器的责任动态分配到局域网上的 VRRP 路由器中的一台。控制虚拟路由器 IP 地址的 VRRP 路由器称为主路由器,它负责转发数据包到这些虚拟 IP 地址。一旦主路由器不可用,这种选择过程就提供了动态的故障转移机制,这就允许虚拟路由器的 IP 地址可以作为终端主机的默认第一跳路由器。使用 VRRP 的好处是有更高的默认路径的可用性而无需在每个终端主机上配置动态路由或路由发现协议。

      VRRP中定义了三种状态模型,初始状态Initialize,活动状态Master和备份状态Backup,其中只有活动状态的交换机可以为到虚拟IP地址的的转发请求提供服务。

      虚拟交换机根据配置的优先级的大小选择主交换机,优先级最大的作为主交换机,状态为Master,若优先级相同(如果交换机没有配置优先级,就采用默认值100),则比较接口的主IP地址,主IP地址大的就成为主交换机,由它提供实际的路由服务。其他交换机作为备份交换机,随时监测主交换机的状态。当主交换机正常工作时,它会每隔一段时间发送一个VRRP组播报文,以通知组内的备份交换机,主交换机处于正常工作状态。如果组内的备份交换机长时间没有接收到来自主交换机的VRRP组播报文,则将自己状态转换为Master。当组内有多台备份交换机,将有可能产生多个主交换机。这时每一个主交换机就会比较VRRP报文中的优先级和自己本地的优先级,如果本地的优先级小于VRRP中的优先级,则将自己的状态转换为Backup,否则保持自己的状态不变。通过这样一个过程,就会将优先级最大的交换机选成新的主交换机,完成VRRP的备份功能。

      VRRP协议的工作机理与CISCO公司的HSRP(Hot Standby Routing Protocol)有许多相似之处。但二者主要的区别是在CISCO的HSRP中,需要单独配置一个IP地址作为虚拟路由器对外体现的地址,这个地址不能是组中任何一个成员的接口地址

      下面我们还是举这个例子,可以和上一篇的hsrp相对照:

      有一家公司有两台路由器,想做的负载均衡,让公司的两个vlan走不同的路径上网,(两个vlan间通信也走不同路径),如vlan10的从左边路由上网,vlan20的走右边上网,当某一台路由器坏掉时,两个vlan也能正常上网,其简易的拓扑图如下:

wps_clip_p_w_picpath-28521

路由器R1的配置:

sysname R1       更改名称为R1

int e0             进入e0端口

ip address 192.168.1.2 255.255.255.0   给e0端口配置ip

int e1.10         进入e1的子接口

vlan-type dot1q vid 10      封装相应的协议dot1q,和相应的vlan号

ip address 192.168.10.1 255.255.255.0    给子接口e1.10配置ip

interface Ethernet1.20     进入e1的另一子接口

vlan-type dot1q vid 20     将子接口封装为dot1q协议,并写出相应vlan号

ip address 192.168.20.1 255.255.255.0     给这个子接口配置ip

quit

vrrp ping-enable       开启vrrp

int e1.10             进到e1.10子接口

vrrp vrid 10 virtual-ip 192.168.10.254    将子接口划分到相应的vrrp组中并指定虚拟ip

vrrp vrid 10 priority 120                配置此接口的优先级120,默认值为100

vrrp vrid 10 track Ethernet0 reduced 30   配置追踪信息,当e0不通时,自动降优先级30

interface Ethernet1.20                 进到e1.20子接口

vrrp vrid 20 virtual-ip 192.168.20.254    配置虚拟ip

quit

ip route-static 0.0.0.0 0.0.0.0 192.168.1.1    配置默认路由,以便和外网通信

acl 2000        建一个访问控制列表

rule permit source any     设置列表信息,允许所有的源ip通过

quit

interface Ethernet0           

nat outbound 2000 interface    当符合列表2000外出的地址都转换成此端口的地址出去

查看配置的信息命令:

[R1]dis cu

  Now create configuration...

  Current configuration

  !

    version 1.74

    local-user user1 service-type administrator password simple 123

    sysname R1

    undo pos-server addr-switch

    firewall enable

    aaa-enable

    aaa accounting-scheme optional

    vrrp ping-enable

  !

  acl 2000 match-order auto

    rule normal permit source any

  !

  controller e1 0

  !

  interface Aux0

    async mode flow

    link-protocol ppp

  !

  interface Ethernet0        外出接口e0的信息

    ip address 192.168.1.2 255.255.255.0

    nat outbound 2000 interface          

  !

  interface Ethernet1

  !

  interface Ethernet1.10       子接口e1.10的信息

    vlan-type dot1q vid 10

    ip address 192.168.10.1 255.255.255.0

    vrrp vrid 10 virtual-ip 192.168.10.254

    vrrp vrid 10 priority 120

    vrrp vrid 10 track Ethernet0 reduced 30

  !

  interface Ethernet1.20      子接口e1.20的信息

    vlan-type dot1q vid 20

    ip address 192.168.20.1 255.255.255.0

    vrrp vrid 20 virtual-ip 192.168.20.254

  !

  interface Serial0

    link-protocol ppp

  !

  interface Serial1

    link-protocol ppp

  !

  interface Async0

    physical-mode async                  

    async mode protocol

    link-protocol ppp

  !

  interface Async1

    physical-mode async

    async mode protocol

    link-protocol ppp

  !

  interface Async2

    physical-mode async

    async mode protocol

    link-protocol ppp

  quit

  ip route-static 0.0.0.0 0.0.0.0 192.168.1.1 preference 60      默认路由信息

  !

  Return

查看vrrp的详细信息

[R1]dis vrrp

   Ethernet1.20 | Virtual Router 20

       state : Backup

  Virtual IP : 192.168.20.254     虚拟ip

    Priority : 100               默认优先级100

     Preempt : YES   Delay Time : 0      华为的抢占模式是默认开启的

       Timer : 1

   Auth Type : NO

   Ethernet1.10 | Virtual Router 10

       state : Backup

  Virtual IP : 192.168.10.254

    Priority : 90

     Preempt : YES   Delay Time : 0

       Timer : 1

   Auth Type : NO

    Track IF : Ethernet0   Priority reduced : 30    追踪e0端口, 和减少优先级30

路由器R2的配置:

sysname R2

interface Ethernet0.10      

vlan-type dot1q vid 10

ip address 192.168.10.2 255.255.255.0

interface Ethernet0.20

vlan-type dot1q vid 20

ip address 192.168.20.2 255.255.255.0

interface Ethernet1

ip address 192.168.2.2 255.255.255.0

quit

vrrp ping-enable

interface Ethernet0.10      此处的R2的e0.10没有配置优先级,是因为实现vlan间通信的负载均衡,让vlan10 走的是R1路由器。

vrrp vrid 10 virtual-ip 192.168.10.254

interface Ethernet0.20

vrrp vrid 20 virtual-ip 192.168.20.254

vrrp vrid 20 priority 120            此处配置优先级120,大于R1  vlan20的优先级,实现了vlan20走的R2路由器

vrrp vrid 20 track Ethernet1 reduced 30     追踪端口,当e1端口不通信,就减少优先级30,然后R1的相应接口会自动启动抢占模式

quit

acl 2000

rule permit source any

quit

interface Ethernet1

nat outbound 2000 interface

quit

ip route-static 0.0.0.0 0.0.0.0 192.168.2.1

查看R2信息命令:

[R2]dis cu

  Now create configuration...

  Current configuration

  !

    version 1.74

    local-user user1 service-type administrator password simple 123

    sysname R2

    firewall enable

    aaa-enable

    aaa accounting-scheme optional

    vrrp ping-enable

  !

  acl 2000 match-order auto

    rule normal permit source any

  !

  interface Aux0

    async mode flow

    link-protocol ppp

  !

  interface Ethernet0

  !

  interface Ethernet0.10

    vlan-type dot1q vid 10

    ip address 192.168.10.2 255.255.255.0

    vrrp vrid 10 virtual-ip 192.168.10.254

  !

  interface Ethernet0.20

    vlan-type dot1q vid 20

    ip address 192.168.20.2 255.255.255.0

    vrrp vrid 20 virtual-ip 192.168.20.254

    vrrp vrid 20 priority 120

    vrrp vrid 20 track Ethernet1 reduced 30

  !

  interface Ethernet1

    ip address 192.168.2.2 255.255.255.0

    nat outbound 2000 interface

  !

  interface Serial0

    link-protocol ppp

  !

  interface Serial1

    link-protocol ppp

  !

  interface Async0

    physical-mode async

    async mode protocol

    link-protocol ppp

  !                                      

  interface Async1

    physical-mode async

    async mode protocol

    link-protocol ppp

  voice-setup

    !

    subscriber-line 0

    !

    subscriber-line 1

    !

    quit

  !

  quit

  ip route-static 0.0.0.0 0.0.0.0 192.168.2.1 preference 60

  !

  return

查看vrrp详细信息:

[R2]dis vrrp

   Ethernet0.20 | Virtual Router 20

       state : Master

  Virtual IP : 192.168.20.254

    Priority : 120

     Preempt : YES   Delay Time : 0

       Timer : 1

   Auth Type : NO

    Track IF : Ethernet1   Priority reduced : 30

   Ethernet0.10 | Virtual Router 10

       state : Master

  Virtual IP : 192.168.10.254

    Priority : 100

     Preempt : YES   Delay Time : 0

       Timer : 1

   Auth Type : NO

路由器R3的配置:

sysname R3

interface Ethernet0    

ip address 192.168.1.1 255.255.255.0    配置e0的ip

interface Ethernet1

ip address 192.168.2.1 255.255.255.0    给e1端口相应的ip

interface LoopBack1                  设置一个loopback端口作为外网

ip address 202.102.224.25 255.255.255.0    给loopback端口相应的ip

查看命令:

[R3]dis cu

  Now create configuration...

  Current configuration

  !

    version 1.74

    local-user user1 service-type administrator password simple 123

    sysname R3

    firewall enable

    aaa-enable

    aaa accounting-scheme optional

  !

  interface Aux0

    async mode flow

    link-protocol ppp

  !

  interface Ethernet0

    ip address 192.168.1.1 255.255.255.0

  !

  interface Ethernet1

    ip address 192.168.2.1 255.255.255.0

  !

  interface Serial0

    link-protocol ppp

  !

  interface Serial1

    link-protocol ppp                    

  !

  interface Async0

    physical-mode async

    async mode protocol

    link-protocol ppp

  !

  interface Async1

    physical-mode async

    async mode protocol

    link-protocol ppp

  !

  interface Async2

    physical-mode async

    async mode protocol

    link-protocol ppp

  !

  interface LoopBack1

    ip address 202.102.224.25 255.255.255.0

  !

  Return

交换机SW1的配置:

sysname SW1    改成 相应名称

vlan 10         创建vlan10

port link-type eth0/3 to eth0/10     把相应端口加入到vlan10 中

quit

vlan 20             创建vlan20

port link-type eth0/11 to eth0/15     把相应端口加入到vlan20 中

interface Ethernet0/2

port link-type trunk       把此端口设置成trunk

port trunk permit vlan all   允许所有vlan通过,默认只允许vlan1通过

quit

interface Ethernet0/24

port link-type trunk        把此端口设置成trunk

port trunk permit vlan all     允许所有vlan通过,默认只允许vlan1通过

 

查看相应的命令:

<SW1>dis cu

#

sysname SW1

#

radius scheme system

server-type huawei

primary authentication 127.0.0.1 1645

primary accounting 127.0.0.1 1646

user-name-format without-domain

domain system

radius-scheme system

access-limit disable

state active

idle-cut disable

self-service-url disable

messenger time disable

domain default enable system

#

local-server nas-ip 127.0.0.1 key huawei

local-user user1

password simple 123

service-type telnet level 3             

#

queue-scheduler wrr 1 2 4 8

#

vlan 1

#

vlan 10

#

vlan 20

#

interface Vlan-interface1

ip address 192.168.1.9 255.255.255.0

#

interface Aux0/0

#

interface Ethernet0/1

#

interface Ethernet0/2

port link-type trunk

port trunk permit vlan all

#

interface Ethernet0/3

port access vlan 10

#                                        

interface Ethernet0/4

port access vlan 10

#

#

interface Ethernet0/10

port access vlan 10

#

interface Ethernet0/11                   

port access vlan 20

#

#

interface Ethernet0/15

port access vlan 20

#

#

interface Ethernet0/24

port link-type trunk

port trunk permit vlan all

#

interface Ethernet0/25

#

interface NULL0

#

user-interface aux 0

user-interface vty 0 4

authentication-mode scheme

#

return

交换机SW2的配置:

sysname SW2

vlan 10

port link-type eth0/3 to eth0/10     

quit

vlan 20

port link-type eth0/11 to eth0/15

interface Ethernet0/2

port link-type trunk

port trunk permit vlan all

quit

interface Ethernet0/24

port link-type trunk

port trunk permit vlan all

查看命令:

<SW2>dis cu

#

sysname SW2

#

radius scheme system

server-type huawei

primary authentication 127.0.0.1 1645

primary accounting 127.0.0.1 1646

user-name-format without-domain

domain system

radius-scheme system

access-limit disable

state active

idle-cut disable

self-service-url disable

messenger time disable

domain default enable system

#

local-server nas-ip 127.0.0.1 key huawei

#

queue-scheduler wrr 1 2 4 8

#

vlan 1                                   

#

vlan 10

#

vlan 20

#

interface Aux0/0

#

interface Ethernet0/1

#

interface Ethernet0/2

port link-type trunk

port trunk permit vlan all

#

interface Ethernet0/3

port access vlan 10

#

interface Ethernet0/4

port access vlan 10

#

#

interface Ethernet0/10

port access vlan 10

#

interface Ethernet0/11

port access vlan 20

#

#

interface Ethernet0/15

port access vlan 20

#

#

interface Ethernet0/24

port link-type trunk

port trunk permit vlan all

#

interface Ethernet0/25

#

interface NULL0

#

user-interface aux 0

user-interface vty 0 4

#

Return

最后的通信结果:

Vlan10中机器的ip配置;

wps_clip_p_w_picpath-3788

Vlan20中机器的ip配置:

wps_clip_p_w_picpath-27528

看它们的通信情况:

首先Vlan10上的机器ping  vlan20上的机器:

wps_clip_p_w_picpath-20182

其追踪的路径:

wps_clip_p_w_picpath-31191

再看vlan20中的机器pingvlan10中的机器:

和其追踪走的路径:

C:\Users\likang&gt;ping 192.168.10.100

正在 Ping 192.168.10.1 具有 32 字节的数据:

来自 192.168.10.1 的回复: 字节=32 时间<1ms TTL=255

来自 192.168.10.1 的回复: 字节=32 时间&lt;1ms TTL=255

来自 192.168.10.1 的回复: 字节=32 时间&lt;1ms TTL=255

来自 192.168.10.1 的回复: 字节=32 时间&lt;1ms TTL=255

192.168.10.1 的 Ping 统计信息:

    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),

往返行程的估计时间(以毫秒为单位):

    最短 = 0ms,最长 = 0ms,平均 = 0ms

C:\Users\likang>tracert 192.168.10.100

通过最多 30 个跃点跟踪

到 SF-PC [192.168.10.100] 的路由:

  1    <1 毫秒    6 ms    &lt;1 毫秒 192.168.20.1           可以看到vlan20中的机器和vlan10通信走的是R2路由器

  2     1 ms    &lt;1 毫秒   &lt;1 毫秒 SF-PC [192.168.10.100]

跟踪完成。

 

这样就完成了vlan间通信的负载均衡。

Vlan10机器ping外网的结果:

和其追踪的路径:

wps_clip_p_w_picpath-30147

Vlan20中的机器ping外网和追踪的路径:

C:\Users\likang>ping 202.102.224.25

正在 Ping 202.102.224.25 具有 32 字节的数据:

来自 202.102.224.25 的回复: 字节=32 时间<1ms TTL=254

来自 202.102.224.25 的回复: 字节=32 时间=1ms TTL=254

来自 202.102.224.25 的回复: 字节=32 时间=3ms TTL=254

来自 202.102.224.25 的回复: 字节=32 时间=2ms TTL=254

202.102.224.25 的 Ping 统计信息:

    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),

往返行程的估计时间(以毫秒为单位):

    最短 = 0ms,最长 = 3ms,平均 = 1ms

C:\Users\likang>tracert 202.102.224.25

通过最多 30 个跃点跟踪到 202.102.224.25 的路由

  1    &lt;1 毫秒   &lt;1 毫秒   &lt;1 毫秒 192.168.20.2         走的是R2路由器,

  2    &lt;1 毫秒   &lt;1 毫秒   &lt;1 毫秒 202.102.224.25

跟踪完成。

这样和外网通信也完成了负载均衡。

当shutdown掉路由器R1上的e0端口:

Vlan10上的机器ping外网和追踪的路径:

wps_clip_p_w_picpath-22565

说明我们成功的完成了。

 

 

 

还有很多不足之处,请多指教!