A-A+

【思科】VRRP热备路由协议实验

2015年12月12日 站长资讯 暂无评论

实验拓扑:

3台路由器R1、R3、R2和交换机R4连成一个环状,R4除了连接R1外,还连接了两台PC(C1和C2)。图略。

实验需求:

假设R3路由器为外网路由器,上面有一条虚拟网段3.3.3.0,模拟外网。

C1为vlan10 ,C2为vlan 20。

R1作为vlan10的主路由器,vlan20的备用路由器。R2作为vlan10的备用路由器,vlan10的主路由器。

测试热备路由的效果。

实验步骤:

配置C1,C2的IP地址,配置交换机R4

  1. R4#conf t  
  2. Enter configuration commands, one per line.  End with CNTL/Z.  
  3. R4(config)#no ip routing  
  4. R4(config)#vlan 10,20  
  5. R4(config-vlan)#ex  
  6. R4(config)#int f1/1  
  7. R4(config-if)#switchport access vlan 10  
  8. R4(config-if)#int f1/2                   
  9. R4(config-if)#switchport access vlan 20  
  10. R4(config-if)#int f1/3                   
  11. R4(config-if)#int range f1/3 -4  
  12. R4(config-if-range)#switchport mode trunk   
  13. R4(config-if-range)#  
  14. *Mar  1 00:04:35.099: %DTP-5-TRUNKPORTON: Port Fa1/3-4 has become dot1q trunk  

2.配置R1

  1. R1#conf t  
  2. Enter configuration commands, one per line.  End with CNTL/Z.  
  3. R1(config)#ip routing                   //开启路由  
  4. R1(config)#int f1/4  
  5. R1(config-if)#no sh  
  6. R1(config-if)#switchport mode trunk   
  7. R1(config-if)#  
  8. *Mar  1 00:05:45.635: %DTP-5-TRUNKPORTON: Port Fa1/4 has become dot1q trunk  
  9. R1(config)#track 1 int f1/3 line-protocol                    
  10. R1(config-track)#track 2 int f1/4 line-protocol            //创建监听端口  
  11. R1(config)#vlan 10  
  12. R1(config-vlan)#vlan 20      
  13. R1(config-vlan)#ex  

(1)配置vlan 10

  1. R1(config)#int vlan 10  
  2. R1(config-if)#ip add 192.168.10.10 255.255.255.0  
  3. R1(config-if)#no sh  
  4. R1(config-if)#ex    
  5. *Mar  1 00:07:54.263: %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to up  
  6. R1(config-vlan)#ex  
  7. R1(config)#int vlan 10  
  8. R1(config-if)#vrrp 1 ?  
  9.   authentication  Authentication  
  10.   description     Group specific description  
  11.   ip              Enable Virtual Router Redundancy Protocol (VRRP) for IP  
  12.   preempt         Enable preemption of lower priority Master  
  13.   priority        Priority of this VRRP group  
  14.   shutdown        Disable VRRP Configuration  
  15.   timers          Set the VRRP timers   
  16.   track           Event Tracking  
  17.   
  18. R1(config-if)#vrrp 1 ip 192.168.10.1         //虚拟网关IP  
  19. *Mar  1 00:09:20.763: %VRRP-6-STATECHANGE: Vl10 Grp 1 state Init -> Backup          
  20. *Mar  1 00:09:24.375: %VRRP-6-STATECHANGE: Vl10 Grp 1 state Backup -> Master  
  21. R1(config-if)#vrrp 1 preempt                  //设置抢占  
  22. R1(config-if)#vrrp 1 priority 100             //设置优先级,主要高于备用优先级  
  23. R1(config-if)#vrrp 1 track 1                  //设置监听端口  
  24. R1(config-if)#vrrp 1 track 2  

(2)配置vlan 20

  1. R1(config)#int vlan 20    
  2. *Mar  1 00:10:39.051: %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to up  
  3. R1(config-if)#ip add 192.168.20.10 255.255.255.0  
  4. R1(config-if)#no sh  
  5. R1(config-if)#vrrp 2 ip 192.168.20.1                
  6. *Mar  1 00:11:02.399: %VRRP-6-STATECHANGE: Vl20 Grp 2 state Init -> Backup       
  7. R1(config-if)#vrrp 2 preempt   
  8. *Mar  1 00:11:06.007: %VRRP-6-STATECHANGE: Vl20 Grp 2 state Backup -> Master    
  9. R1(config-if)#vrrp 2 priority 95              //要低于主路由器的优先级  
  10. *Mar  1 00:12:58.911: %VRRP-6-STATECHANGE: Vl10 Grp 1 state Master -> Backup  
  11. *Mar  1 00:13:09.515: %VRRP-6-STATECHANGE: Vl10 Grp 1 state Backup -> Master  
  12. *Mar  1 00:13:47.295: %VRRP-6-STATECHANGE: Vl20 Grp 2 state Master -> Backup  

3.配置R2

  1. R2#conf t www.xiaoxiongboke.com/cisco  
  2. Enter configuration commands, one per line.  End with CNTL/Z.  
  3. R2(config)#ip routing  
  4. R2(config)#int f1/4  
  5. R2(config-if)#no sh  
  6. R2(config-if)#switchport mode trunk   
  7. R2(config-if)#  
  8. *Mar  1 00:10:09.595: %DTP-5-TRUNKPORTON: Port Fa1/4 has become dot1q trunk  
  9. R2(config-if)#ex  
  10. R1(config)#track 1 int f1/3 line-protocol   
  11. R1(config-track)#track 2 int f1/4 line-protocol  
  12. R2(config)#vlan 10  
  13. R2(config-vlan)#vlan 20  

