【理论准备】

 
balance number
 
 
number:进行负载分担的BGP路由条数,当number取值为1时,相当于不进行负载分担。不同型号的设备支持的取值范围不同,请以设备的实际情况为准。
 
 
balance命令用来配置BGP负载分担的路由条数。undo balance命令用来取消BGP路由负载分担功能。
 
缺省情况下,没有进行路由负载分担。
 
与IGP路由的负载分担不同,BGP没有明确的度量值决定是否对路由进行负载分担。BGP的负载分担是通过改变BGP选路规则来实现的。
【实验拓扑】
 
 

 
本文实验采用的交换机是H3C模拟器,下载地址如下:http://forum.h3c.com/forum.php?mod=viewthread&tid=109740&highlight=H3C%E6%A8%A1%E6%8B%9F%E5%99%A8 有兴趣的朋友可以在论坛上去下载。
【实验过程】
按如上拓扑配置接口IP和BGP AS
 
R4和R5建立OSPF邻居
R4配置:
#
 area 0.0.0.0 
  network 1.1.1.2 0.0.0.0 
  network 10.1.3.0 0.0.0.255 
#
 
 
R5配置:
#
ospf 1
 area 0.0.0.0   
  network 1.1.1.3 0.0.0.0
  network 10.1.3.0 0.0.0.255
 
[R5] dis ospf peer
 
                  OSPF Process 1 with Router ID 1.1.1.3
                        Neighbor Brief Information
 
 Area: 0.0.0.0        
 Router ID       Address         Pri Dead-Time Interface       State
 1.1.1.2         10.1.3.1        1   32        S0/6/2          Full/ -
 
 
[R5]dis ip ro
Routing Tables: Public
        Destinations : 10       Routes : 10
 
Destination/Mask    Proto  Pre  Cost         NextHop         Interface
 
1.1.1.2/32          OSPF   10   1562         10.1.3.1        S0/6/2
 
 
 
[R4]dis ip ro
Routing Tables: Public
        Destinations : 10       Routes : 10
 
Destination/Mask    Proto  Pre  Cost         NextHop         Interface
 
1.1.1.3/32          OSPF   10   1562         10.1.3.2        S0/6/2
 
【BGP配置】
R3:
bgp 100 
 network 10.0.0.1 255.255.255.255 
 undo synchronization
 peer 10.1.1.2 as-number 200 
 peer 10.1.2.2 as-number 200 
 group ex external
 peer 10.1.1.2 group ex 
 peer 10.1.2.2 group ex 
 
R4:
bgp 200 
 network 10.1.1.0 255.255.255.0 
 network 10.1.3.0 255.255.255.0
 undo synchronization
 peer 10.1.1.1 as-number 100 
 group ex external
 peer 10.1.1.1 group ex 
 group in internal
 peer 1.1.1.3 group in 
 peer 1.1.1.3 connect-interface LoopBack0
 
R5:
 
bgp 200 
network 10.1.2.0 255.255.255.0 
 network 10.1.3.0 255.255.255.0 
 undo synchronization
 peer 10.1.2.1 as-number 100 
 group in internal
 peer 1.1.1.2 group in 
 peer 1.1.1.2 connect-interface LoopBack0
 group ex external
 peer 10.1.2.1 group ex 
#
 
[R3]dis bgp peer  
 
 BGP local router ID : 10.0.0.1
 Local AS number : 100
 Total number of peers : 2                Peers in established state : 2
 
  Peer            V    AS  MsgRcvd  MsgSent  OutQ PrefRcv Up/Down  State
 
  10.1.1.2        4   200        5        7     0       0 00:03:36 Established
  10.1.2.2        4   200        2        5     0       0 00:00:17 Established
[R3]
 
[R4]dis bgp peer
 
 BGP local router ID : 1.1.1.2
 Local AS number : 200
 Total number of peers : 2                Peers in established state : 2
 
  Peer            V    AS  MsgRcvd  MsgSent  OutQ PrefRcv Up/Down  State
 
  10.1.1.1        4   100        7        6     0       1 00:03:58 Established
  1.1.1.3         4   200        3        3     0       1 00:00:20 Established
 
