您的位置:首页 > 其它

BGP的13条选路原则

2015-07-30 20:04 260 查看


一、Weight 权重

介绍:Cisco私有参数,范围0-65535,本地始发默认32768,其他默认0。

仅在本地有效,无法传递,且越大越优先。

 

例如:图1-1 在R1上宣告自己的回环口1.1.1.1/32,可以在R4上看到如下路由:

   Network          Next Hop            Metric LocPrf Weight Path 

* i1.1.1.1/32       34.34.34.3               0    100      0 65001 i 
*>i                     24.24.24.2               0    100      0
65001 i

遵循13条规则,选择24.24.24.2,我们更改其Weight,使34.34.34.4优先。

R4:

access-list 2 permit 1.1.1.1

route-map 2
permit 10 

match ip address 2 
set weight 2

route-map 2
permit 20

neighbor 34.34.34.3 route-map 2 in

 

验证:

R4:

*>i1.1.1.1/32       34.34.34.3               0    100      2
65001 i 
* i                       24.24.24.2               0    100      0
65001 i

 


二、Local Preference 本地优先级

介绍:越大越优先,默认值均为100,可以影响本AS内部路由,不能传递给EBGP邻居。

例如:在R1上宣告自己的回环口1.1.1.1/32,可以在R4上看到如下路由:

   Network          Next Hop            Metric LocPrf Weight Path 

* i1.1.1.1/32       34.34.34.3               0    100      0 65001 i 
*>i                     24.24.24.2               0    100      0
65001 i

我们更改R3上LP值,使其影
4000
响R4,使34.34.34.4优先。

R3:

access-list 3 permit 1.1.1.1 



route-map 3 permit 10 

match ip address 3 
set local-preference 101

route-map 3 permit 20

 

neighbor 13.13.13.1 route-map 3 in

验证:

R3:

   Network          Next Hop            Metric LocPrf Weight Path 
*> 1.1.1.1/32       13.13.13.1               0    101      0 65001 i

R4:

   Network          Next Hop            Metric LocPrf Weight Path 

*>i1.1.1.1/32       34.34.34.3               0    101      0 65001 i 
* i                       24.24.24.2               0    100      0
65001 i

 


三、本地始发路由方式

介绍:该比较原则主要是指本地在进入一条IGP路由进去BGP表时,使用不同的方式比如network或redistribute等。

那么这些方式之间是存在优先顺序的:network>redistribute>aggregate

这项不作为选路原则,在BGP表中看不到其他项。

例如:我们在R2上建立如下BGP条目:

R2:

network 2.2.2.2 mask 255.255.255.255 

aggregate-address 3.3.3.3 255.255.255.255 
redistribute connected

相当于建立了 一条宣告i 一条汇总i 一条重分发?

验证:

1.在三种都在的情况下,选network

*> 2.2.2.2/32       0.0.0.0                  0         32768
i

2.删除network,选redistribute

*> 2.2.2.2/32       0.0.0.0                  0         32768
?

3.删除redistribute,选aggregate

*> 1.1.1.1/32       12.12.12.1               0             1
65001 i

 


四、AS PATH最短

介绍:对于EBGP来说,越短的AS越优先

可以在BGP进程下使用bgp bestpath
as-path ignore命令来跳过AS-Path的长度比较

例如:如图1-1,在R4上配置一个回环口4.4.4.4/32,宣告并在R1上看到如下条目:

R1:

*  4.4.4.4/32       13.13.13.3                             0
65234 i 
*>                      12.12.12.2                             0
65234 i

我们在R2上将其AS PATH加长。

R2:

access-list 4 permit 4.4.4.4 
!

route-map 4 permit 10 

match ip address 4 

set as-path prepend 65535 


route-map 4 permit 20

neighbor 12.12.12.1 route-map 4 out

验证:

R1:

*> 4.4.4.4/32       13.13.13.3                             0
65234 i 
*                   12.12.12.2                             0
65234 65535 i

 


五、Origin 属性

介绍:三种不同的Origin属性的优先顺序:IGP>EGP>incomplete,这种属性将影响全局!注意使用

除了重分发进来的之外,一般都是i,e的已经不存在了。

