BGP選路原則

IPA-task packet002BGP選路原則

實驗二:BGP選路原則


實驗目標:調試和觀察BGP的選路原則

實驗TOP

物理拓撲

wKioL1NUubPBiJaSAAJsDD2pKgI315.jpg

wKioL1NUubaxJR-zAAIdoEWtYRI979.jpg

邏輯拓撲



基本配置:


R1


!

hostname R1

!

no ip domain lookup

!

interface Loopback0

ip address 1.1.1.1 255.255.255.0

!

interface Loopback10

ip address 10.10.10.10 255.255.255.0

ip ospf network point-to-point

!

interface Ethernet0/0

ip address 10.1.1.1 255.255.255.0

!

interface Serial1/0

ip address 12.1.1.1 255.255.255.0

serial restart-delay 0

clock rate 64000

!

interface Serial2/0

ip address 13.1.1.1 255.255.255.0

serial restart-delay 0

!

router ospf 10

router-id 1.1.1.1

log-adjacency-changes

network 10.1.1.0 0.0.0.255 area 0

network 10.10.10.0 0.0.0.255 area 0

network 12.1.1.0 0.0.0.255 area 0

network 13.1.1.0 0.0.0.255 area 0

!

router bgp 1

no synchronization

bgp router-id 1.1.1.1

bgp log-neighbor-changes

network 1.1.1.0 mask 255.255.255.0

neighbor 10.1.1.4 remote-as 345

neighbor 12.1.1.2 remote-as 2

neighbor 13.1.1.3 remote-as 345

no auto-summary

!

ip classless

no ip http server

no ip http secure-server

!

!

line con 0

exec-timeout 0 0

logging synchronous

line aux 0

line vty 0 4

!

end




R2


!

hostname R2

!

no ip domain lookup

!

!

interface Loopback0

ip address 2.2.2.2 255.255.255.0

!

interface Loopback10

ip address 20.20.20.20 255.255.255.0

ip ospf network point-to-point

!

interface Ethernet0/0

no ip address

shutdown

!

interface Serial1/0

ip address 24.1.1.2 255.255.255.0

serial restart-delay 0

clock rate 64000

!

interface Serial2/0

ip address 12.1.1.2 255.255.255.0

serial restart-delay 0

!

router ospf 10

router-id 2.2.2.2

log-adjacency-changes

network 12.1.1.0 0.0.0.255 area 0

network 20.20.20.0 0.0.0.255 area 0

network 24.1.1.0 0.0.0.255 area 0

!

router bgp 2

no synchronization

bgp router-id 2.2.2.2

bgp log-neighbor-changes

network 2.2.2.0 mask 255.255.255.0

neighbor 12.1.1.1 remote-as 1

neighbor 24.1.1.4 remote-as 345

no auto-summary

!

ip classless

no ip http server

no ip http secure-server

!

!

!

!

!

line con 0

exec-timeout 0 0

logging synchronous

line aux 0

line vty 0 4

!

end




R3


!

hostname R3

!

no ip domain lookup

!

!

interface Loopback0

ip address 3.3.3.3 255.255.255.0

!

interface Loopback10

ip address 30.30.30.30 255.255.255.0

ip ospf network point-to-point

!

interface Ethernet0/0

no ip address

shutdown

!

interface Serial1/0

ip address 13.1.1.3 255.255.255.0

serial restart-delay 0

clock rate 64000

!

interface Serial2/0

ip address 35.1.1.3 255.255.255.0

serial restart-delay 0

!

router ospf 10

router-id 3.3.3.3

log-adjacency-changes

network 13.1.1.0 0.0.0.255 area 0

network 30.30.30.0 0.0.0.255 area 0

network 35.1.1.0 0.0.0.255 area 0

!

router bgp 345

no synchronization

bgp router-id 3.3.3.3

bgp log-neighbor-changes

network 3.3.3.0 mask 255.255.255.0

neighbor 13.1.1.1 remote-as 1

neighbor 35.1.1.5 remote-as 345

neighbor 45.1.1.4 remote-as 345

no auto-summary

!

ip classless

no ip http server

no ip http secure-server

!

!

!

!

!

line con 0

exec-timeout 0 0

logging synchronous

line aux 0

line vty 0 4

!

End




R4


!

hostname R4

!

no ip domain lookup

!

!

interface Loopback0

ip address 4.4.4.4 255.255.255.0

!

interface Loopback10

ip address 40.40.40.40 255.255.255.0

ip ospf network point-to-point

!

interface Ethernet0/0

ip address 10.1.1.4 255.255.255.0

!

interface Serial1/0

ip address 45.1.1.4 255.255.255.0

serial restart-delay 0

clock rate 64000

!

interface Serial2/0

ip address 24.1.1.4 255.255.255.0

serial restart-delay 0

!

router ospf 10

router-id 4.4.4.4

log-adjacency-changes

network 10.1.1.0 0.0.0.255 area 0

network 24.1.1.0 0.0.0.255 area 0

network 40.40.40.0 0.0.0.255 area 0

network 45.1.1.0 0.0.0.255 area 0

!

router bgp 345

no synchronization

bgp router-id 4.4.4.4

bgp log-neighbor-changes

network 4.4.4.0 mask 255.255.255.0

neighbor 10.1.1.1 remote-as 1

neighbor 24.1.1.2 remote-as 2

neighbor 35.1.1.3 remote-as 345

neighbor 45.1.1.5 remote-as 345

no auto-summary

!

ip classless

no ip http server

