实验拓扑图:
一、前言
1.相关术语
2.工作机制
二、实验步骤
1.进行网段地划分和IP地址的规划
靠下一侧为.1,靠上一侧为.2
2.为PC机配置IP地址及网关
PC1>ip 1.1.1.2/24 1.1.1.1
PC2>ip 192.168.1.200/24 192.168.1.3
主机 | IP地址 | 子网掩码 | 网关 |
---|---|---|---|
PC1 | 1.1.1.2 | 255.255.255.0 | 1.1.1.1 |
PC2 | 192.168.1.200 | 255.255.255.0 | 192.168.1.3(虚拟网关) |
3.先为路由器做基本配置
1)为路由器接口配置IP地址,并打开接口(no shut)
以R1为例,R2、R3同理。
R1(config-if)#ip addr 1.1.1.1 255.255.255.0
R1(config-if)#no shut(打开接口)
R1(config-if)#exit
R1(config)#int f1/0(为接口f1/0配置IP地址)
R1(config-if)#ip addr 192.168.14.2 255.255.255.0
R1(config-if)#no shut(打开接口)
R1(config-if)#exit
R1(config)#int f1/1(为接口f1/1配置IP地址)
R1(config-if)#ip addr 192.168.24.2 255.255.255.0
R1(config-if)#no shut(打开接口)
R1(config-if)#exit
路由器接口状态展示:
路由器 | 接口 | IP地址 | 掩码 |
---|---|---|---|
R1 | f0/0 | 1.1.1.1 | 255.255.255.0 |
R1 | f1/0 | 192.168.14.2 | 255.255.255.0 |
R1 | f1/1 | 192.168.24.2 | 255.255.255.0 |
R2 | f0/0 | 192.168.1.1 | 255.255.255.0 |
R2 | f1/0 | 192.168.14.1 | 255.255.255.0 |
R3 | f0/0 | 192.168.1.2 | 255.255.255.0 |
R3 | f1/1 | 192.168.24.1 | 255.255.255.0 |
2)配置路由协议
可以是动态路由(配置所有直连网段),
也可以是静态路由(配置所有非直连网段)
下面为路由器配置动态路由,以R1为例,R2、R3同理。
R1#config t
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#router rip(开启RIP配置)
R1(config-router)#version 2(启用RIP版本2)
R1(config-router)#no auto-summary(禁用自动汇总)
R1(config-router)#network 1.1.1.0(配置RIP)
R1(config-router)#network 192.168.14.0
R1(config-router)#network 192.168.24.0
3)将switch与路由器相连的接口改为dot1q类型
4.下面配置两种情况
情况1:
R2为主用路由器,R3为备用路由器
==> vrrp 1 IP地址即为 R2 f0/0接口 IP地址;vrrp 2 IP地址即为 R3 f0/0接口 IP地址(可不配置)
情况2:
R2,R3数据共同传输,一方忙时通过另一方传输
==> vrrp 1 IP地址都为虚拟网关地址。
5.情况1:R1主用,R2备用
需将pc2的网关IP改为192.168.1.1
PC2> ip 192.168.1.200/24 192.168.1.1
Checking for duplicate address...
PC1 : 192.168.1.200 255.255.255.0 gateway 192.168.1.1
PC2> save
Saving startup configuration to startup.vpc
. done
R2#config t
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#int f0/0
R2(config-if)#vrrp 1 ip 192.168.1.1
R2(config-if)#vrrp 2 ip 192.168.1.2
R2#show vrrp
FastEthernet0/0 - Group 1
State is Master
Virtual IP address is 192.168.1.1
Virtual MAC address is 0000.5e00.0101
Advertisement interval is 1.000 sec
Preemption enabled
Priority is 255
Master Router is 192.168.1.1 (local), priority is 255
Master Advertisement interval is 1.000 sec
Master Down interval is 3.003 sec
FastEthernet0/0 - Group 2
State is Master
Virtual IP address is 192.168.1.2
Virtual MAC address is 0000.5e00.0102
Advertisement interval is 1.000 sec
Preemption enabled
Priority is 100
Master Router is 192.168.1.1 (local), priority is 100
Master Advertisement interval is 1.000 sec
Master Down interval is 3.609 sec
R3#config t
Enter configuration commands, one per line. End with CNTL/Z.
R3(config)#int f0/0
R3(config-if)#vrrp 1 ip 192.168.1.1
R3(config-if)#vrrp 2 ip 192.168.1.2
R3#show vrrp
FastEthernet0/0 - Group 1
State is Backup
Virtual IP address is 192.168.1.1
Virtual MAC address is 0000.5e00.0101
Advertisement interval is 1.000 sec
Preemption enabled
Priority is 100
Master Router is 192.168.1.1, priority is 255
Master Advertisement interval is 1.000 sec
Master Down interval is 3.609 sec (expires in 3.073 sec)
FastEthernet0/0 - Group 2
State is Master
Virtual IP address is 192.168.1.2
Virtual MAC address is 0000.5e00.0102
Advertisement interval is 1.000 sec
Preemption enabled
Priority is 255
Master Router is 192.168.1.2 (local), priority is 255
Master Advertisement interval is 1.000 sec
Master Down interval is 3.003 sec
保存配置,举例:
R2#write
Building configuration...
[OK]
PC2> save
Saving startup configuration to startup.vpc
. done
6.情况1:测试
PC2> ping 192.168.14.1
84 bytes from 192.168.14.1 icmp_seq=1 ttl=255 time=9.638 ms
84 bytes from 192.168.14.1 icmp_seq=2 ttl=255 time=11.289 ms
84 bytes from 192.168.14.1 icmp_seq=3 ttl=255 time=10.315 ms
84 bytes from 192.168.14.1 icmp_seq=4 ttl=255 time=6.850 ms
84 bytes from 192.168.14.1 icmp_seq=5 ttl=255 time=7.108 ms
PC2> ping 192.168.14.2
192.168.14.2 icmp_seq=1 timeout
84 bytes from 192.168.14.2 icmp_seq=2 ttl=254 time=37.356 ms
84 bytes from 192.168.14.2 icmp_seq=3 ttl=254 time=27.576 ms
84 bytes from 192.168.14.2 icmp_seq=4 ttl=254 time=34.110 ms
84 bytes from 192.168.14.2 icmp_seq=5 ttl=254 time=27.610 ms
PC2> ping 1.1.1.2
1.1.1.2 icmp_seq=1 timeout
84 bytes from 1.1.1.2 icmp_seq=2 ttl=62 time=54.204 ms
84 bytes from 1.1.1.2 icmp_seq=3 ttl=62 time=38.891 ms
84 bytes from 1.1.1.2 icmp_seq=4 ttl=62 time=39.075 ms
84 bytes from 1.1.1.2 icmp_seq=5 ttl=62 time=43.174 ms
7.情况2:虚拟网关192.168.1.3
R2#config t
R2(config)#int f0/0
R2(config-if)#vrrp 1 ip 192.168.1.3
R3#config t
R3(config)#int f0/0
R3(config-if)#vrrp 1 ip 192.168.1.3
R2#show vrrp
FastEthernet0/0 - Group 1
State is Backup
Virtual IP address is 192.168.1.3
Virtual MAC address is 0000.5e00.0101
Advertisement interval is 1.000 sec
Preemption enabled
Priority is 100
Master Router is 192.168.1.2, priority is 100
Master Advertisement interval is 1.000 sec
Master Down interval is 3.609 sec (expires in 2.641 sec)
R3#show vrrp
FastEthernet0/0 - Group 1
State is Master
Virtual IP address is 192.168.1.3
Virtual MAC address is 0000.5e00.0101
Advertisement interval is 1.000 sec
Preemption enabled
Priority is 100
Master Router is 192.168.1.2 (local), priority is 100
Master Advertisement interval is 1.000 sec
Master Down interval is 3.609 sec
8.情况2:测试
PC2> ping 192.168.24.1
84 bytes from 192.168.24.1 icmp_seq=1 ttl=255 time=7.179 ms
84 bytes from 192.168.24.1 icmp_seq=2 ttl=255 time=13.763 ms
84 bytes from 192.168.24.1 icmp_seq=3 ttl=255 time=4.590 ms
84 bytes from 192.168.24.1 icmp_seq=4 ttl=255 time=7.372 ms
84 bytes from 192.168.24.1 icmp_seq=5 ttl=255 time=4.653 ms
PC2> ping 192.168.24.2
84 bytes from 192.168.24.2 icmp_seq=1 ttl=254 time=28.679 ms
84 bytes from 192.168.24.2 icmp_seq=2 ttl=254 time=30.906 ms
84 bytes from 192.168.24.2 icmp_seq=3 ttl=254 time=26.973 ms
84 bytes from 192.168.24.2 icmp_seq=4 ttl=254 time=20.812 ms
84 bytes from 192.168.24.2 icmp_seq=5 ttl=254 time=25.170 ms
PC2> ping 1.1.1.2
1.1.1.2 icmp_seq=1 timeout
84 bytes from 1.1.1.2 icmp_seq=2 ttl=62 time=30.579 ms
84 bytes from 1.1.1.2 icmp_seq=3 ttl=62 time=47.245 ms
84 bytes from 1.1.1.2 icmp_seq=4 ttl=62 time=51.657 ms
84 bytes from 1.1.1.2 icmp_seq=5 ttl=62 time=46.760 ms
三、实验结果
两种情况下全网都可以通信(ping通)
情况2:将R2的f0/0接口down掉,使用Wireshark进行抓包(vrrp)并分析。
R2#config t
R2(config)#int f0/0
R2(config-if)#shutdown(关闭接口)
在Wireshark中进行抓包,启用vrrp显示过滤器
截取报文进行分析
可以看到IP地址为192.168.1.2(转换路径成功)
四、思考与总结
1.在一个VRRP组中,如何指定其中的一台设备为主用设备?假如故障的主用设备恢复,是否执行切换动作?
比较优先级的大小,优先级高者当选为Master设备。当两台设备优先级相同时,如果已经存在Master,则其保持Master身份,无需继续选举;如果不存在Master,则继续比较接口IP地址大小,接口IP地址较大的设备当选为Master设备。不执行切换动作。