BGP路由优选
当到达同一个目的网段存在多条路由时,BGP通过如下的次序进行路由优选
01 优选Preferred-Value属性值最大的路由。
02 优选Local_Preference属性值最大的路由。
03 本地始发的BGP路由优于从其他对等体学习到的路由,本地始发的路由优先级:优选手动聚合>自动聚合>network>import>从对等体学到的。
04 优选AS_Path属性值最短的路由。
05 优选Origin属性最优的路由。Origin属性值按优先级从高到低的排列是:IGP、EGP及Incomplete。
06 优选MED属性值最小的路由。
07 优选从EBGP对等体学来的路由(EBGP路由优先级高于IBGP路由)。
08 优选到Next_Hop的IGP度量值最小的路由。
09 优选Cluster_List最短的路由。
10 优选Router ID(Orginator_ID)最小的设备通告的路由。
11 优选具有最小IP地址的对等体通告的路由。
上述规则依序排列,BGP进行路由优选时,从第一条规则开始执行,如果根据第一条规则无法作出判断,例如路由的Preferred-Value属性值相同,则继续执行下一条规则,如果根据当前的规则,BGP能够决策出最优的路由,则不再继续往下执行。类似于ACL匹配规则。
BGP路由优选逐条分析
实验拓扑
查看BGP详细路由,可查看未被优选的原因
<R7>display bgp routing-table 11.11.11.11
BGP local router ID : 7.7.7.7
Local AS number : 200
Paths: 2 available, 1 best, 1 select
BGP routing table entry information of 11.11.11.11/32:
From: 5.5.5.5 (5.5.5.5)
Route Duration: 00h06m10s
Relay IP Nexthop: 20.2.0.5
Relay IP Out-Interface: GigabitEthernet0/0/0
Original nexthop: 5.5.5.5
Qos information : 0x0
AS-path 100, origin igp, MED 0, localpref 100, pref-val 0, valid, internal, bes
t, select, active, pre 255, IGP cost 1
Not advertised to any peer yet
BGP routing table entry information of 11.11.11.11/32:
From: 6.6.6.6 (6.6.6.6)
Route Duration: 00h06m25s
Relay IP Nexthop: 20.3.0.6
Relay IP Out-Interface: GigabitEthernet0/0/1
Original nexthop: 6.6.6.6
Qos information : 0x0
AS-path 100, origin igp, localpref 100, pref-val 0, valid, internal, pre 255, I
GP cost 1, not preferred for router ID
Not advertised to any peer yet
分析:其中,第二条路由最下面注明了“not preferred for router ID”,说明这条路由未被优选的原因是Router ID比较大。
多条BGP路由负载均衡(影响本机)
[R7-bgp]maximum load-balancing ibgp ?
INTEGER<1-8> Specify maximum equal cost routes
01 优选Preferred-Value属性值最大的路由(华为设备特有属性)
修改属性方式:
1 使用preferred-value命令修改(在本机上修改,影响自身的路由优选)
[R7]bgp 200
[R7-bgp]peer 6.6.6.6 preferred-value 100
查看修改后的结果
<R7>display bgp routing-table
BGP Local router ID is 7.7.7.7
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 11
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 11.11.11.11/32 6.6.6.6 100 100 100i
* i 5.5.5.5 0 100 0 100i
*>i 22.22.22.22/32 6.6.6.6 0 100 100 100i
* i 5.5.5.5 100 0 100i
*>i 33.33.33.33/32 6.6.6.6 100 100 100i
* i 5.5.5.5 100 0 100i
*>i 44.44.44.44/32 6.6.6.6 100 100 100i
* i 5.5.5.5 100 0 100i
*>i 55.55.55.55/32 5.5.5.5 0 100 0 i
*>i 66.66.66.66/32 6.6.6.6 0 100 100 i
*> 77.77.77.77/32 0.0.0.0 0 0 i
分析:PrefVal字段大的路由,被优选。修改preferred-value的特性是所有下一跳为6.6.6.6的路由都被优选,属于对全局进行修改。
2 使用路由策略修改(在本机上修改,影响自身的路由优选)
[R7]acl 2000
[R7-acl-basic-2000]rule 5 permit source 11.11.11.11 0
[R7]route-policy 1 permit node 10
[R7-route-policy]if-match acl 2000
[R7-route-policy]apply preferred-value 200
[R7]bgp 200
[R7-bgp]peer 5.5.5.5 route-policy 1 import
查看修改后的结果
<R7>display bgp routing-table
BGP Local router ID is 7.7.7.7
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 7
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 11.11.11.11/32 5.5.5.5 0 100 200 100i
* i 6.6.6.6 100 100 100i
*>i 22.22.22.22/32 6.6.6.6 0 100 100 100i
*>i 33.33.33.33/32 6.6.6.6 100 100 100i
*>i 44.44.44.44/32 6.6.6.6 100 100 100i
*>i 66.66.66.66/32 6.6.6.6 0 100 100 i
*> 77.77.77.77/32 0.0.0.0 0 0 i
分析:采用策略路由的方式进行修改,可修改某条指定的路由条目,相对于第1中方法,更加的精准。
02 优选Local_Preference属性值最大的路由。
本地优先级属性会在AS内部传递,不会传递给其他AS。缺省值100。
修改属性方式:
1 修改默认本地优先级(在AS内的边界路由上器修改,影响AS内部的其他路由器)
[R5]bgp 200
[R5-bgp]default local-preference 200
[R6]bgp 200
[R6-bgp]default local-preference 200
查看修改后的结果
<R7>dis bgp routing-table
BGP Local router ID is 7.7.7.7
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 11
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 11.11.11.11/32 5.5.5.5 0 200 0 100i
* i 6.6.6.6 200 0 100i
*>i 22.22.22.22/32 5.5.5.5 200 0 100i
* i 6.6.6.6 0 200 0 100i
*>i 33.33.33.33/32 5.5.5.5 200 0 100i
* i 6.6.6.6 200 0 100i
*>i 44.44.44.44/32 5.5.5.5 200 0 100i
* i 6.6.6.6 200 0 100i
*>i 55.55.55.55/32 5.5.5.5 0 200 0 i
*>i 66.66.66.66/32 6.6.6.6 0 200 0 i
*> 77.77.77.77/32 0.0.0.0 0 0 i
分析:所有LocPrf字段值都变为200,属于对全局进行修改。
2 使用路由策略修改(在AS内的边界路由上器修改,影响AS内部的其他路由器)
[R5]acl 2000
[R5-acl-basic-2000]rule 5 permit source 11.11.11.11 0
[R5]route-policy 1 permit node 10
[R5-route-policy]if-match acl 2000
[R5-route-policy]apply local-preference 300
[R5]route-policy 1 permit node 20
[R5]bgp 200
[R5-bgp]peer 1.1.1.1 route-policy 1 import
查看修改结果
<R7>display bgp routing-table
BGP Local router ID is 7.7.7.7
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 10
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 11.11.11.11/32 5.5.5.5 0 300 0 100i
*>i 22.22.22.22/32 5.5.5.5 200 0 100i
* i 6.6.6.6 0 200 0 100i
*>i 33.33.33.33/32 5.5.5.5 200 0 100i
* i 6.6.6.6 200 0 100i
*>i 44.44.44.44/32 5.5.5.5 200 0 100i
* i 6.6.6.6 200 0 100i
*>i 55.55.55.55/32 5.5.5.5 0 200 0 i
*>i 66.66.66.66/32 6.6.6.6 0 200 0 i
*> 77.77.77.77/32 0.0.0.0 0 0 i
分析:采用策略路由的方式进行修改,可修改某条指定的路由条目,相对于第1中方法,更加的精准。
03 本地始发的BGP路由优于从其他对等体学习到的路由,本地始发的路由优先级:优选手动聚合>自动聚合>network>import>从对等体学到的
04 优选AS_Path属性值最短的路由
详见
05 优选Origin属性最优的路由。Origin属性值按优先级从高到低的排列是:IGP、EGP及Incomplete
详见
06 优选MED属性值最小的路由
MED(Multi-Exit Discriminator,多出口鉴别器)是可选非过渡属性,是一种度量值,用于向外部对等体指出进入本AS的首选路径,即当进入本AS的入口有多个时,AS可以使用MED动态地影响其他AS选择进入的路径。
MED属性值越小则BGP路由越优。
MED主要用于在AS之间影响BGP的选路。MED被传递给EBGP对等体后,对等体在其AS内传递路由时,携带该MED值,但将路由再次传递给其EBGP对等体时,缺省不会携带MED属性。
特性:
MED最多只影响相邻的两个AS,收到MED属性的AS不会再把它传递给其他AS。
MED属性类似COST,适用在当一个目的地有多个路由情况下,和一个AS有多个入口的情况下,可手动配置MED进行路由的优选。
使用路由策略修改(在AS内的边界路由上器修改,影响AS内其他路由器-export,影响自身-import)
[R5]acl 2000
[R5-acl-basic-2000]rule 5 permit source 11.11.11.11 0
[R5]route-policy 1 permit node 10
[R5-route-policy]if-match acl 2000
[R5-route-policy]apply cost 20
[R5]bgp 200
[R5-bgp]peer 1.1.1.1 route-policy 1 import
[R5-bgp]compare-different-as-med
[R5-bgp]bestroute med-none-as-maximum
PS:
compare-different-as-med命令。缺省情况下,路由器只比较来自同一相邻AS的BGP路由的MED值,可以通过该命令开启来自不同AS的相同路由也比较MED值。
bestroute med-none-as-maximum命令。配置BGP在选择最优路由时,如果路由属性中没有MED值则按最大值处理。
查看修改结果
[R5]display bgp routing-table
BGP Local router ID is 5.5.5.5
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
Total Number of Routes: 11
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 11.11.11.11/32 1.1.1.1 100 0 100i
* i 6.6.6.6 100 0 100i
*>i 22.22.22.22/32 6.6.6.6 0 100 0 100i
* 1.1.1.1 0 100i
*> 33.33.33.33/32 1.1.1.1 0 100i
* i 6.6.6.6 100 0 100i
*> 44.44.44.44/32 1.1.1.1 0 100i
* i 6.6.6.6 100 0 100i
*> 55.55.55.55/32 0.0.0.0 0 0 i
*>i 66.66.66.66/32 6.6.6.6 0 100 0 i
*>i 77.77.77.77/32 7.7.7.7 0 100 0 i
分析:去往11.11.11.11的路由因为下一跳1.1.1.1的路由MED值改为了100,但是因为配置了bestroute med-none-as-maximum命令,因此去往11.11.11.11和22.22.22.22的路由中,MED在丢失的情况下的路由为最大值,都不被优选。
07 优选从EBGP对等体学来的路由(EBGP路由优先级高于IBGP路由)
假如到达一个目的地有2条不同的路由,一条从IBGP学习到,一条从EBGP学习到,会优选EBGP学习到的这条。
08 优选到Next_Hop的IGP度量值最小的路由
指底层IGP协议的开销值,例如OSPF、IS-IS
修改方式详见
09 优选Cluster_List最短的路由
相关命令
配置反射器
[R7-bgp]peer 6.6.6.6 reflect-client
10 优选Router ID(Orginator_ID)最小的设备通告的路由
11 优选具有最小IP地址的对等体通告的路由
指更新源地址大小