no ip http secure-server

!

!

!

!

!

line con 0

exec-timeout 0 0

logging synchronous

line aux 0

line vty 0 4

!

End




R5


!

hostname R5

!

no ip domain lookup

!

!

interface Loopback0

ip address 5.5.5.5 255.255.255.0

!

interface Loopback10

ip address 50.50.50.50 255.255.255.0

ip ospf network point-to-point

!

interface Ethernet0/0

no ip address

shutdown

!

interface Serial1/0

ip address 35.1.1.5 255.255.255.0

serial restart-delay 0

clock rate 64000

!

interface Serial2/0

ip address 45.1.1.5 255.255.255.0

serial restart-delay 0

!

router ospf 10

router-id 5.5.5.5

log-adjacency-changes

network 35.1.1.0 0.0.0.255 area 0

network 45.1.1.0 0.0.0.255 area 0

network 50.50.50.0 0.0.0.255 area 0

!

router bgp 345

no synchronization

bgp router-id 5.5.5.5

bgp log-neighbor-changes

network 5.5.5.0 mask 255.255.255.0

neighbor 35.1.1.3 remote-as 345

neighbor 45.1.1.4 remote-as 345

no auto-summary

!

ip classless

no ip http server

no ip http secure-server

!

!

!

!

!

line con 0

exec-timeout 0 0

logging synchronous

line aux 0

line vty 0 4

!

End


(注:路由器接口默認是關閉的,所以應將對應的接口開啓)

如上配置,已經將R1R5基本配置完成。




BGP選路規則:


BGP路由信息庫(RIB)包括

Adj-RIBs-In:儲存未經處理的路由信息,來自對等體接收到的更新消息,所包含的路由信息是可用的

Loc-RIB: 包含的路由是運行BGP的路由器通過對Adj-RIBs-In中的路由使用他的本地路由策略而選擇的路由

Adj-RIBs-Out:包含運行BGP的路由器向其對等體公佈的路由


三個數據庫間的處理方法如下:

1、爲每一條可用路由計算優先級,並對BGP update消息中包含的路由信息變更做出處理。

2、將最優路由放入Loc-RIB

3、將適合的路由放入Adj-RIBs-Out(調用僅在上一步完成後)。


BGP路徑選擇順序

1、優選有最大Weight的路由 (範圍065,535)

AweightCISCO私有的參數,路由器配置了權重後在本地有效。


2、優選有最大LOCAL_PREF值的路由(範圍04,294,967,295)


3、優選從本路由器始發的路由(包括本地network配置的重分佈,或者在IGP表中已經有一些需要被配置路由聚合的地址,在BGP中用Aggregate命令配置的路由聚合)。


4、優選有最短AS_PATH的路由。

A:如果配置了Bgp bestpath as-path ignore,則這個步驟被忽略。

B:一個AS路徑集被當作一個AS,無論在這個集合中有多少ASAS路徑長度中沒有包括。AS_CONFED_SEQUENCE


5、根據Origin屬性,優選具有最低起源類型的路由(IGP>EGP>Incomplete)。


6、優選最小MED值的路由(範圍04,294,967,295)

A:只有在通過兩條路徑得到第一個AS(對等體)是同一個AS時才進行MED比較;任何子自治域的聯盟系統都會被忽略。也就是說,只有在AS序列號中第一個AS號碼一致時,才進行MED比較;任何聯盟AS序列號(AS_CONFED_SEQUENCE)都會被忽略。

B:如果路由器上配置了bgp always—compare—med,在全部的路徑進行MED比較。但是這需要全體AS都同時啓用這個功能,否則有可能發生路由環路。

C:如果路由器上配置了bgp bestpath med confed,將對所有隻包括AS_CONFED_SEQUE

NCE的路徑進行MED比較(即路徑是起源於本地聯盟)。

D:如果接收到的路徑沒有分配MED值,則將此路徑分配爲0,除非路由器上配置了bestpath missing—is—worst,將被看作MED值爲4,294,967,295的路由將在注入到BGP路由選擇表之前被改爲4,294,967,295

EBGP明確的MED9也可以影響此步驟。


7、外部路由eBGP優先於聯盟(confederation)外部路由優於內部路由iBGP(優選eBGP路由)。

注意,路徑中包括AS_CONFEND_SEQUENCE屬性對聯盟只有在本地有效,因此被看作是內部路徑。無法區別外部聯盟和內部聯盟。


8、優選能通過最近的IGP鄰居到達的路徑(優選對BGP下一跳具有最低IGP度量值的路徑)。


9、如果在路由器上配置了maximum—pathsN,而且從同一個對等體自治域/子自治域接收到多條外部/外部聯盟的路徑,則最多可以將N條最近接收到的路徑加入到IP路由選擇表中,這可以使得eBGP在多條路徑上進行負載分擔,目前N所代表的最大數目是6;當沒有啓用此功能時,缺省數值是1。在輸入了showip bgp x.x.x.x後系統輸出信息中可以看到最早接收到的路徑被標記爲最優路徑,在將這條最優路徑轉發到內部對等體之前,需要執行與next_hop_self作用相同的功能。


10、如果是external的路由,優選最老的路由(最先被學習到的路由)

A:此步驟可以將路由擺動的影響減到最小,因爲新接收到的路徑不會取代老的,即使這條新接收的路徑是通過下面提及到的額外路徑選擇標準來進行選擇的。這使得只在iBGP路徑下應用額外的選擇步驟更有意義。

