7.2 浮动静态路由及负载均衡
7.2.1 原理概述
浮动静态路由(Floating Static Route)是一种特殊的静态路由,通过配置去往相同的目的网段,但优先级不同的静态路由,以保证在网络中优先级较高的路由,即主路由失效的情况下,提供备份路由。正常情况下,备份路由不会出现在路由表中。
负载均衡(Load sharing),当数据有多条可选路径前往同一目的网络,可以通过配置相同优先级和开销的静态路由实现负载均衡,使得数据的传输均衡地分配到多条路径上,从而实现数据分流、减轻单条路径负载过重的效果。而当其中某一条路径失效时,其他路径仍然能够正常传输数据,也起到了冗余作用。
7.2.2 实验内容
R2为公司总部,R1与R3是两个分部,pc模拟各个部门办公电脑,现在需要总部与各个分部,分部与分部之间都能通信,且分部之间在通讯时候,之间的直连链路为主用链路,通过总部的链路为备份链路,本实验使用浮动静态路由实现,在根据实验需求实现负载均衡来优化网络。
7.2.3 实验拓扑
7.2.4 实验编址
设备 | 接口 | IP地址 | 子网掩码 | 默认网关 |
---|---|---|---|---|
R1(AR2220) | GE 0/0/0 | 192.168.10.254 | 255.255.255.0 | N/A |
R1(AR2220) | Serial 1/0/0 | 172.16.1.1 | 255.255.255.0 | N/A |
R1(AR2220) | Serial 1/0/1 | 172.16.2.6 | 255.255.255.0 | N/A |
R2(AR2220) | GE 0/0/0 | 192.168.30.254 | 255.255.255.0 | N/A |
R2(AR2220) | Serial 1/0/0 | 172.16.1.2 | 255.255.255.0 | N/A |
R2(AR2220) | Serial 1/0/1 | 172.16.3.3 | 255.255.255.0 | N/A |
R3(AR2220) | GE 0/0/0 | 192.168.20.254 | 255.255.255.0 | N/A |
R3(AR2220) | Serial 1/0/0 | 172.16.3.4 | 255.255.255.0 | N/A |
R3(AR2220) | Serial 1/0/1 | 172.16.2.5 | 255.255.255.0 | N/A |
PC1 | Ethernet 0/0/1 | 192.168.10.1 | 255.255.255.0 | 192.168.10.254 |
PC2 | Ethernet 0/0/1 | 192.168.20.1 | 255.255.255.0 | 192.168.20.254 |
PC3 | Ethernet 0/0/1 | 192.168.30.1 | 255.255.255.0 | 192.168.30.254 |
7.2.5 实验步骤
1、基本配置
根据实验编址表进行pc等的基本配置。电脑IP我就不在这里配置了。
[R1]interface GigabitEthernet 0/0/0
[R1-GigabitEthernet0/0/0]ip address 192.168.10.254 24
[R1-GigabitEthernet0/0/0]interface serial 1/0/0
[R1-Serial1/0/0]ip address 172.16.1.1 24
[R1-Serial1/0/1]interface serial 1/0/1
[R1-Serial1/0/1]ip address 172.16.2.6 24[R2]interface GigabitEthernet 0/0/0
[R2-GigabitEthernet0/0/0]ip address 192.168.30.254 24
[R2-GigabitEthernet0/0/0]interface serial 1/0/0
[R2-Serial1/0/0]ip address 172.16.1.2 24
[R2-Serial1/0/0]interface serial 1/0/1
[R2-Serial1/0/1]ip address 172.16.3.3 24[R3]interface GigabitEthernet 0/0/0
[R3-GigabitEthernet0/0/0]ip address 192.168.20.254 24
[R3-GigabitEthernet0/0/0]interface serial 1/0/0
[R3-Serial1/0/0]ip address 172.16.3.4 24
[R3-Serial1/0/0]interface serial 1/0/1
[R3-Serial1/0/1]ip address 172.16.2.5 24
2、实现两分部间,总部与两分部间的通信
在R1上配置目的网段为主机PC2所在网段的静态路由,在R3上配置目的网段为PC1所在网段的静态路由,在R2上配置目的网段分别为主机PC1和PC2所在网段的路由。
[R1]ip route-static 192.168.20.0 24 serial 1/0/1
[R1]ip route-static 192.168.30.0 24 serial 1/0/0[R2]ip route-static 192.168.10.0 24 serial 1/0/0
[R2]ip route-static 192.168.20.0 24 serial 1/0/1[R3]ip route-static 192.168.10.0 24 serial 1/0/1
[R3]ip route-static 192.168.30.0 24 serial 1/0/0
测试pc1和pc2的连通性。
PC1>ping 192.168.20.1
Ping 192.168.20.1: 32 data bytes, Press Ctrl_C to break
From 192.168.20.1: bytes=32 seq=1 ttl=254 time=47 ms
From 192.168.20.1: bytes=32 seq=2 ttl=254 time=16 ms
From 192.168.20.1: bytes=32 seq=3 ttl=254 time=31 ms
From 192.168.20.1: bytes=32 seq=4 ttl=254 time=16 ms
From 192.168.20.1: bytes=32 seq=5 ttl=254 time=15 ms
--- 192.168.20.1 ping statistics ---5 packet(s) transmitted5 packet(s) received0.00% packet lossround-trip min/avg/max = 15/25/47 ms
使用命令tracert命令测试所经过的网关。通过观察发现数据包是经过R1和R3到达主机pc2的。
PC>tracert 192.168.20.1
traceroute to 192.168.20.1, 8 hops max
(ICMP), press Ctrl+C to stop1 192.168.10.254 16 ms 16 ms <1 ms2 172.16.2.5 31 ms 15 ms 32 ms3 192.168.20.1 15 ms 32 ms 15 ms
通过总公司测试分公司也是都可以互相通信。
PC>ping 192.168.10.1
Ping 192.168.10.1: 32 data bytes, Press Ctrl_C to break
From 192.168.10.1: bytes=32 seq=1 ttl=126 time=16 ms
From 192.168.10.1: bytes=32 seq=2 ttl=126 time=31 msPC>ping 192.168.20.1
Ping 192.168.20.1: 32 data bytes, Press Ctrl_C to break
From 192.168.20.1: bytes=32 seq=1 ttl=126 time=15 ms
From 192.168.20.1: bytes=32 seq=2 ttl=126 time=31 ms
3、通过浮动静态路由实现路由备份
通过上面的配置,现在的网络搭建已经初步完成,现需要实现当两分部间通信时,直连链路为主要链路,通过总部的链路为备份链路,即当主要链路发生故障时,可以使用备用链路来保证通信正常。现在模拟链路故障pc1是不能ping通pc2的。
PC>ping 192.168.20.1
Ping 192.168.20.1: 32 data bytes, Press Ctrl_C to break
Request timeout!
Request timeout!
Request timeout!
Request timeout!
Request timeout!
--- 192.168.20.1 ping statistics ---5 packet(s) transmitted0 packet(s) received100.00% packet loss
在R1上配置静态路由,目的网段为主机pc2所在网段,掩码为24位,下一跳为R2,将路由优先级设置为100,默认60.在R3上做相同的配置。使用display ip routing-table protocol static
命令查看静态路由信息,可以观察到目的地址为pc2所在网段的两条优先级为100和60的静态路由都已经存在。
[R1]ip route-static 192.168.20.0 24 serial 1/0/0 preference 100
[R3]ip route-static 192.168.10.0 24 serial 1/0/0 preference 100[R1]display ip routing-table protocol static
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : StaticDestinations : 2 Routes : 3 Configured Routes : 3
Static routing table status : <Active>Destinations : 2 Routes : 2
Destination/Mask Proto Pre Cost Flags NextHop Interface192.168.20.0/24 Static 60 0 D 172.16.2.6 Serial1/0/1192.168.30.0/24 Static 60 0 D 172.16.1.1 Serial1/0/0
Static routing table status : <Inactive>Destinations : 1 Routes : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface192.168.20.0/24 Static 100 0 172.16.1.1 Serial1/0/0
现在模拟链路故障测试pc1和pc2的连通性,发现可以正常通信,在使用tracert命令查看此时pc1与pc2通信时所经过的网关。
PC>ping 192.168.20.1
Ping 192.168.20.1: 32 data bytes, Press Ctrl_C to break
From 192.168.20.1: bytes=32 seq=1 ttl=125 time=32 ms
From 192.168.20.1: bytes=32 seq=2 ttl=125 time=15 ms
From 192.168.20.1: bytes=32 seq=3 ttl=125 time=32 ms
From 192.168.20.1: bytes=32 seq=4 ttl=125 time=31 ms
From 192.168.20.1: bytes=32 seq=5 ttl=125 time=15 msPC>tracert 192.168.20.1
traceroute to 192.168.20.1, 8 hops max
(ICMP), press Ctrl+C to stop1 192.168.10.254 <1 ms 16 ms 16 ms2 172.16.1.2 15 ms 32 ms 15 ms3 172.16.3.4 16 ms 31 ms 16 ms4 192.168.20.1 31 ms 31 ms 16 ms
可以观察到经过R2到R3,再次验证了此时两部门通信已经使用了备份链路。
4、通过负载均衡实现网络优化
公司网络管理员发现分部之间业务往来越来越多,网络流量剧增,主用链路压力非常大,而总部与两分部间的网络流量相对较少,即备用链路上的带宽多处在闲置状态。此时可以通过配置实现负载均衡,即同时利用主备两条链路来支撑两分部间的通信。
恢复R1的1/0/1接口,并配置目的网段为主机pc2所在网段,掩码24位,下一跳为R2,优先级不变。在R3上做同样的配置。用display ip routing-table
命令查看R1上面的路由表。
[R1]interface Serial 1/0/1
[R1-Serial1/0/1]undo shutdown
[R1]ip route-static 192.168.20.0 24 serial 1/0/0
[R3]ip route-static 192.168.10.0 24 serial 1/0/0[R1]display ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: PublicDestinations : 17 Routes : 18
Destination/Mask Proto Pre Cost Flags NextHop Interface127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0172.16.1.0/24 Direct 0 0 D 172.16.1.1 Serial1/0/0172.16.1.1/32 Direct 0 0 D 127.0.0.1 Serial1/0/0172.16.1.2/32 Direct 0 0 D 172.16.1.2 Serial1/0/0172.16.1.255/32 Direct 0 0 D 127.0.0.1 Serial1/0/0172.16.2.0/24 Direct 0 0 D 172.16.2.6 Serial1/0/1172.16.2.5/32 Direct 0 0 D 172.16.2.5 Serial1/0/1172.16.2.6/32 Direct 0 0 D 127.0.0.1 Serial1/0/1172.16.2.255/32 Direct 0 0 D 127.0.0.1 Serial1/0/1192.168.10.0/24 Direct 0 0 D 192.168.10.254 GigabitEthernet0/0/0192.168.10.254/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0192.168.10.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0192.168.20.0/24 Static 60 0 D 172.16.2.6 Serial1/0/1Static 60 0 D 172.16.1.1 Serial1/0/0192.168.30.0/24 Static 60 0 D 172.16.1.1 Serial1/0/0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
可以看到去到192.168.20.0网段有两条下一跳不同的路由条目,即实现了负载均衡。