(1)配置vlan 10

  1. R2(config-vlan)#int vlan 10  
  2. *Mar  1 00:10:20.911: %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to up  
  3. R2(config-if)#ip add 192.168.10.20 255.255.255.0  
  4. R2(config-if)#no sh  
  5. R2(config-if)#vrrp 1 ip 192.168.10.1       
  6. *Mar  1 00:12:54.007: %VRRP-6-STATECHANGE: Vl10 Grp 1 state Init -> Backup  
  7. R2(config-if)#vrrp 1 preempt   
  8. *Mar  1 00:12:57.619: %VRRP-6-STATECHANGE: Vl10 Grp 1 state Backup -> Master      
  9. R2(config-if)#vrrp 1 priority 95  
  10. R2(config-if)#ex  
  11. R2(config)#  

(2)配置vlan 20

  1. R2(config)#int vlan 20  
  2. *Mar  1 00:13:14.543: %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to up  
  3. R2(config-if)#ip add 192.168.20.20 255.255.255.0  
  4. R2(config-if)#no sh  
  5. R2(config-if)#vrrp 2 ip 192.168.20.1           
  6. *Mar  1 00:13:42.375: %VRRP-6-STATECHANGE: Vl20 Grp 2 state Init -> Backup  
  7. R2(config-if)#vrrp 2 preempt   
  8. *Mar  1 00:13:45.983: %VRRP-6-STATECHANGE: Vl20 Grp 2 state Backup -> Master      
  9. R2(config-if)#vrrp 2 priority 100  
  10. R2(config-if)#vrrp 2 track 1  
  11. R2(config-if)#vrrp 2 track 2  
  12. R2(config-if)#ex  

4.分别在R1,R2上检查一下vrrp的配置是否正确

  1. R1#show vrrp b  
  2. Interface          Grp Pri Time  Own Pre State   Master addr     Group addr  
  3. Vl10               1   100 3609       Y  Master  192.168.10.10   192.168.10.1     
  4. Vl20               2   95  3628       Y  Backup  192.168.20.20   192.168.20.1  
  5.   
  6. R2#show vrrp b  
  7. Interface          Grp Pri Time  Own Pre State   Master addr     Group addr  
  8. Vl10               1   95  3628       Y  Backup  192.168.10.10   192.168.10.1     
  9. Vl20               2   100 3609       Y  Master  192.168.20.20   192.168.20.1  

无误,分别配置上行口IP

  1. R1(config)#int f1/3  
  2. R1(config-if)#no switchport     将二层口变为三层口  
  3. R1(config-if)#ip add 13.0.0.1 255.255.255.0  
  4. R1(config-if)#no sh  
  5. R1(config-if)#  
  6. *Mar  1 00:14:36.199: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/3, changed state to up  
  7. R1(config-if)#ex  
  8.   
  9. R2(config)#int f1/3  
  10. R2(config-if)#no switchport    
  11. *Mar  1 00:14:50.827: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/3, changed state to up  
  12. R2(config-if)#ip add 23.0.0.2 255.255.255.0  
  13. R2(config-if)#no sh  
  14. R2(config-if)#ex  

配置外网路由器R3

  1. R3#conf t http://www.xiaoxiongboke.com/  
  2. Enter configuration commands, one per line.  End with CNTL/Z.  
  3. R3(config)#int f0/0  
  4. R3(config-if)#ip add 13.0.0.3 255.255.255.0  
  5. R3(config-if)#no sh  
  6. R3(config-if)#int f0/1                       
  7. *Mar  1 00:15:18.651: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up  
  8. *Mar  1 00:15:19.651: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up  
  9. R3(config-if)#ip add 23.0.0.3 255.255.255.0  
  10. R3(config-if)#no sh  
  11. *Mar  1 00:15:32.571: %LINK-3-UPDOWN: Interface FastEthernet0/1, changed state to up  
  12. *Mar  1 00:15:33.571: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up   
  13. R3(config)#int l0                           //建立虚拟接口  
  14. *Mar  1 00:15:36.259: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback0, changed state to up.  
  15. R3(config-if)#ip add 3.3.3.3 255.255.255.0  
  16. R3(config-if)#no sh  
  17. R3(config-if)#ex  

5.使用动态协议RIP互相告知网段

  1. R3(config)#router rip                          //启动RIP协议  
  2. R3(config-router)#network 3.3.3.0              //告知与自己直连网段,以便相邻路由器学习  
  3. R3(config-router)#network 13.0.0.0  
  4. R3(config-router)#network 23.0.0.0  
  5.   
  6. R1(config)#router rip   
  7. R1(config-router)#network 13.0.0.0  
  8. R1(config-router)#network 192.168.10.0  
  9. R1(config-router)#network 192.168.20.0  
  10.   
  11. R2(config)#router rip  
  12. R2(config-router)#network 23.0.0.0  
  13. R2(config-router)#network 192.168.10.0  
  14. R2(config-router)#network 192.168.20.0  

6.可以连通测试了

可以发现,C1走的路线是R1,C2走的路线是R2。这是刚才配置的vrrp优先级决定的。

将R1的上行口f1/3 和 R3的f0/0口 shutdown,观察tracert的变化。

此时R1已经的不同,电脑C1的路线已经由R1切换到了R2。

再将R1的f1/3口和R3的f0/0口 no shutdown,观察变化。

可以发现R1又将C1的路线抢占过来了。这样,热备路由的目的已经实现。

C2同理。

标签:

给我留言