B:此步驟可以被bgp bestpath compare_routerid命令語句所關閉。

C:如果路由器標誌是一樣的,此步驟可以被屏蔽,因爲這說明路由器正在從自己那裏接收路由。

D:如果當前沒有最優路由器,此步驟可以被屏蔽。當提供某個路徑的對等體路由器宏機,就會發生丟失當前最優路徑的情況。


11、如果在同一時間學習到多條到同一目的地的路由,優選最小BGP-router-ID的路由,注意,如果一個路徑包括路由反射器屬性,起始者標識將代替路由器標識在路徑選擇過程中起作用。


12、如果路由從路由反射器上學習到,優選最小Cluster-IDBGP_IDof the route reflector)長度的路由,而且它運行客戶機和其他反射器族中的RR/Clients之間做對等連接,在這種情況下,路由器必須知道BGP協議中的RR的具體配置。


13、優選具有最低對等體地址接收到的路徑。這個地址是在BGP對等體上配置並使用的地址,這個地址是本地對等體路由器在其上配置TCP鄰居並與遠端對等體建立連接時採用的地址。




BGP路徑選擇順序:

如果路徑不可達或者同步開啓後,路徑不同步,則該路徑不參與選路

1Weight——權重(越大越優先,Cisco私有屬性)

2Local_Pref——本地優先(越大越優先,本AS內有效)

3Next_Hop——所傳遞路由的本地起源優先,即下一跳是0.0.0.0(在BGP表中,當前路由器通告的路由的下一跳爲0.0.0.0

4AS_Path(越短越優先,對於outin方向的AS_Path操作產生的效果是不同的)

5Origin起源(優先:IGP>EGP>IncompleteIGP指通過在BGPnetwork通告出來的路由,Incomplete指在BGP 中通過重發布通告出來的路由)

6MED(越小越優先,影響另一個AS的出站選路)

7eBGP>iBGP(從eBGP對等體學習的路由優先於從iBGP對等體學習的路由)

8BGP 優先選擇到BGP下一跳的IGP度量最低的路徑

9、如果有多條來自相同相鄰AS的路由並通過Maximum-paths使多條路徑可用,則將所有開銷相同的路由加入Loc-RIB

10AgeeBGP)(Age越大越優先,多條路徑具有相同的RID,這個原則不考慮)

11BGP 鄰居的RID(越小越優先)

12、如果多條路徑始發路由器ID或路由器ID相同,那麼優選Cluster-List最短的路徑

13、選擇鄰居ip地址最小的路由


下面根據觀察每臺路由器的BGP表並根據BGP的路徑選擇順序進行分析:


R1


我們可以通過show ip bgp命令來查看本路由器的BGP表,以下爲R1BGP表。


R1#show ip bgp

BGP table version is 6, local router ID is 1.1.1.1

Status codes: s suppressed, d damped, h history, * valid, > best,i - internal,

             r RIB-failure, SStale

Origin codes: i - IGP, e - EGP, ? - incomplete


  Network        Next Hop            Metric LocPrf Weight Path

*> 1.1.1.0/24       0.0.0.0                  0         32768 i

*  2.2.2.0/24       10.1.1.4                               0 345 2 i

*>                12.1.1.2                 0             0 2 i

*                13.1.1.3                              0 345 2 i

*  3.3.3.0/24       10.1.1.4                               0 345 i

*                12.1.1.2                              0 2 345 i

*>                13.1.1.3                 0             0 345 i

*  4.4.4.0/24       10.1.1.4                 0             0 345 i

*                12.1.1.2                              0 2 345 i

*>                13.1.1.3                               0 345 i

*  5.5.5.0/24       10.1.1.4                               0 345 i

*                12.1.1.2                               0 2 345 i

*>                13.1.1.3                               0 345 i


分析:

2.2.2.0/24從拓撲圖中可以看到R1分別從R2R3R4三個eBGP對等體學習到2.2.2.0網段,但最後只將從R2學習到的下一跳爲12.1.1.2的路由條目作爲最優路徑裝進路由表。

根據BGP的路徑選擇順序:

1Weight(未設置)

2、Local_Perf(未設置)

3、Next_Hop(無)

4、AS_Path

由於從R3和R4學習到的路由條目跨越了AS 345,所以由R3和R4傳來的路由條目爲2跳,最終選擇由R2傳來下一跳爲12.1.1.2的路由條目裝進路由表。

(注意:當BGP協議依據某條選路規則選出最優路徑時,將不再考慮後面的規則。)


3.3.3.0/24R1分別從R2R3R4三個eBGP對等體學習到3.3.3.0網段,並將下一跳爲13.1.1.3的路由條目裝進路由表。

根據BGP的路徑選擇順序:

1Weight(未設置)

2、Local_Perf(未設置)

3、Next_Hop(無)

4、AS_Path

由R2傳來的路由條目爲2跳,R3和R4相同,都爲1跳,所以先排除R2傳來的路由條目爲最佳路由。

5、Origin起源(無)

6、MED值(未設置)

7、eBGP>iBGP(R3和R4同爲R1的eBGP對等體)

8、cost(用於iBGP)

9、Maximum-paths(無)

10、Age(用於eBGP,越大越優先)

這裏我們用show ip bgp summary查看R1與R3、R4的老化時間。可以看到R1與R3建立對等體的時間較長,所以選擇由R3傳來的下一跳爲13.1.1.3的路由條目做爲最佳路徑裝進路由表。


R1#show ip bgp summary

BGP router identifier 1.1.1.1, local ASnumber 1

