配置OSPF负载分担
组网需求
如下图所示。
路由器RouterA、RouterB、RouterC和RouterD之间通过OSPF协议达到IP网络互连的目的。
路由器RouterA、RouterB、RouterC和RouterD同属于区域0。
要求配置负载分担,使得路由器RouterA的流量,可以分别通过路由器RouterB和RouterC发送到路由器RouterD。
配置OSPF负载分担组网图
| router | interface | ip address | router | interface | ip address |
| RouterA | GE3/0/0 | 172.16.1.1./24 | RouterD | POS1/0/0 | 192.168.0.2/24 |
| POS2/0/0 | 10.1.2.1/24 | GE3/0/0 | 172.17.1.1/24 | ||
| POS1/0/0 | 10.1.1.1/24 | POS2/0/0 | 192.168.1.2/24 | ||
| RouterC | POS2/0/0 | 192.168.0.1/24 | RouterB | POS2/0/0 | 192.168.1.1/24 |
| POS1/0/0 | 10.1.2.2/24 | POS1/0/0 | 10.1.1.2/24 |
配置思路
采用如下的思路配置OSPF的负载分担:
在各路由器上使能OSPF基本功能,实现互连。
取消负载分担,查看路由表信息。
在RouterA上配置负载分担方式。
在RouterA上配置等价路由优先级(可选配置)。
数据准备
为完成此配置例,需准备如下的数据:
四台路由器
RouterA的router id 1.1.1.1,运行的OSPF进程号1,区域0的网段10.1.0.0
RouterB的router id 2.2.2.2,运行的OSPF进程号1,区域0的网段10.1.0.0和192.168.0.0
RouterC的router id 3.3.3.3,运行的OSPF进程号1,区域0的网段10.1.0.0和192.168.1.0
RouterD的router id 4.4.4.4,运行的OSPF进程号1,区域0的网段192.168.0.0和192.168.1.0
RouterA上负载分担数目为1。
RouterA的路由负载分担方式。
RouterC的等价路由优先级权值为1。
配置步骤
步骤 1 配置各接口的IP地址(略)
步骤 2 配置OSPF的基本功能
步骤 3 在RouterA上取消负载分担配置
[RouterA] ospf [RouterA-ospf-1] maximum load-balancing 1
# 查看RouterA的路由表。
[RouterA] display ip routing-table
Routing Tables: Public
Destinations : 7 Routes : 7
Destination/Mask Proto Pre Cost NextHop Interface
10.1.1.0/24 Direct 0 0 10.1.1.1 Pos1/0/0
10.1.1.2/32 Direct 0 0 10.1.1.2 Pos1/0/0
10.1.2.0/24 Direct 0 0 10.1.2.1 Pos2/0/0
10.1.2.2/32 Direct 0 0 10.1.2.2 Pos2/0/0
172.17.1.0/24 OSPF 10 3125 10.1.1.2 Pos1/0/0
192.168.0.0/24 OSPF 10 3124 10.1.1.2 Pos1/0/0
192.168.1.0/24 OSPF 10 3124 10.1.2.2 Pos2/0/0
从路由表中可以看出,当配置负载分担最大等价路由条数为1后,到达目标网段172.17.1.0的下一跳为10.1.1.2。
说明
由于OSPF对等价路由下一跳的选择是随机的,所以上面例子中10.1.1.2被选为最优下一跳。
步骤 4 在RouterA上恢复负载分担路由的缺省数量
[RouterA] ospf [RouterA-ospf-1] undo maximum load-balancing
# 查看RouterA的路由表。
[RouterA] display ip routing-table
Routing Tables: Public
Destinations : 7 Routes : 8
Destination/Mask Proto Pre Cost NextHop Interface
10.1.1.0/24 Direct 0 0 10.1.1.1 Pos1/0/0
10.1.1.2/32 Direct 0 0 10.1.1.2 Pos1/0/0
10.1.2.0/24 Direct 0 0 10.1.2.1 Pos2/0/0
10.1.2.2/32 Direct 0 0 10.1.2.2 Pos2/0/0
172.17.1.0/24 OSPF 10 3125 10.1.1.2 Pos1/0/0
OSPF 10 3125 10.1.2.2 Pos2/0/0
192.168.0.0/24 OSPF 10 3124 10.1.1.2 Pos1/0/0
192.168.1.0/24 OSPF 10 3124 10.1.2.2 Pos2/0/0
从路由表可以看出,当取消负载分担条数设置即恢复缺省配置后,由于最大等价路由条数的缺省值为6,因此路由器RouterA的两个下一跳10.1.1.2(RouterB)和10.1.2.2(RouterC)均成为有效路由。
说明
不同的产品,不同协议,最大等价路由条数可能会不同,这个最大值可以通过购买许可证文件来调整。
步骤 5 配置RouterA的负载分担方式
负载分担支持两种方式,逐包负载分担和逐流负载分担。
# 逐包负载分担 [RouterA] load-balance packet
检查配置结果
[RouterA] acl 3000
[RouterA -acl-adv-3000] rule permit icmp destination 172.17.1.1 0
[RouterA -acl-adv-3000] quit
[RouterA] quit
<RouterA> debugging ip packet acl 3000
<RouterA> terminal debugging
<RouterA> terminal monitor
<RouterA> ping 172.17.1.1
PING 172.17.1.1: 56 data bytes, press CTRL_C to break
*0.10792570 RouterA IP/8/debug_case:
Sending, interface = pos1/0/0, version = 4, headlen = 20, tos = 0,
pktlen = 84, pktid = 1194, offset = 0, ttl = 255, protocol = 1,
checksum = 65258, s = 10.1.1.1, d = 172.17.1.1
prompt: Sending the packet from local at pos1/0/0
Reply from 172.17.1.1: bytes=56 Sequence=1 ttl=254 time=30 ms
*0.10793100 RouterA IP/8/debug_case:
Sending, interface = pos2/0/0, version = 4, headlen = 20, tos = 0,
pktlen = 84, pktid = 1195, offset = 0, ttl = 255, protocol = 1,
checksum = 65001, s = 10.1.2.1, d = 172.17.1.1
prompt: Sending the packet from local at pos2/0/0
Reply from 172.17.1.1: bytes=56 Sequence=2 ttl=254 time=50 ms
*0.10793600 RouterA IP/8/debug_case:
Sending, interface = pos1/0/0, version = 4, headlen = 20, tos = 0,
pktlen = 84, pktid = 1196, offset = 0, ttl = 255, protocol = 1,
checksum = 65256, s = 10.1.1.1, d = 172.17.1.1
prompt: Sending the packet from local at pos1/0/0
Reply from 172.17.1.1: bytes=56 Sequence=3 ttl=254 time=40 ms
*0.10794140 RouterA IP/8/debug_case:
Sending, interface = pos2/0/0, version = 4, headlen = 20, tos = 0,
pktlen = 84, pktid = 1197, offset = 0, ttl = 255, protocol = 1,
checksum = 64999, s = 10.1.2.1, d = 172.17.1.1
prompt: Sending the packet from local at pos2/0/0
Reply from 172.17.1.1: bytes=56 Sequence=4 ttl=254 time=30 ms
*0.10794670 RouterA IP/8/debug_case:
Sending, interface = pos1/0/0, version = 4, headlen = 20, tos = 0,
pktlen = 84, pktid = 1198, offset = 0, ttl = 255, protocol = 1,
checksum = 65254, s = 10.1.1.1, d = 172.17.1.1
prompt: Sending the packet from local at pos1/0/0
Reply from 172.17.1.1: bytes=56 Sequence=5 ttl=254 time=40 ms
--- 172.17.1.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 30/38/50 ms
从上面的debugging信息中,我们可以看出,到达目标地址172.17.1.1的报文分别从RouterA的POS 1/0/0接口和POS 2/0/0接口轮流发送出去,即基于报文的负载分担。
# 逐流负载分担 [RouterA] load-balance flow
检查配置结果
[RouterA] acl 3000 [RouterA -acl-adv-3000] rule permit icmp destination 172.17.1.1 0 [RouterA -acl-adv-3000] quit [RouterA] quit <RouterA> debugging ip packet acl 3000 <RouterA> terminal debugging <RouterA> terminal monitor
<RouterA> ping 172.17.1.1
PING 172.17.1.1: 56 data bytes, press CTRL_C to break
*0.11319030 RouterA IP/8/debug_case:
Sending, interface = pos1/0/0, version = 4, headlen = 20, tos = 0,
pktlen = 84, pktid = 1320, offset = 0, ttl = 255, protocol = 1,
checksum = 65132, s = 10.1.1.1, d = 172.17.1.1
prompt: Sending the packet from local at pos1/0/0
Reply from 172.17.1.1: bytes=56 Sequence=1 ttl=254 time=90 ms
*0.11319500 RouterA IP/8/debug_case:
Sending, interface = pos1/0/0, version = 4, headlen = 20, tos = 0,
pktlen = 84, pktid = 1321, offset = 0, ttl = 255, protocol = 1,
checksum = 65131, s = 10.1.1.1, d = 172.17.1.1
prompt: Sending the packet from local at pos1/0/0
Reply from 172.17.1.1: bytes=56 Sequence=2 ttl=254 time=30 ms
*0.11320000 RouterA IP/8/debug_case:
Sending, interface = pos1/0/0, version = 4, headlen = 20, tos = 0,
pktlen = 84, pktid = 1322, offset = 0, ttl = 255, protocol = 1,
checksum = 65130, s = 10.1.1.1, d = 172.17.1.1
prompt: Sending the packet from local at pos1/0/0
Reply from 172.17.1.1: bytes=56 Sequence=3 ttl=254 time=40 ms
*0.11320530 RouterA IP/8/debug_case:
Sending, interface = pos1/0/0, version = 4, headlen = 20, tos = 0,
pktlen = 84, pktid = 1324, offset = 0, ttl = 255, protocol = 1,
checksum = 65128, s = 10.1.1.1, d = 172.17.1.1
prompt: Sending the packet from local at pos1/0/0
Reply from 172.17.1.1: bytes=56 Sequence=4 ttl=254 time=40 ms
*0.11321070 RouterA IP/8/debug_case:
Sending, interface = pos1/0/0, version = 4, headlen = 20, tos = 0,
pktlen = 84, pktid = 1325, offset = 0, ttl = 255, protocol = 1,
checksum = 65127, s = 10.1.1.1, d = 172.17.1.1
prompt: Sending the packet from local at pos1/0/0
Reply from 172.17.1.1: bytes=56 Sequence=5 ttl=254 time=80 ms
--- 172.17.1.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 30/56/90 ms
从上面的debugging信息中,我们可以看出,到达目标地址172.17.1.1的报文全部从RouterA的POS 1/0/0接口发送出去,即基于流的负载分担。
说明
因为基于流的负载分担的选路原则为:到达同一个目的地址,它总是选择以前走过的路径。由于上一次到达目的地址是从POS 1/0/0接口发出,所以基于流的负载分担时也选择从POS 1/0/0发送报文。
步骤 6 在RouterA上配置等价路由优先级(可选配置)
如果我们不希望RoterB和RouterC形成负载分担,可以配置等价路由优先级,指定下一跳。
[RouterA] ospf [RouterA-ospf-1] nexthop 10.1.2.2 weight 1
# 查看RouterA的路由表
[RouterA] display ip routing-table
Routing Tables: Public
Destinations : 7 Routes : 7
Destination/Mask Proto Pre Cost NextHop Interface
10.1.1.0/24 Direct 0 0 10.1.1.1 Pos1/0/0
10.1.1.2/32 Direct 0 0 10.1.1.2 Pos1/0/0
10.1.2.0/24 Direct 0 0 10.1.2.1 Pos2/0/0
10.1.2.2/32 Direct 0 0 10.1.2.2 Pos2/0/0
172.17.1.0/24 OSPF 10 3125 10.1.2.2 Pos2/0/0
192.168.0.0/24 OSPF 10 3124 10.1.1.2 Pos1/0/0
192.168.1.0/24 OSPF 10 3124 10.1.2.2 Pos2/0/0
从路由表中可以看出,当配置等价路由的优先级后,由于下一跳为10.1.2.2(RouterC)的优先级(权值为1)高于下一跳为10.1.1.2(RouterB)的优先级,所以OSPF优先选择下一跳为10.1.2.2为唯一最优路由。