BGP配置完成,我们来看R3上的路由表:
 
R3]dis bgp ro
 
 Total Number of Routes: 7
 
 BGP Local router ID is 10.0.0.1 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete
     Network            NextHop         MED        LocPrf     PrefVal Path/Ogn
 
 *>  10.0.0.1/32        0.0.0.0         0                     0       i
 *   10.1.1.0/24        10.1.1.2        0                     0       200i
 *                      10.1.2.2                              0       200i
 *   10.1.2.0/24        10.1.2.2        0                     0       200i
 *                      10.1.1.2                              0       200i
 *>  10.1.3.0/24        10.1.1.2        0                     0       200i
 *                      10.1.2.2        0                     0       200i
 
[R3]
[R3]
[R3]dis ip ro
Routing Tables: Public
        Destinations : 11       Routes : 11
 
Destination/Mask    Proto  Pre  Cost         NextHop         Interface
 
1.1.1.1/32          Direct 0    0            127.0.0.1       InLoop0
10.0.0.1/32         Direct 0    0            127.0.0.1       InLoop0
10.1.1.0/24         Direct 0    0            10.1.1.1        S0/6/0
10.1.1.1/32         Direct 0    0            127.0.0.1       InLoop0
10.1.1.2/32         Direct 0    0            10.1.1.2        S0/6/0
10.1.2.0/24         Direct 0    0            10.1.2.1        S0/6/2
10.1.2.1/32         Direct 0    0            127.0.0.1       InLoop0
10.1.2.2/32         Direct 0    0            10.1.2.2        S0/6/2
10.1.3.0/24         BGP    255  0            10.1.1.2        S0/6/0
127.0.0.0/8         Direct 0    0            127.0.0.1       InLoop0
127.0.0.1/32        Direct 0    0            127.0.0.1       InLoop0
由上可见路由表中到10.1.3.0/24的下一跳是10.1.1.2,10.1.2.2存在于BGP路由表中,但是并没有存在于路由表中,是合法的,但不是最佳的。
 
加入如下命令后我们再来观察:
[R3-bgp]balance 2
[R3-bgp]dis ip ro
Routing Tables: Public
        Destinations : 11       Routes : 12
 
Destination/Mask    Proto  Pre  Cost         NextHop         Interface
 
1.1.1.1/32          Direct 0    0            127.0.0.1       InLoop0
10.0.0.1/32         Direct 0    0            127.0.0.1       InLoop0
10.1.1.0/24         Direct 0    0            10.1.1.1        S0/6/0
10.1.1.1/32         Direct 0    0            127.0.0.1       InLoop0
10.1.1.2/32         Direct 0    0            10.1.1.2        S0/6/0
10.1.2.0/24         Direct 0    0            10.1.2.1        S0/6/2
10.1.2.1/32         Direct 0    0            127.0.0.1       InLoop0
10.1.2.2/32         Direct 0    0            10.1.2.2        S0/6/2
10.1.3.0/24         BGP    255  0            10.1.1.2        S0/6/0
                    BGP    255  0            10.1.2.2        S0/6/2
127.0.0.0/8         Direct 0    0            127.0.0.1       InLoop0
127.0.0.1/32        Direct 0    0            127.0.0.1       InLoop0
 
[R3-bgp]dis bgp ro
 
 Total Number of Routes: 7
 
 BGP Local router ID is 10.0.0.1 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete
     Network            NextHop         MED        LocPrf     PrefVal Path/Ogn
 
 *>  10.0.0.1/32        0.0.0.0         0                     0       i
 *   10.1.1.0/24        10.1.1.2        0                     0       200i
 *                      10.1.2.2                              0       200i
 *   10.1.2.0/24        10.1.2.2        0                     0       200i
 *                      10.1.1.2                              0       200i
 *>  10.1.3.0/24        10.1.1.2        0                     0       200i
 *>                     10.1.2.2        0                     0       200i
 
[R3-bgp]
 
加了命令后可见,在路由表中有两个下一跳,在BGP路由表中两个下一跳都是合法的和最佳的。