BGP table version is 6, main routing tableversion 6

5 network entries using 505 bytes of memory

13 path entries using 624 bytes of memory

6 BGP path attribute entries using 360bytes of memory

4 BGP AS-PATH entries using 96 bytes ofmemory

0 BGP route-map cache entries using 0 bytesof memory

0 BGP filter-list cache entries using 0bytes of memory

BGP using 1585 total bytes of memory

BGP activity 15/10 prefixes, 39/26 paths,scan interval 60 secs


Neighbor        V   AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down State/PfxRcd

10.1.1.4        4  345     181     180       6    0    0 02:19:07       4

12.1.1.2        4    2     182     182       6    0    0 02:19:08        4

13.1.1.3        4  345     181     179       6    0    0 02:19:12       4


4.4.4.0/24情況同R3,所以R1學習4.4.4.0網段並不是通過R4學到,而是由R3傳遞過來,下一跳爲13.1.1.3


5.5.5.0/24情況同R3,需要注意的是R4在傳遞路由時遵循路由傳遞原則,即iBGP對等體學來的路由,傳遞給自身直連的eBGP對等體,下一跳更改,所以下一跳爲13.1.1.3






路由器R2R3R4R5將不在一一贅述,只挑其中比較有代表性的來分析。


R3


R3#show ip bgp

BGP table version is 13, local router ID is3.3.3.3

Status codes: s suppressed, d damped, hhistory, * valid, > best, i - internal,

             r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? -incomplete


 Network       Next Hop            Metric LocPrf Weight Path

* i1.1.1.0/24      10.1.1.1                 0    100     0 1 i

*>              13.1.1.1                 0             0 1 i

* 2.2.2.0/24     13.1.1.1                               0 1 2 i

*>i             24.1.1.2                 0    100     0 2 i

*> 3.3.3.0/24     0.0.0.0                  0         32768 i

*>i4.4.4.0/24    45.1.1.4                 0    100     0 i

*>i5.5.5.0/24     35.1.1.5                 0    100     0 i


分析:

4.4.4.0/24BGP表中可以看到R3只從R4學習到下一跳爲45.1.1.4的條目做爲最佳路由裝進路由表中。但從拓撲中我們知道R1R5同爲R3的對等體,爲何R1R5不向R3傳遞路由條目?這裏需要注意,由於R5R3R4都是iBGP對等體的關係,遵循路由傳遞原則,即從直連iBGP對等體學來的路由,不會再傳給直連的另外一個iBGP對等體,所以R5是不會向R3傳遞R4的路由條目的;再看R1,因爲R1是從AS 345學習到R44.4.4.0條目,所以R1不會再傳回給AS 345,這點很像矢量路由中的“水平分割”。




R4


R4# show ip bgp

BGP table version is 13, local router ID is4.4.4.4

Status codes: s suppressed, d damped, hhistory, * valid, > best, i - internal,

             r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? -incomplete


 Network        Next Hop            Metric LocPrf Weight Path

*  1.1.1.0/24      24.1.1.2                               0 2 1 i

* i               13.1.1.1                 0    100     0 1 i

*>               10.1.1.1                 0             0 1 i

* 2.2.2.0/24      10.1.1.1                               0 1 2 i

*>               24.1.1.2                 0             0 2 i

*>i3.3.3.0/24       35.1.1.3                 0    100     0 i

*> 4.4.4.0/24       0.0.0.0                  0         32768 i

*>i5.5.5.0/24       45.1.1.5                 0    100     0 i


分析:

1.1.1.0/24R4分別從R1R2R3三個對等體學習到1.1.1.0網段,並將下一跳爲10.1.1.1的路由條目裝進路由表。

根據BGP的路徑選擇順序:

1Weight(未設置)

2、Local_Perf(未設置)

3、Next_Hop(無)

4、AS_Path

由R2傳來的路由條目爲2跳,R1和R2相同,都爲1跳,所以先排除R2傳來的路由條目爲最佳路由。

5、Origin起源(無)

6、MED值(未設置)

7、eBGP>iBGP

由於R4與R1爲eBGP對等體關係,而與R3爲iBGP對等體關係,所以R4優選從R1傳來的下一跳爲10.1.1.1的路由條目做爲最佳路由裝進路由表。




R5


R5#show ip bgp

BGP table version is 14, local router ID is 5.5.5.5

Status codes: s suppressed, d damped, h history, * valid, > best,i - internal,

             r RIB-failure, SStale

Origin codes: i - IGP, e - EGP, ? - incomplete


  Network        NextHop            Metric LocPrf Weight Path

* i1.1.1.0/24      13.1.1.1                 0    100     0 1 i

*>i               10.1.1.1                 0   100      0 1 i

*>i2.2.2.0/24      24.1.1.2                 0    100     0 2 i

*>i3.3.3.0/24      35.1.1.3                 0    100     0 i

*>i4.4.4.0/24      45.1.1.4                 0    100     0 i

*> 5.5.5.0/24      0.0.0.0                  0         32768 i


分析:


1.1.1.0/24R5分別從R3R4兩個對等體學習到1.1.1.0網段,並將下一跳爲10.1.1.1的路由條目裝進路由表。

根據BGP的路徑選擇順序:

1Weight(未設置)

2、Local_Perf(未設置)

3、Next_Hop(無)

4、AS_Path(同爲1跳)

5、Origin起源(無)

6、MED值(未設置)

7、eBGP>iBGP(R3和R4同爲R5的iBGP對等體)