例如:R4从R2、R3学到的1.1.1.1/32的路由条目

R4:

* i1.1.1.1/32       34.34.34.3               0    100      0
65001 i 
*>i                     24.24.24.2               0    100      0
65001 i

我们将24.24.24.2学来的路由改为incomplete,使1.1.1.1/32走R3

R2:

access-list 1 permit 1.1.1.1

route-map 1 permit 10 

match ip address 1 

set weight 1 
set origin incomplete

route-map 1 permit 20

neighbor 24.24.24.4 route-map 1 out

验证:

R4:

*>i1.1.1.1/32       34.34.34.3               0    100      0
65001 i 
* i                 24.24.24.2               0    100      0
65001 ?

 


六、MED值

介绍:也就是metric值,默认为0,同其他metric一样,越小越优先。

默认情况下,只比较来自同一邻居AS的BGP路由的MED值。

可以配置bgp always-compare-med命令,可以比较多个AS的med值。

本地在将一条BGP路由通告给EBGP Peer时,是否携带MED值,需要根据以下条件进行判断(不对EBGP Peer使用Route-map): 

如果该BGP路由是本地始发(network或redistribute)的,则携带MED值发送给EBGP Peer (如果MED为空,则设置为0) 

如果该BGP路由是从其他BGP Peer学习过来的,那么将该路由通告给EBGP Peer时不携带MED 

本地在将一条BGP路由通告给IBGP Peer时,一定会携带MED值 
如果接收或产生的路由的MED为空,那么在向IBGP Peer通告时,将MED设置为0

 

简而言之:IBGP间传递,自己产生的传给EBGP邻居,否则不携带。

 

下面我们一一验证。

例如:

1.在IBGP间传递MED值,R2把非0metric传递给R4,导致1.1.1.1/32从R3走。

R4:

   Network          Next Hop            Metric LocPrf Weight Path 

* i1.1.1.1/32       34.34.34.3               0    100      0 65001 i 
*>i                     24.24.24.2               0    100      0
65001 i

在R2上作策略:

access-list 2 permit 1.1.1.1

route-map 2 permit 10 

match ip address 2 
set metric +1

route-map 2 permit 20

neighbor 24.24.24.4 route-map 2 out

 

验证:

R4:

   Network          Next Hop            Metric LocPrf Weight Path 

*>i1.1.1.1/32       34.34.34.3               0    100      0 65001 i 
* i                       24.24.24.2               1    100      0
65001 i

2.测试R4上的4.4.4.4可以传递给R2,但R2不能传递给R1

R4:

access-list 4 permit 4.4.4.4

route-map 4 permit 10 

match ip address 4 
set metric +4

route-map 4 permit 20

neighbor 24.24.24.2 route-map 4 out

 

验证:

R2:

   Network          Next Hop            Metric LocPrf Weight Path 

*> 1.1.1.1/32       12.12.12.1               0             0 65001 i 
*>i4.4.4.4/32       24.24.24.4               4    100      0 i

R1:

   Network          Next Hop            Metric LocPrf Weight Path 

*> 1.1.1.1/32       0.0.0.0                  0         32768 i 

*  4.4.4.4/32       13.13.13.3                             0 65234 i 
*>                      12.12.12.2                             0
65234 i

 

3.测试R2上的2.2.2.2可以传递给R1和R4

R1:

   Network          Next Hop            Metric LocPrf Weight Path 

*> 1.1.1.1/32       0.0.0.0                  0         32768 i 
*> 2.2.2.2/32       12.12.12.2               0             0 65234 i

R4:

*>i2.2.2.2/32       24.24.24.2               0    100      0
i

我们在R2上配置:

access-list 22 permit 2.2.2.2 



route-map 22 permit 10 

match ip address 22 
set metric +22

route-map 22 permit 20

neighbor 12.12.12.1 route-map 22 out 
neighbor 24.24.24.4 route-map 22 out

 

验证:

可以看到R1和R4上都可以看到Metric

R1:

*> 2.2.2.2/32       12.12.12.2              22             0
65234 i

R4:

*>i2.2.2.2/32       24.24.24.2              22    100      0
i


