local-preference
本地優先級屬性
僅在IBGP對等體之間交換,不通告給其他AS
優先級越大越優先,默認爲100
用於同一AS多個出口,出去的選路
屬於公認任意屬性
注意:源路由傳遞方向+指定的peer+希望傳遞的方向(import/export)才能正確應用路由策略。
默認R5 55.1.1.1訪問R1 11.1.1.1 都走R2,通過修改local-preference屬性使AS200選擇出去到11.1.1.1選擇R3
route-policy LOCAL permit node 10
if-match acl 2000
apply local-preference 2289
#
route-policy LOCAL permit node 20
acl number 2000
rule 5 permit source 11.1.1.1 0
有兩種方式:
第一種:在R3上 peer 10.1.13.1 route-policy LOCAL import
[R3]dis bgp routing-table
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 11.1.1.1/32 10.1.13.1 0 2289 0 100i
*>i 55.1.1.1/32 44.1.1.1 0 100 0 300i
*> 111.1.1.1/32 10.1.13.1 0 0 100i
只有有IBGP對等體的纔會有local-preference值,因爲local-preference只在IBGP傳遞
[R4]dis bgp routing-table
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 11.1.1.1/32 33.1.1.1 0 2289 0 100i
* i 22.1.1.1 0 100 0 100i
*> 55.1.1.1/32 10.1.45.5 0 0 300i
*>i 111.1.1.1/32 22.1.1.1 0 100 0 100i
* i 33.1.1.1 0 100 0 100i
[R5]dis bgp routing-table
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 11.1.1.1/32 10.1.45.4 0 200 100i
*> 55.1.1.1/32 0.0.0.0 0 0 i
*> 111.1.1.1/32 10.1.45.4 0 200 100i
[R5]tracert -a 55.1.1.1 11.1.1.1
1 10.1.45.4 30 ms 50 ms 50 ms
2 10.1.34.3 60 ms 60 ms 60 ms 受路由策略影響,選擇R3
3 10.1.13.1 60 ms 70 ms 40 ms
<Huawei>tracert -a 11.1.1.1 55.1.1.1
1 10.1.12.2 30 ms 40 ms 50 ms 不受路由策略影響,仍選擇R2
2 10.1.24.4 80 ms 80 ms 60 ms
3 10.1.45.5 110 ms 90 ms 80 ms
-----------------------------------------------------------------
第二種:在R3 peer 44.1.1.1 route-policy LOCAL export
[R3]display bgp routing-table
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 11.1.1.1/32 10.1.13.1 0 2289 0 100i
*>i 55.1.1.1/32 44.1.1.1 0 100 0 300i
*> 111.1.1.1/32 10.1.13.1 0 0 100i
[R4]dis bgp routing-table
Total Number of Routes: 5
Network NextHop MED LocPrf PrefVal Path/Ogn
*>i 11.1.1.1/32 33.1.1.1 0 2289 0 100i
* i 22.1.1.1 0 100 0 100i
*> 55.1.1.1/32 10.1.45.5 0 0 300i
*>i 111.1.1.1/32 22.1.1.1 0 100 0 100i
* i 33.1.1.1 0 100 0 100i
[R5]dis bgp routing-table
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 11.1.1.1/32 10.1.45.4 0 200 100i
*> 55.1.1.1/32 0.0.0.0 0 0 i
*> 111.1.1.1/32 10.1.45.4 0 200 100i
針對第一條路由,由於local-preference是IBGP對等之間傳遞,且不傳遞給其他AS。由於R5沒有IBGP,並且也不會有R4傳遞給R5,所以第一條路由的local-preference爲空?
[R5]tracert -a 55.1.1.1 11.1.1.1
1 10.1.45.4 30 ms 30 ms 50 ms
2 10.1.34.3 60 ms 60 ms 60 ms
3 10.1.13.1 80 ms 80 ms 60 ms
<R1>tracert -a 11.1.1.1 55.1.1.1
1 10.1.12.2 20 ms 40 ms 30 ms
2 10.1.24.4 100 ms 70 ms 50 ms
3 10.1.45.5 100 ms 90 ms 120 ms