8、cost(用於iBGP)

由於整網起OSPF協議,R1與R4之間是用以太網線路連接,因此R5通過R4到R1的cost值爲65;而通過R3到R1的cost值爲128,所以最終選擇R4傳來的下一跳爲10.1.1.1的路由條目做爲最佳路由裝進路由表。

(注意:因爲這裏沒有在R4上配置next-hop-self參數,所以R4在傳遞路由時遵循路由傳遞原則,即從eBGP對等體學來的路由,傳遞給自身直連的iBGP對等體,下一跳不改。)



以上我們分析了R1R5BGP表,瞭解到了部分BGP選路原則在網絡中是如何工作的,下面我們將配置和調試BGP選路原則種的Weight屬性、Local_Pref屬性、AS_Path屬性及MED屬性。


Weight屬性的用法和配置方法


基本配置不變,我們到R1show ip bgp查看一下BGP路由表:


R1#show ip bgp

BGP table version is 12, local router ID is1.1.1.1

Status codes: s suppressed, d damped, hhistory, * valid, > best, i - internal,

             r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? -incomplete


 Network         Next Hop            Metric LocPrf Weight Path

*> 1.1.1.0/24       0.0.0.0                  0         32768 i

* 2.2.2.0/24       10.1.1.4                               0 345 2 i

*                 13.1.1.3                               0 345 2 i

*>                12.1.1.2                 0             0 2 i

* 3.3.3.0/24       10.1.1.4                               0 345 i

*>                13.1.1.3                 0             0 345 i

*                 12.1.1.2                               0 2 345 i

* 4.4.4.0/24       10.1.1.4                 0             0 345 i

*>                13.1.1.3                               0 345 i

*                 12.1.1.2                               0 2 345 i

* 5.5.5.0/24       12.1.1.2                               0 2 345 i

*                 13.1.1.3                               0 345 i

*>                10.1.1.4                               0 345 i


2.2.2.0的路由是從12.1.1.2學到的,也就是從R2學到的,默認的Weight值爲0,因爲這條路由不是由自己產生的(如果是自己產生的路由,默認爲32768,到R2show ip bgp看到的就會是32768)。下面我們在R1上修改BGPWeight屬性,使從R4傳來的下一跳爲10.1.1.4的路由爲最優路由。


實驗配置:

R1(config)#access-list 10 permit 2.2.2.0 0.0.0.255       //創建ACL匹配感興趣的路由

R1(config)#route-map wei_2 permit 10        //配置策略路由wei_2,序號爲10,允許通過

R1(config-route-map)#match ip address 10     //匹配ACL 10定義的路由

R1(config-route-map)#set weight 65535       //設置Weight的值爲65535

R1(config-route-map)#exit

R1(config)#router bgp 1

R1(config-router)#neighbor 10.1.1.4 route-map wei_2 in  //在鄰居10.1.1.4上應用策略路由

R1(config-router)#exit


上面的配置很關鍵,首先需要定義ACL,用來標記需要使用策略的路由,然後配置策略路由,匹配剛纔定義的感興趣的路由,最後分別應用到鄰居上,注意方向爲inWeight屬性本地有效),BGP會優先選擇Weight值大的路徑。

這樣配置完成後,我們先在R1clear ip bgp *,然後再來看看R1BGP表:


R1#show ip bgp

BGP table version is 9, local router ID is1.1.1.1

Status codes: s suppressed, d damped, hhistory, * valid, > best, i - internal,

             r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? -incomplete


 Network         Next Hop            Metric LocPrf Weight Path

*> 1.1.1.0/24       0.0.0.0                  0         32768 i

* 2.2.2.0/24       13.1.1.3                               0 345 2 i

*                 12.1.1.2                 0             0 2 i

*>                10.1.1.4                           65535 345 2 i

*> 3.3.3.0/24       13.1.1.3                 0             0 345 i

*                 12.1.1.2                               0 2 345 i

*> 4.4.4.0/24       13.1.1.3                               0 345 i

*                 12.1.1.2                               0 2 345 i

*> 5.5.5.0/24       13.1.1.3                               0 345 i

*                 12.1.1.2                               0 2 345 i


可以看到,不僅原來默認的Weight屬性值發生了變化,並且也改變了2.2.2.0這個路由的下一跳爲10.1.1.4,也就是R4了,成功地實現了用Weight屬性來修改BGP的選路。再來看一下R1的路由表:


R1#show ip route bgp

2.0.0.0/24 is subnetted, 1subnets

B       2.2.2.0 [20/0] via10.1.1.4, 00:34:34

   3.0.0.0/24 is subnetted, 1 subnets

B       3.3.3.0 [20/0] via 13.1.1.3, 00:34:34

   4.0.0.0/24 is subnetted, 1 subnets

B      4.4.4.0 [20/0] via 13.1.1.3, 00:34:34

   5.0.0.0/24 is subnetted, 1 subnets

B      5.5.5.0 [20/0] via 13.1.1.3, 00:34:34




Local_Pref屬性的用法和配置方法


保持基本配置不變,我們分別到R1R2R3show ip bgp查看它們的BGP路由表表:


R3


R3#show ip bgp

BGP table version is 9, local router ID is 3.3.3.3

Status codes: s suppressed, d damped, h history, * valid, > best,i - internal,

             r RIB-failure, SStale

Origin codes: i - IGP, e - EGP, ? - incomplete


  Network        Next Hop            Metric LocPrf Weight Path