七、EBGP优于IBGP

介绍:

EBGP路由优于IBGP路由这条原则进行优选 

该原则不会做为BGP路由选路策略

 

例如:

R1、R4同时向R2发布4.4.4.4这条路由。

验证:

*  4.4.4.4/32       12.12.12.1               0             0
65001 i

在path中出现了R1所在AS,说明是从R1传来的。

因为IBGP条目不出现在BGP table中,所以不作为选路策略。

 


八、到达Next-Hop代价

介绍:这里的代价,指的是IGP的metric值。注意比较的是metric,不是AD。



 

例如:如图1-2所示,R1从属AS 1,R2-4从属AS 234

R2-3 与 R4使用lookback 0口建立邻居。

其中R2——R4使用Rip建立底层

其中R3——R4使用Eigrp建立底层

如下效果:

R4#sh ip bgp 1.1.1.1 

BGP routing table entry for 1.1.1.1/32, version 6 

Paths: (2 available, best #2, table Default-IP-Routing-Table) 

  Not advertised to any peer 

  1 

    3.3.3.3 (metric 409600) from 3.3.3.3 (3.3.3.3) 

      Origin IGP, metric 0, localpref 100, valid, internal 

  1 

    2.2.2.2 (metric 1) from 2.2.2.2 (2.2.2.2) 

      Origin IGP, metric 0, localpref 100, valid, internal, best

可以看到虽然EIGRP(90)比RIP(120)小,但BGP只比较metric

 

我们将RIP与EIGRP对调。

   Network          Next Hop            Metric LocPrf Weight Path 

*>i1.1.1.1/32       3.3.3.3                  0    100      0 1 i 

* i                       2.2.2.2                  0    100      0
1 i

  

 

 


九、负载均衡

介绍:当BGP进程下面配置了maximum-paths [ibgp]  2-6,那么将执行等价负载均衡

例如:R4到1.1.1.1/32走负载均衡。

R4:

maximum-paths ibgp 2

验证:

R4:

B       1.1.1.1 [200/0] via 34.34.34.3, 00:00:02 

                [200/0] via 24.24.24.2, 00:00:02

 

R4#tracer 1.1.1.1 so lo 0

Type escape sequence to abort. 

Tracing the route to 1.1.1.1

  1 34.34.34.3 112 msec 

    24.24.24.2 236 msec 

    34.34.34.3 408 msec

 


十、EBGP越老越优先

介绍:会根据EBGP路由安装进BGP表的先后顺序进行优选,先安装的EBGP路由会被优选

例如:

R1上学到4.4.4.4/32的路由,通过R2和R3

如下:

R1:

r  4.4.4.4/32       13.13.13.3                             0
65234 i 

r>                      12.12.12.2                             0
65234 i

当我们重启R2的邻居时,会优先选择老的路由R3

R1:

r  4.4.4.4/32       12.12.12.2                             0
65234 i 

r>                      13.13.13.3                             0
65234 i

 


十一、Router-id

介绍:Router-ID越小,越优先。

注意,在配置router-id的时候BGP会自动重启进程,引起各种中断。

例如:

R1上学到4.4.4.4/32的路由,通过R2和R3

默认情况下,R1:

r  4.4.4.4/32       13.13.13.3                             0
65234 i 

r>                      12.12.12.2                             0
65234 i

然后,我们修改R3 Router-id使其高于R2,并重启R1进程(为了避免十条规则)

R1:

   Network          Next Hop            Metric LocPrf Weight Path 

r  4.4.4.4/32       12.12.12.2                             0 65234 i 

r>                      13.13.13.3                             0
65234 i

 


十二、Cluster-list长度

介绍:长度越小,越优先 

仅在存在反射器的环境下,才会进行Cluster-list长度的比较,RR在执行路由反射动作时会将自己的Cluster ID添加在Cluster-list中.

 


十三、最小邻居地址

介绍:优选最低对等体地址收到的路由条目。

例如:如图1-1,在没有配置策略和router-id的情况下,选择24.24.24.2路径。即最小邻居(对等体)地址。

摘自“http://loneblog.com/blog/new-bgp-router-rules-1.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  BGP 选路