簡介
本文檔介紹如何使用BGP社群值控制上游提供商網路中的路由策略。
必要條件
需求
本文檔要求您瞭解邊界網關協定(BGP)路由協定及其操作。
採用元件
本文件所述內容不限於特定軟體和硬體版本。但是本檔案中的資訊是根據以下軟體版本而定:
本文中的資訊是根據特定實驗室環境內的裝置所建立。文中使用到的所有裝置皆從已清除(預設)的組態來啟動。如果您的網路運作中,請確保您瞭解任何指令可能造成的影響。
背景資訊
儘管社群本身不會更改BGP最佳路徑過程,但社群可以用作標誌以標籤一組路由。然後,上游服務提供商路由器可以使用這些標誌在其網路中應用特定的路由策略(例如,本地優先順序)。
提供商會在提供商網路內的可配置社群值和相應的本地首選項值之間進行對映。您可以具有需要修改提供商網路集中的LOCAL_PREF的特定策略及其路由更新中的相應社群值。
團體是一組字首,它們共用一些公共屬性,可以使用BGP團體屬性進行配置。BGP社群屬性是長度可變的可選傳遞屬性。屬性包含一組四個八位組值,這些值指定了一個團體。社群屬性值在前兩個八位元中以自治系統(AS)編號編碼,其他兩個八位元則由AS定義。一個字首可以有多個社群屬性。BGP發言人看到字首中有多個社群屬性時,可以基於其中一個、部分或全部屬性採取行動。在路由器將屬性傳遞到其他對等體之前,路由器可以選擇增加或修改社群屬性。要瞭解有關社群屬性的詳細資訊,請參閱BGP案例分析。
本地優先順序屬性指示了AS首選哪條路徑到達特定網路。當有多條路徑通往同一個目的地時,會選擇具有更高優先順序的路徑(本機優先順序屬性的預設值為100)。有關詳細資訊,請參閱案例分析。
慣例
如需文件慣例的詳細資訊,請參閱思科技術提示慣例。
配置和控制路由策略
注意:要查詢關於用於本文的命令的其他資訊,請使用命令查詢工具。
為簡化起見,假定在上游服務提供商(AS 100)和您的裝置(AS 30)之間建立社群屬性和本地首選項屬性對映。
本地優先使用程度 |
社群價值觀 |
130 |
100:300 |
125 |
100:250 |
如果通告字首的社群屬性等於100:300,則如果社群屬性等於100:250,上游服務提供商將這些路由的本地優先順序設定為130和125。
如果更改向服務提供商通告的字首的社群值,則此操作可讓您控制服務提供商網路中的路由策略。
在網路圖中,AS 30希望將此路由策略與社群屬性一起使用。
為實現此路由策略,R3會以下列方式宣佈其字首:
到R1:
- 10.0.10.0/24,社群屬性為100:300
- 10.1.0.0/24,社群屬性為100:250
到R2:
一旦BGP鄰居R1和R2收到來自R3的字首,R1和R2就會根據社群與本地優先順序屬性之間的對映應用配置的策略(如上表所示),從而實現您指定的路由策略(AS 30)。R1在BGP表中安裝字首。
-
10.0.10.0/24,本地優先順序為130
-
10.1.0.0/24,本地優先順序為125
R2在其BGP表中安裝字首:
-
10.0.10.0/24,本地優先順序為125
-
10.1.0.0/24,本地優先順序為130
由於BGP路徑選擇標準中優先使用較高的本地優先順序,因此將本地優先順序為130(130大於125)的路徑選為AS 100內的最佳路徑,並安裝在R1和R2的IP路由表中。有關BGP路徑選擇標準的詳細資訊,請參閱BGP最佳路徑選擇演算法。
網路圖表
BGP網路
組態
本檔案使用下列組態:
R3
hostname R3
!
interface Loopback0
ip address 10.0.10.0 255.255.255.0
!
interface Ethernet0/0
ip address 10.1.0.0 255.255.255.1
!
interface Serial8/0
ip address 10.10.13.3 255.255.255.0
!--- Interface connected to R1
!
interface Serial9/0
ip address 10.10.23.3 255.255.255.0
!--- Interface connected to R2
!
router bgp 30
network 10.0.10.0 mask 255.255.255.0
network 10.1.0.0 mask 255.255.255.1
!--- Network commands announce prefix 10.0.10.0/24 and 10.1.0.0/24.
neighbor 10.10.13.1 remote-as 100
!--- Establishes peering with R1
neighbor 10.10.13.1 send-community
!--- Without this command, the community attributes are not sent to the neighbor
neighbor 10.10.13.1 route-map Peer-R1 out
!--- Configures outbound policy as defined by route-map "Peer-R1" when peering with R1
neighbor 10.10.23.2 remote-as 100
!--- Establishes peering with R2
neighbor 10.10.23.2 send-community
!--- Configures to send community attribute to R2
neighbor 10.10.23.2 route-map Peer-R2 out
!--- Configures outbound policy as defined by
!--- route-map "Peer-R2" when peering with R2.
no auto-summary
!
ip classless
ip bgp-community new-format
!--- Allows you to configure the BGP community
!--- attribute in AA:NN format.
!
access-list 101 permit ip host 10.0.10.0 host 255.255.255.0
access-list 102 permit ip host 10.1.0.0 host 255.255.255.1
!
!
route-map Peer-R1 permit 10
match ip address 101
set community 100:300
!--- Sets community 100:300 for routes matching access-list 101
!
route-map Peer-R1 permit 20
match ip address 102
set community 100:250
!--- Sets community 100:250 for routes matching access-list 102
!
route-map Peer-R2 permit 10
match ip address 101
set community 100:250
!--- Sets community 100:250 for routes matching access-list 101
!
route-map Peer-R2 permit 20
match ip address 102
set community 100:300
!--- Sets community 100:300 for routes matching access-list 102
!
end
R1
hostname R1
!
interface Loopback0
ip address 10.200.10.1 255.255.255.0
!
interface Serial8/0
ip address 10.10.13.1 255.255.255.1
!--- Connected to R3
!
interface Serial10/0
ip address 10.10.12.1 255.255.255.0
!--- Connected to R2
!
router bgp 100
no synchronization
bgp log-neighbor-changes
neighbor 10.10.12.2 remote-as 100
!--- Establishes peering with R2
neighbor 10.10.12.2 next-hop-self
neighbor 10.10.13.3 remote-as 30
!--- Establishes peering with R3
neighbor 10.10.13.3 route-map Peer-R3 in
!--- Configures the inbound policy as defined by route-map "Peer-R3" when peering with R3.
no auto-summary
!
ip bgp-community new-format
!--- Allows you to configure the BGP community attribute in AA:NN format.
ip community-list 1 permit 100:300
ip community-list 2 permit 100:250
!--- Defines community list 1 and 2.
!
route-map Peer-R3 permit 10
match community 1
set local-preference 130
!--- Sets local preference 130 for all routes matching community list 1.
!
route-map Peer-R3 permit 20
match community 2
set local-preference 125
!--- Sets local preference 125 for all routes matching community list 2.
!
route-map Peer-R3 permit 30
!--- Without this permit 30 statement, updates that do not match the permit 10 or permit 20 statements are dropped.
!
end
R2
hostname R2
!
interface Loopback0
ip address 10.0.10.0 255.255.255.0
!
interface Serial9/0
ip address 10.10.23.2 255.255.255.1
!--- Connected to R3
!
interface Serial10/0
ip address 10.10.12.2 255.255.255.0
!--- Connected to R1
!
router bgp 100
no synchronization
bgp log-neighbor-changes
neighbor 10.10.12.1 remote-as 100
!--- Establishes iBGP peering with R1
neighbor 10.10.12.1 next-hop-self
neighbor 10.10.23.3 remote-as 30
!--- Establishes peering with R3
neighbor 10.10.23.3 route-map Peer-R3 in
!--- Configures inbound policy as defined by route-map "Peer-R3" when peering with R3.
no auto-summary
!
ip bgp-community new-format
!--- Allows you to configure the BGP community attribute in AA:NN format.
!
ip community-list 1 permit 100:300
ip community-list 2 permit 100:250
!--- Defines community list 1 and 2.
!
route-map Peer-R3 permit 10
match community 1
set local-preference 130
!--- Sets local preference 130 for all routes matching community list 1.
!
route-map Peer-R3 permit 20
match community 2
set local-preference 125
!--- Sets local preference 125 for all routes matching community list 2.
!
route-map Peer-R3 permit 30
!--- Without this permit 30 statement, updates that do not match the permit 10 or permit 20 statements are dropped.
!
end
驗證
R1將接收社群屬性為100:300和100:250的字首10.0.10.0/24和10.1.0.0/24,如下一條 show ip bgp 命令輸出結果所示。
注意:根據配置的策略,將這些路由安裝到BGP表中後,社群為100:300的字首將被分配本地優先順序130,社群為100:250的字首將被分配本地優先順序125。
R1#show ip bgp 10.0.10.0 BGP routing table entry for 10.0.10.0/24, version 2 Paths: (1 available, best #1, table Default-IP-Routing-Table) Advertised to non peer-group peers: 10.10.12.2 30 10.10.13.3 from 10.10.13.3 (10.0.10.0) Origin IGP, metric 0, localpref 130, valid, external, best Community: 100:300 !--- Prefix 10.0.10.0/24 with community 100:300 received from 10.10.13.3 (R3) is assigned local preference 130.
R1#show ip bgp 10.1.0.0 BGP routing table entry for 10.1.0.0/24, version 4 Paths: (2 available, best #1, table Default-IP-Routing-Table) Advertised to non peer-group peers: 10.10.13.3 30 10.10.12.2 from 10.10.12.2 (10.1.0.0) Origin IGP, metric 0, localpref 130, valid, internal, best
!--- Received prefix 10.1.0.0/24 over iBGP from 10.10.12.2 (R2) with local preference 130
30 10.10.13.3 from 10.10.13.3 (198.51.100.1) Origin IGP, metric 0, localpref 125, valid, external Community: 100:250 !--- Prefix 10.1.0.0/24 with community 100:250 received from 10.10.13.3 (R3) is assigned local preference 125.
R1#show ip bgp BGP table version is 4, local router ID is 10.200.10.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal Origin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path *> 10.0.10.0/24 10.10.13.3 0 130 0 30 i *>i 10.1.0.0/24 10.10.12.2 0 130 0 30 i * 10.10.13.3 0 125 0 30 i
R1上的 show ip bgp 命令將確認在R1上選擇的最佳路徑的本地優先順序(LoclPrf) = 130。同樣,R2也會接收社群屬性為100:250和100:300的字首10.0.10.0/24和10.1.0.0/24,如以下 show ip bgp 命令輸出中的粗體所示:
注意:根據配置的策略,將這些路由安裝到BGP表中後,社群為100:300的字首將分配本地優先順序130,社群為100:250的字首將分配本地優先順序125。
R2#show ip bgp 10.0.10.0 BGP routing table entry for 10.0.10.0/24, version 2 Paths: (2 available, best #2, table Default-IP-Routing-Table) Advertised to non peer-group peers: 10.10.23.3 30 10.10.23.3 from 10.10.23.3 (10.0.10.0) Origin IGP, metric 0, localpref 125, valid, external Community: 100:250 !--- Prefix 10.0.10.0/24 with community 100:250 received from 10.10.23.3 (R3) is assigned local preference 125
30 10.10.12.1 from 10.10.12.1 (10.200.10.1) Origin IGP, metric 0, localpref 130, valid, internal, best !--- Received prefix 10.0.10.0/24 over iBGP from 10.10.12.1 (R1) with local preference 130
R2#show ip bgp 10.1.0.0 BGP routing table entry for 10.1.0.0/24, version 3 Paths: (1 available, best #1, table Default-IP-Routing-Table) Advertised to non peer-group peers: 10.10.12.1 30 10.10.23.3 from 10.10.23.3 (10.1.0.0) Origin IGP, metric 0, localpref 130, valid, external, best Community: 100:300 !--- Prefix 10.1.0.0/24 with community 100:300 received from 10.10.23.3 (R3) is assigned local preference 130.
R2#show ip bgp BGP table version is 3, local router ID is 192.168.50.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal Origin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path * 10.0.10.0/24 10.10.23.3 0 125 0 30 i *>i 10.10.12.1 0 130 0 30 i *> 10.1.0.0/24 10.10.23.3 0 130 0 30 i
R2上的此 show ip bgp 命令輸出將確認在R2上選擇的最佳路徑的本地優先順序(loclPrf) = 130。 到字首10.0.10.0/24的IP路由優先於R1-R3鏈路從AS 100退出,指向AS 30。R1和R2上的 show ip route 命令可確認此首選項。
R1#show ip route 10.0.10.0 Routing entry for 10.0.10.0/24 Known via "bgp 100", distance 20, metric 0 Tag 30, type external Last update from 10.10.13.3 3d21h ago Routing Descriptor Blocks: * 10.10.13.3, from 10.10.13.3, 3d21h ago Route metric is 0, traffic share count is 1 AS Hops 1 !--- On R1, the IP route to prefix 10.0.10.0/24 points to next hop 10.10.13.3 which is R3 serial 8/0 interface on the R1-R3 link.
R2#show ip route 10.1.0.0 Routing entry for 10.1.0.0/24 Known via "bgp 100", distance 200, metric 0 Tag 30, type internal Last update from 10.10.12.1 3d21h ago Routing Descriptor Blocks: * 10.10.12.1, from 10.10.12.1, 3d21h ago Route metric is 0, traffic share count is 1 AS Hops 1 !--- On R2, IP route to prefix 10.1.0.0/24 points to next hop R1 (10.10.12.1) on its iBGP link !--- Thus traffic to network 10.1.0.0/24 from R2 exits through R2-R1 and then R1-R3 link from AS 100 towards AS 30
到字首10.1.0.0/24的IP路由優先於R2-R3鏈路從AS 100退出,指向AS 30。R1和R2上的 show ip route 命令可確認此首選項。
R2#show ip route 10.1.0.0 Routing entry for 10.1.0.0/24 Known via "bgp 100", distance 20, metric 0 Tag 30, type external Last update from 10.10.23.3 3d22h ago Routing Descriptor Blocks: * 10.10.23.3, from 10.10.23.3, 3d22h ago Route metric is 0, traffic share count is 1 AS Hops 1 !--- On R2, IP route to prefix 10.1.0.0/24 points to next hop 10.10.23.3 which is R3 serial 9/0 interface on R2-R3 link.
R1#show ip route 10.1.0.0 Routing entry for 10.1.0.0/24 Known via "bgp 100", distance 200, metric 0 Tag 30, type internal Last update from 10.10.12.2 3d22h ago Routing Descriptor Blocks: * 10.10.12.2, from 10.10.12.2, 3d22h ago Route metric is 0, traffic share count is 1 AS Hops 1 !--- On R1, IP route to prefix 10.1.0.0/24 points to next hop R2 (10.10.12.2) on its iBGP link. !--- Thus traffic to network 10.1.0.0/24 from R1 exits through R1-R2 and then R2-R3 link from AS 100 towards AS 30.
如果一條鏈路(例如R1-R3鏈路)發生故障,則所有流量都必須跟蹤R2-R3鏈路。如果關閉R1-R3之間的鏈路,則可以模擬此流量。
R1#configure terminal Enter configuration commands, one per line. End with CNTL/Z. R1(config)#interface serial8/0 R1(config-if)#shut R1(config-if)# 3d22h: %BGP-5-ADJCHANGE: neighbor 10.10.13.3 Down Interface flap 3d22h: %LINK-5-CHANGED: Interface Serial8/0, changed state to administratively down 3d22h: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial8/0, changed state to down
注意R1和R2上字首10.0.10.0/24和10.1.0.0/24的IP路由表。使用R2-R3鏈路退出AS 100。
R1#show ip route 10.0.10.0 Routing entry for 10.0.10.0/24 Known via "bgp 100", distance 200, metric 0 Tag 30, type internal Last update from 10.10.12.2 00:01:47 ago Routing Descriptor Blocks: * 10.10.12.2, from 10.10.12.2, 00:01:47 ago Route metric is 0, traffic share count is 1 AS Hops 1
R1#show ip route 10.1.0.0 Routing entry for 10.1.0.0/24 Known via "bgp 100", distance 200, metric 0 Tag 30, type internal Last update from 10.10.12.2 3d22h ago Routing Descriptor Blocks: * 10.10.12.2, from 10.10.12.2, 3d22h ago Route metric is 0, traffic share count is 1 AS Hops 1
此 show 命令輸出顯示到字首10.0.10.0/24和10.1.0.0/24的路由指向下一跳10.10.12.2 (R2),這符合預期。現在,檢視R2上的IP路由表,檢查字首10.0.10.0/24和10.1.0.0/24的下一跳。下一跳必須為已配置策略的R3,這樣才能成功工作。
R2#show ip route 10.0.10.0 Routing entry for 10.0.10.0/24 Known via "bgp 100", distance 20, metric 0 Tag 30, type external Last update from 10.10.23.3 00:04:10 ago Routing Descriptor Blocks: * 10.10.23.3, from 10.10.23.3, 00:04:10 ago Route metric is 0, traffic share count is 1 AS Hops 1
R2#show ip route 10.1.0.0 Routing entry for 10.1.0.0/24 Known via "bgp 100", distance 20, metric 0 Tag 30, type external Last update from 10.10.23.3 3d22h ago Routing Descriptor Blocks: * 10.10.23.3, from 10.10.23.3, 3d22h ago Route metric is 0, traffic share count is 1 AS Hops 1
下一跳10.10.23.3是R2-R3鏈路上的R3 Serial 9/0介面。這可以確認配置的策略按預期工作。
相關資訊