* i1.1.1.0/24       10.1.1.1                 0    100     0 1 i

*>               13.1.1.1                 0             0 1 i

*>i2.2.2.0/24      24.1.1.2                 0    100     0 2 i

*> 3.3.3.0/24      0.0.0.0                  0         32768 i

*>i4.4.4.0/24      45.1.1.4                 0    100     0 i

*>i5.5.5.0/24      35.1.1.5                 0    100     0 i


R4


R4#show ip bgp

BGP table version is 41, local router ID is 4.4.4.4

Status codes: s suppressed, d damped, h history, * valid, > best,i - internal,

             r RIB-failure, SStale

Origin codes: i - IGP, e - EGP, ? - incomplete


  Network        Next Hop            Metric LocPrf Weight Path

* i1.1.1.0/24       13.1.1.1                 0    100     0 1 i

*                24.1.1.2                               0 2 1 i

*>               10.1.1.1                 0             0 1 i

*> 2.2.2.0/24      24.1.1.2                 0             0 2 i

*>i3.3.3.0/24      35.1.1.3                 0    100     0 i

*> 4.4.4.0/24      0.0.0.0                  0         32768 i

*>i5.5.5.0/24      45.1.1.5                 0    100     0 i


R5


R5#show ip bgp

BGP table version is 21, local router ID is 5.5.5.5

Status codes: s suppressed, d damped, h history, * valid, > best,i - internal,

             r RIB-failure, SStale

Origin codes: i - IGP, e - EGP, ? - incomplete


  Network         NextHop            Metric LocPrf Weight Path

*>i1.1.1.0/24       10.1.1.1                0    100     0 1 i

* i                13.1.1.1                 0    100     0 1 i

*>i2.2.2.0/24      24.1.1.2                 0    100     0 2 i

*>i3.3.3.0/24      35.1.1.3                 0    100     0 i

*>i4.4.4.0/24      45.1.1.4                 0    100     0 i

*> 5.5.5.0/24      0.0.0.0                  0         32768 i


下面我們通過對R3的配置,設置從R1學到的1.1.1.0的本地優先級(Localpref)設置爲200,由於缺省的值爲100AS345中所有的路由器都會選擇R3到達1.1.1.0


實驗配置:

R3(config)#access-list 10 permit 1.1.1.0 0.0.0.255

R3(config)#route-map local_pref permit 10

R3(config-route-map)#match ip address 10

R3(config-route-map)#set local-preference 200

R3(config-route-map)#exit

R3(config)#router bgp 345

R3(config-router)#neighbor 13.1.1.1 route-map local_pref in

R3(config-router)#end


當配置完成後,我們分別在3臺路由器上clear ip bgp * soft,然後在分別看它們的BGP表:


R3


R3#show ip bgp        

BGP table version is 10, local router ID is3.3.3.3

Status codes: s suppressed, d damped, hhistory, * valid, > best, i - internal,

             r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? -incomplete


 Network         Next Hop            Metric LocPrf Weight Path

*> 1.1.1.0/24      13.1.1.1                 0    200     0 1 i

*>i2.2.2.0/24       24.1.1.2                 0    100     0 2 i

*> 3.3.3.0/24       0.0.0.0                  0         32768 i

*>i4.4.4.0/24       45.1.1.4                 0    100     0 i

*>i5.5.5.0/24       35.1.1.5                 0    100     0 i


R4


R4#show ip bgp

BGP table version is 42, local router ID is4.4.4.4

Status codes: s suppressed, d damped, hhistory, * valid, > best, i - internal,

             r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? -incomplete


 Network         Next Hop            Metric LocPrf Weight Path

*>i1.1.1.0/24      13.1.1.1                 0    200     0 1 i

*                 24.1.1.2                               0 2 1 i

*                 10.1.1.1                 0             0 1 i

*> 2.2.2.0/24       24.1.1.2                 0             0 2 i

*>i3.3.3.0/24       35.1.1.3                 0    100     0 i

*> 4.4.4.0/24       0.0.0.0                  0         32768 i

*>i5.5.5.0/24       45.1.1.5                 0    100     0 i


R5


R5#show ip bgp

BGP table version is 22, local router ID is5.5.5.5

Status codes: s suppressed, d damped, hhistory, * valid, > best, i - internal,

             r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? -incomplete


 Network         Next Hop            Metric LocPrf Weight Path

*>i1.1.1.0/24      13.1.1.1                 0    200     0 1 i

*>i2.2.2.0/24       24.1.1.2                 0    100     0 2 i

*>i3.3.3.0/24       35.1.1.3                 0    100     0 i

*>i4.4.4.0/24       45.1.1.4                 0    100     0 i

*> 5.5.5.0/24       0.0.0.0                  0         32768 i


因爲Local_Pref屬性作用範圍是所在的本AS(這裏爲AS 345),可以看到,不僅R3原來默認的LocPrf屬性值發生了變化,也改變了R4R5的默認LocPrf屬性值,並且R4R51.1.1.0這個路由的下一跳變爲13.1.1.1,也就是R3,成功地實現了用LocPrf屬性來修改BGP的選路。

這裏需要注意的是,R3在修改Local_Pref屬性前,是從R1R4學習到1.1.1.0網段的,而修改Local_Pref屬性後,R3只從R1學習到1.1.1.0網段。這是因爲在修改前,R4是從R1學得1.1.1.0網段,而修改Local_Pref屬性後,根據選路原則,R4將從R3傳來的1.1.1.0網段的路由條目做爲最優路徑,所以R4不會再將自己的次優路徑下一跳爲10.1.1.1的條目傳遞給R3。(R5同理)




AS_Path屬性的用法和配置方法


保持基本配置不變,我們用show ip bgp查看R1R2BGP表:

R1


R1#show ip bgp

BGP table version is 10, local router ID is1.1.1.1

Status codes: s suppressed, d damped, hhistory, * valid, > best, i - internal,

             r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? -incomplete


 Network         Next Hop            Metric LocPrf Weight Path

*> 1.1.1.0/24      0.0.0.0                  0         32768 i

* 2.2.2.0/24       13.1.1.3                               0 345 2 i

*                 12.1.1.2                 0             0 2 i

*>                10.1.1.4                           65535 345 2 i

*> 3.3.3.0/24       13.1.1.3                 0             0 345 i

*                 12.1.1.2                               0 2 345 i

*> 4.4.4.0/24       13.1.1.3                               0 345 i

*                 12.1.1.2                               0 2 345 i

*> 5.5.5.0/24       13.1.1.3                               0 345 i

*                 12.1.1.2                               0 2 345 i


R2


R2#show ip bgp

BGP table version is 9, local router ID is2.2.2.2

Status codes: s suppressed, d damped, hhistory, * valid, > best, i - internal,

             r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? -incomplete


 Network         Next Hop            Metric LocPrf Weight Path

*  1.1.1.0/24       24.1.1.4                               0 345 1 i

*>               12.1.1.1                 0             0 1 i

*> 2.2.2.0/24        0.0.0.0                  0         32768 i

* 3.3.3.0/24       12.1.1.1                               0 1 345 i

*>                24.1.1.4                               0 345 i

* 4.4.4.0/24       12.1.1.1                               0 1 345 i

*>                24.1.1.4                 0             0 345 i

* 5.5.5.0/24       12.1.1.1                               0 1 345 i

*>                24.1.1.4                               0 345 i


根據選路原則,BGP總是優先選擇具有最短AS路徑的路由。接下來我們將配置R1,將1.1.1.0通告給R2之前預先添加兩個額外的AS路徑到1.0.0.0上(AS100AS200)。


實驗配置:

R1(config)#access-list 10 permit 1.1.1.00.0.0.255

R1(config)#route-map aspath 10

R1(config-route-map)#match ip address 10

R1(config-route-map)#set as-path prepend100 200

R1(config-route-map)#exit

R1(config)#router bgp 1

R1(config-router)#neighbor 12.1.1.2route-map aspath out

R1(config-router)#exit


當配置完成後,我們分別在R1R2路由器上clear ip bgp * soft,然後在分別看它們的BGP表:


R1


R1#show ip bgp

BGP table version is 10, local router ID is1.1.1.1

Status codes: s suppressed, d damped, hhistory, * valid, > best, i - internal,

             r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? -incomplete


 Network         Next Hop            Metric LocPrf Weight Path

*> 1.1.1.0/24       0.0.0.0                  0         32768 i

* 2.2.2.0/24       13.1.1.3                               0 345 2 i

*                 12.1.1.2                 0             0 2 i

*>                10.1.1.4                           65535 345 2 i

*> 3.3.3.0/24       13.1.1.3                 0             0 345 i

*                 12.1.1.2                               0 2 345 i

*> 4.4.4.0/24       13.1.1.3                               0 345 i

*                 12.1.1.2                               0 2 345 i

*> 5.5.5.0/24       13.1.1.3                               0 345 i

*                 12.1.1.2                               0 2 345 i


R2


R2#show ip bgp

BGP table version is 10, local router ID is2.2.2.2

Status codes: s suppressed, d damped, hhistory, * valid, > best, i - internal,

             r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? -incomplete


 Network         Next Hop            Metric LocPrf Weight Path

*> 1.1.1.0/24      24.1.1.4                              0 345 1 i

*                 12.1.1.1                 0             0 1 100 200 i

*> 2.2.2.0/24       0.0.0.0                  0         32768 i

*> 3.3.3.0/24       24.1.1.4                               0 345 i

*> 4.4.4.0/24       24.1.1.4                 0             0 345 i

*> 5.5.5.0/24       24.1.1.4                               0 345 i


我們發現R2BGP表發生了變化,在下一跳爲12.1.1.1的條目中,Path屬性值增加了2跳(100 200),所以根據選路原則,R2最終將從R4學來的下一跳爲24.1.1.4的路由條目做爲最優路徑。

注意: R1BGP表在做了路由策略前後沒有任何變化,因爲對R1做的路由策略是out方向,所以隻影響出站的路由條目。

反過來,我們也可以在R2in方向做路由策略修改AS_Path屬性值。首先,清除之前對R1所做的配置,使其保持基本配置,接下來在R2上進行配置,配置如下:


實驗配置:

R2(config)#access-list 10 permit 1.1.1.00.0.0.255

R2(config)#route-map aspath 10

R2(config-route-map)#match ip address 10

R2(config-route-map)#set as-path prepend100 200

R2(config-route-map)#exit

R2(config)#router bgp 2

R2(config-router)#neighbor 12.1.1.1route-map aspath in

R2(config-router)#end


當配置完成後,我們分別在R2路由器上clear ip bgp * soft,然後在分別看它的BGP表:


R2#show ip bgp

BGP table version is 10, local router ID is2.2.2.2

Status codes: s suppressed, d damped, hhistory, * valid, > best, i - internal,

             r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? -incomplete


 Network         Next Hop            Metric LocPrf Weight Path

*> 1.1.1.0/24      24.1.1.4                              0 345 1 i

*                 12.1.1.1                 0             0 100 200 1 i

*> 2.2.2.0/24       0.0.0.0                  0         32768 i

*> 3.3.3.0/24       24.1.1.4                               0 345 i

*> 4.4.4.0/24       24.1.1.4                 0             0 345 i

*> 5.5.5.0/24       24.1.1.4                               0 345 i


這時我們發現,R2收到的下一跳爲12.1.1.1的條目依然爲2跳,與out方向有所不同的是,我們所增加的AS100AS200AS1之前。

總結:修改AS_Path參數,對於outin方向的AS_Path操作產生的效果是不同的。




MED屬性的作用和配置方法


保持基本的BGP配置不變,然後在R1show ip bgp查看一下BGP的路由表:


R1#show ip bgp

BGP table version is 6, local router ID is1.1.1.1

Status codes: s suppressed, d damped, hhistory, * valid, > best, i - internal,

             r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? -incomplete


 Network         NextHop            Metric LocPrf Weight Path

*> 1.1.1.0/24       0.0.0.0                  0         32768 i

* 2.2.2.0/24       13.1.1.3                               0 345 2 i

*>                12.1.1.2                 0             0 2 i

*                10.1.1.4                               0 345 2 i

* 3.3.3.0/24       13.1.1.3                 0             0 345 i

*                 12.1.1.2                               0 2 345 i

*>               10.1.1.4                              0 345 i

* 4.4.4.0/24       13.1.1.3                               0 345 i

*                 12.1.1.2                               0 2 345 i

*>               10.1.1.4                 0             0 345 i

* 5.5.5.0/24       13.1.1.3                               0 345 i

*                 12.1.1.2                               0 2 345 i

*>                10.1.1.4                               0 345 i


可以看到到3.3.3.04.4.4.0的路由都是從10.1.1.4學到的,也就是從R4學到的,默認的Metric0,從拓撲圖中可以看到,從R4學到下一跳爲10.1.1.43.3.3.0網段是一條次優路徑,我們希望R1R3直接學習到3.3.3.0網段。

下面我們來配置BGPMetric屬性來把3.3.3.0的流量分擔到R3上:


實驗配置:


R3


R3(config)#access-list 10 permit 3.3.3.00.0.0.255

R3(config)#access-list 20 permit 4.4.4.00.0.0.255

R3(config)#route-map med permit 10

R3(config-route-map)#match ip address 10

R3(config-route-map)#set metric 10

R3(config-route-map)#exit

R3(config)#route-map med permit 20

R3(config-route-map)#match ip address 20

R3(config-route-map)#set metric 20

R3(config-route-map)#exit

R3(config)#router bgp 345

R3(config-router)#neighbor 13.1.1.1route-map med out

R3(config-router)#end


R4


R4(config)#access-list 10 permit 3.3.3.00.0.0.255

R4(config)#access-list 20 permit 4.4.4.00.0.0.255

R4(config)#route-map med permit 10

R4(config-route-map)#match ip address 10

R4(config-route-map)#set metric 20

R4(config-route-map)#exit

R4(config)#route-map med permit 20

R4(config-route-map)#match ip address 20

R4(config-route-map)#set metric 10

R4(config-route-map)#exit

R4(config)#router bgp 345

R4(config-router)#neighbor 10.1.1.1route-map med out

R4(config-router)#end


配置好後,在R1clear ip bgp * soft軟重啓一下BGP的進程,然後再show ip bgp查看BGP的路由表:


R1#show ip bgp

BGP table version is 9, local router ID is1.1.1.1

Status codes: s suppressed, d damped, hhistory, * valid, > best, i - internal,

             r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? -incomplete


 Network         Next Hop            Metric LocPrf Weight Path

*> 1.1.1.0/24       0.0.0.0                  0         32768 i

*> 2.2.2.0/24       12.1.1.2                 0             0 2 i

*> 3.3.3.0/24       13.1.1.3                10             0 345 i

*                 12.1.1.2                               0 2 345 i

*                 10.1.1.4                20             0 345 i

*  4.4.4.0/24       13.1.1.3                20             0 345 i

*                12.1.1.2                               0 2 345 i

*>               10.1.1.4                10             0 345 i

*> 5.5.5.0/24       12.1.1.2                               0 2 345 i


這時我們發現Metric屬性值變了,從13.1.1.3學到3.3.3.0Metric變爲10,而4.4.4.0Metric變爲20,同樣,從10.1.1.4學到的3.3.3.0Metric變成了204.4.4.0Metric變成了10,這樣的話R1上學到的3.3.3.0的路由就是通過R3學到的,4.4.4.0學到的路由是從R4學到的,這樣就有效的分擔了R4上的流量。

再來看一下R1的路由表:


R1#show ip route bgp

   2.0.0.0/24 is subnetted, 1 subnets

B      2.2.2.0 [20/0] via 12.1.1.2, 00:30:13

   3.0.0.0/24 is subnetted, 1 subnets

B       3.3.3.0 [20/10] via13.1.1.3, 00:19:05

   4.0.0.0/24 is subnetted, 1 subnets

B       4.4.4.0 [20/10] via10.1.1.4, 00:19:05

   5.0.0.0/24 is subnetted, 1 subnets

B      5.5.5.0 [20/0] via 12.1.1.2, 00:19:05


總結:配置MED屬性值後,會影響另一個AS的出站選路。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章