BGP - 不同 AS 間運行的協議


在之前介紹的網絡場景中,ERGRP,OPSF,RIP 等都是運行在單獨一個 AS(自治系統之間)。這些協議統稱為 IGP - 內部網關協議 ,目的主要是為自治系統內發現鄰居和計算路由,從而找到合適的路徑。

而 BGP 這樣的協議,運行在不同的 AS 間(比如聯通和電信間的通信)。目的是為了傳遞路由和控制路由。這類協議統稱為 EGP - 外部網關協議。

BGP 特點

  • BGP 運行在不同 AS 間,端口為 179.
  • 是路徑矢量路由協議
  • 增量更新,只發送更新的路由,原因在於 BGP 支持海量的路由傳輸(幾十,上百萬路由)
  • 無環路
  • 路由策略豐富,對路由進行過濾和選擇
  • 基於 TLV 結構,易於擴展
  • 收斂較慢,由於基於 TCP 可靠傳輸,而且數量較大。
  • BGP 管理值 AD 分為兩種:
    • 20:通過 EGP 鄰居學到的路由 AD 為 20
    • 200:通過 IBGP 學習到的路由 AD 為 200 (一般在 AS 內都有 IGP - OSPF,EIGRP 等,而 IBGP 收斂很慢所以 AD 值較大)

關於路徑矢量路由協議:

在這里,將 AS 65050 的路由傳遞給 AS 65010 時:

其中經過 65050->65030->65020 三個節點,並知道節點的方向,這就是基於路徑矢量的路由協議。

BGP 數據結構

BGP 鄰居表:建立的 Peer(對等體) 信息。

BGP 表:通過 BGP 協議學習到的路由(所有路由)。

路由表:實際轉發的路由表(最優路由)。

BGP 協議術語

AS:自治系統,由一個技術管理機構管理,使用統一選錄策略的一些路由器的集合。每一個自治系統都有一個唯一的自治系統編號,像公有 IP 一樣,需要向 IANA 機構申請。同樣也有私有的 AS 編號。

  • 兩字節 AS 編號:0 - 65535,早期。其中 1 - 64511 公有編號,64512 - 65535 私有編號。
  • 四字節 AS 編號:四字節設備兼容兩字節設備。1 - 42.。。

BGP 鄰居種類:

  • IBGP:運行在同一 AS 號的設備。
  • EBGP:運行在不同 AS 號的設備。

BGP 連接鄰居依賴與 TCP,只要 TCP 可達,就可以建立鄰居。不用直連。

Peer:BGP 建立的鄰居,叫對等體 - Peer.

BGP 報文

Open 報文:在 TCP 連接建立后的第一個報文,用於建立鄰居。

Update 報文:用於在 Peer 間交換路由信息。可以發布或者撤銷多條屬性相同的路由信息

BGP 路由信息都會帶有屬性,如果屬性相同。Update 可以同時發布屬性一致的多條路由,在一個 Update 中,如果不一致,則需要在多個 Update 報文傳送。

Keepalive 報文:BGP 周期性向 Peer 發送 Keepalive 報文,默認 60s 發送一次,保留時間 Hold 為 180s.

Notification 報文:當 BGP 檢測到錯誤狀態時,會像 Peer 發送錯誤報文,之后會斷開連接。

Route Refresh 報文:在路由器開啟路由刷新的功能后,如果在 BGP 入口路由器重新配置策略后,該路由器向對端 Peer 發送 Route Refresh 報文,讓對端 Peer 重新發送路由。

新策略之后當接收到路由信息才生效,對已經進入路由表的路由,策略無法生效。

BGP 工作原理

  1. 首先通過 TCP 建立連接,TCP 建立成功后。開始發送 BGP 的 Open 報文,Open 用於建立 peer 關系。協商參數:
    1. BGP 版本
    2. BGP 連接保持時間
    3. Router ID
    4. 認證信息等
  2. BGP 連接建立后,如果有路由需要發送。會發送 Update 報文。
    1. Update 報文中,攜帶 BGP 屬性。用於對端 Peer 選擇路徑。
    2. 在本地路由發生變化時,同樣需要發送 Update 報文。
  3. 在本端和對端 Peer 都無新路由通告時,趨於穩定狀態。此時定時發送 Keepalived 消息以保持 BGP 連接的有效性。、
  4. 當本地 BGP 發生錯誤時,需要發送 Notification 報文給對端。或者本端 Peer 關閉 BGP 時,同樣會發送 Notification 報文。

BGP 路由生成方式

  1. 通過 network 宣告路由,將 IP 路由表已經存在的路由宣告至 BGP 網絡中。

  2. 通過 redistribute 引入 static,直連,外部協議的路由。

BGP 路由傳遞原則

  1. 當存在多條到達同一目的地址的有效路由時,BGP 設備只會將最優路由通告給對端 Peer.

  2. 從 IBGP 對等體獲得的 BGP,只能發給 EBGP 對等體,不發給 IBGP 對等體(BGP 水平分割)。

  3. 從 EBGP 對等體學到的路由可以發給 EBGP,IBGP 對等體。

  4. BGP 與 IGP 同步:在 IBGP 加入路由表並發布給 EBGP 對等體前,會先檢查 IGP 路由表,在 IGP 路由表也存在該路由,才會加入路由表中,並發布給 EBGP 對等體。思科設備默認關閉。見拓展1。簡單來說就是,只有 IGP(EIGRP,OSPF)能學到的路由,才會發布給 EGBP 對等體。

比如 ISP1 和 R1 連接的 Peer 關系屬於 EBGP 的鄰居關系,所以 R1 通過 EBGP 學到的路由,會發給 R3 和 R2 (屬於 IBGP)。

但是,R3 和 R2 不會將從 R1 學到的路由發給 R4. 因為 R3 和 R4,R2 和 R4 之間是 IBGP 的鄰居關系。

假設 IBGP 學到的路由能傳給 IBGP,這樣 R3 會傳給 R4,R4 會傳給 R2,這樣就存在成環的風險。

但是,R1 和 R4 之間可以通過 TCP 建立 IBGP 鄰居關系,R1 可將路由傳給 R4.

BGP 屬性

BGP 屬性分為四類,是一套參數,是對路由的進一步描述,使得 BGP 能夠對路由進行過濾和選擇:

  • 公認必遵屬性:
    • 所以 BGP 路由器必須遵守,必須存在於 Update 報文中。如果缺少該屬性,路由信息就會出錯。
    • 組成:
      • Origin
      • AS Path
      • Next hop
  • 公認任意屬性:
    • 所以 BGP 必須能識別,但可以不存在 Update 報文中。
    • 組成:
      • Local Preference
      • Atomic Aggregate
  • 可選過濾屬性:
    • 在 AS 直接具有可傳遞的屬性
    • BGP 路由器可以不支持該屬性,但仍然會接受該屬性,並傳遞給其他對等體
    • 組成:
      • Aggregator
      • Community
  • 可選非過濾屬性:
    • 如果 BGP 路由器可以不支持該屬性,則不傳遞給其他對等體
    • 組成:
      • MED(其實是 Metric)
      • Originator ID
      • Cluster List

公認必尊

Origin:路由的起源,標記了該路由如何成為 BGP 路由,共有三類生成方式:

  1. 使用 network 命令,注入到 BGP 路由中,標識符為 i, 表示 Origin 屬性為 IGP.
  2. 通過 EGP 學到的路由,注入到 BGP 路由中,標識符 e, 表示 Origin 屬性為 EGP, 現在已經不存在了。
  3. 通過重分布命令,或其他方式,注入到 BGP 路由中,標識符 . 表示 Origin 屬性為 incomplete.

如果通過三種方式學到同一個路由,會選擇最優的。優先級為:IGP > EGP > Incomplete.

AS Path: AS 路徑列表,記錄了某條路由從本地到目的地所有經過的 AS 號列表。如果發現在列表中,有本 AS 號,則不接受該路由,從而避免 AS 路由環路。

  1. 當 BGP 設備通告一條路由時:
    • 如果將該路由通告給其他 AS ,便會將本地 AS 號添加到 AS Path 中,並通過 Update 報文通告給鄰居路由器。(實驗1,R1 產生 1.0,通告給 R2)
    • 如果該路由通告給本地 AS,會在 Update 報文中,添加空的 AS Path,通過 Update 報文通告給鄰居路由器。
  2. 當 BGP 設備傳播從其他 BGP 設備學習到的路由時:
    • 當 BGP 設備將這條路由通告給其他 AS,會將本地 AS 加入到 AS Path 最前端。(比如在實驗1 中,R4 給 R5 傳遞 1.0 的路由)
    • 通告本地 AS 時,不會改變該 AS Path 的值。(比如在實驗1 中,R2 傳給 R4 1.0 的路由)

Next Hop:記錄了路由的下一跳信息。BGP 的下一跳和 IGP 不同,不一定時鄰居設備的 IP 地址。遵循下面原則:

  • BGP 設備將本地始發的路由發給 IBGP Peer 時,會將該路由信息的下一跳屬性設置為本地與對端建立 BGP 鄰居關系的接口地址。
    • 比如在實驗1 中,R2 和 R4 通過 2.2.2.2 接口和 4.4.4.4 接口建立鄰居。R2 上有幾條始發的路由,在傳遞給 R4 后,R4 看到的路由 next hop 為 2.2.2.2.
  • BGP 設備通過 network 或重分布學習的 IGP 路由,發布給 IBGP Peer,下一跳地址為注入 IGP 的下一跳。
    • 比如在實驗 1 中,R3 聲明了一個回環接口 3.3.3.3/32, 然后通過 R3 上 OSPF 協議傳遞給 R2,此時去往 3.0 網絡的 next hop 為 23.1.1.3 - R3 的e0/0 接口。這時 R2 通過重分布命令將 3.0 網絡引入 BGP. 此時 R4 收到的去往 3.0 網絡的下一跳地址仍然為 23.1.1.3.
  • BGP 設備在向 IBGP Peer 發布從 EBGP 學到的路由時,不改變路由的下一跳。
    • 比如在實驗1 中,比如 R2 從 R1 學到 1.0 網絡的路由,在 R2 去往 1.0 網絡下一跳為 12.1.1.1. 在 R4 上該路由下一跳仍然為 12.1.1.1.
  • BGP 設備在向 EBGP Peer 發布路由時,會將該路由的下一跳設置建立建立鄰居的接口地址。
    • 比如在實驗1 中,比如 R2 向 R1 傳遞 5.0 網絡的路由,在 R1 上看,去往 5.0 網絡的下一跳地址為 R2 e0/0 接口 - 12.1.1.2.

公認任意

Local Preference:調整進入的路由,影響出的數據。

  • 僅在本 AS , IBGP 對等體有效,表明路由器 BGP 的優先級,默認為 100,越大越好。用於判斷流量離開 AS 時的最近路徑。

比如在 AS 65040 中,想要訪問 AS 為 65020 的 209 網絡的地址。可以通過 R3 或者 R5 學習到,所以對於 AS 65040 來說,入口有兩個。假設我們想要將去往 209 網絡的流量,全都經過 R2,R1 去往的也走 R2,這時就可以修改該 AS 的 Local Preference 將其設置為 200。

Atomic Aggregate: 當進行路由匯總時,該屬性作為警告信息,警告下游鄰居此路由是一條匯總路由,可能產生環路。

可選過濾

Community 屬性:類似於 IBGP 中的 TAG 屬性,為一些路由設置策略。下面是公共 community 屬性:

  • Internet:默認情況下,所以路由都屬於 Internet 團體,具有此屬性的路由可以被通告給所以 BGP Peer
  • no-advertise: 具有此屬性的路由,不通告給其他任何 Peer 對等體(EBGP + IBGP)
  • local-AS: 具有此屬性的路由在收到后,不能被發到其他 AS, 只允許本地 AS.
  • no-export: 具有此屬性的路由,不通告給其他EBGP Peer 對等體。

Aggregator 屬性:標識發生聚合的節點,攜帶發生聚合節點的 Router-ID 和 AS 號。

可選非過濾

MED 屬性:相當於 IGP Metric,用於判斷流量進入本地 AS 時的最佳路由,注意和 Local Preference 區分,Local Preference 是影響流量出的優先級。

如圖AS 為 65020 中 R1 和上面 AS 為 65010 的 R1 和 R2 建立了鄰居,對於 AS 為 65020 中 R1 來說可以學習到兩條去往 172 網絡的路由,這時通過調整 MED,來控制選擇那條路由,MED 越小越好。所以流量進入時,會選擇 R2.

BGP 選路原則

當到達統一目的地存在多條路由時,BGP 會話會依照如下的策略順序進行路由選擇:

如果此路由的下一跳不可達,忽略此路由。

  1. 優先選擇權重最高的(weight)路由 - Cisco 路由器私有屬性
    • 在本地設備配置,只針對本身有效
  2. 優先選擇本地優先級(local Preference)最高的路由,見 BGP 屬性。
  3. 優選本地生成的路由。
    • 本地生成路由時:手動聚合 > 自動聚合 > network 宣告 > 重分布
  4. 優選 AS 路徑最短的路由
  5. 比較 Origin 屬性,見 BGP 屬性。
    • Origin 優先級:IGP > EGP > Incomplete
  6. 優選 MED 值最低的路由,見 BGP 屬性。
    • 在同一個 AS 才有效,不同 AS 沒有可比性
  7. 優選從 EBGP 學來的路由(EBGP > IBGP)
  8. 優選下一跳到 IGP Metric 小的路由。
  9. 如果配置負載分擔,執行負載分擔
  10. 建立鄰居時間更久的 EBGP 鄰居。
    1. 可能出現同一個鄰居,建立多條線路的情況 ,就是通過兩個接口建立鄰居。所以如果相同,繼續向下比較。
  11. 優選 originator_ID 較小的路由器發布的路由,如果前者,則優選 Router ID 較小的路由器發布的路由
  12. 優選 Cluster_List 最短的路由
  13. 比較對等體 IP 地址,選擇較小的 IP 地址的對等體學來的路由。

針對 weight 說明

如 R1 在去往 209 網絡時,可通過 R4 或者 R2,R3 的路徑。這時可以在 R1 本地進行設置,將去往 R2 的權重調高,從而將流量都走 R2. 注意該屬性是 CISCO 設備的特有屬性。並且該 Weight 值只能影響 R1,在 R1 傳遞路由給其他 Peer 時,不會傳遞該 Weight.

BGP 連接狀態

Idle:BGP 初始狀態,在 Start 事件啟動后,才會正常開始建立連接。

Connect:等待 TCP 建立連接(默認 32 s).

  • TCP 建立成功,標識 TCP Established 狀態,進入 Open Sent 狀態。
  • TCP 建立失敗,進入 Active 狀態。再次嘗試建立 TCP,如果還失敗,就卡在 Active 狀態。超時后回到 Connect 狀態。
  • 如果超時,會一直在 Connect 狀態,發生其他錯誤回到 Idle 狀態。

Open Sent 狀態:發送 BGP open 報文,同時等待接收 對方的 BGP Open 報文。

  • 如果 Open 報文沒問題,進入 Open Confirm 狀態。
  • 否則回到 Idle.

Open Confirm 狀態:

  • 如果收到 Keepalived 報文,進行鄰居維護。
  • 收到 Notification 報文,表示有錯誤,回到 Idle 狀態。

Established 狀態:經過 Open Confirm 驗證后。

BGP 路由匯總

由於 BGP 的數量條目非常巨大,可以達到幾十,上百萬條。所以路由匯總,在 BGP 就格外的重要。

但在 BGP 匯總時,也會有一些問題,比如:

  • 如果聚合前的多個 AS 發布的路由攜帶了一些不同的屬性,那么聚合后,這些屬性怎么辦?
  • 在聚合后,以前的路由相當於匯總成了一條路由,但發布者變成了聚合者,AS_PATH 中不再帶有之前 AS 的標號,這就可能存在出現環路的風險。

匯總方法:

  • 手動配置:配置靜態路由指向 NULL0,然后在 BGP 中通過此匯總路由,如果需要過濾明細,則通過 route-map 過濾。
  • 自動配置:在 BGP 中,進行宣告 aggregate-address 100.1.0.0 255.255.252.0
    • as-set: 還原路由 AS 的屬性,將聚合前的發布者添加到 AS_PATH 列表
    • summary-only:僅僅發布匯總路由

為匯總后的聚合路由設置 community 屬性:

  • 通過 route-map 配置 community 屬性,需要在開啟 as-set 和 send-community 配置后,才會傳遞 community 屬性
  • 如果聚合前路由含有 community 的屬性,在聚合后也會含有 community 屬性

為聚合路由設置 suppress-map:用於限制某些路由發送

  • 如發送匯總后的路由,以及匯總前的一部分路由

為聚合路由設置屬性:通過 attribute-map 修改匯總的路由屬性:

  • 為匯總后的路由添加一些新的 BGP 屬性

為聚合路由設置 advertise-map 屬性:匯總並通告某些路由:

  • 當有 route-map 中的路由存在時,才會出現匯總路由
  • 並且匯總路由只繼承 advertise-map xxx 中路由的屬性,用於移除某些不想要的明細路由的屬性。

舉例來說:

假如有四個網段:
192.168.0.0/24
192.168.1.0/24
192.168.2.0/24
192.168.3.0/24

想匯總成:
192.168.0.0/22

當由於 192.168.4.0/24 網絡不太穩定,所以想實現:在匯總路由時,當 192.168.4.0/24 網段存在時,才會匯總該路由。
而且聚合后的屬性,是 192.168.4.0/24 該網段的屬性。

BGP 路由過濾

BGP 路由過濾工具:

  • Route-map
  • Prefix-list
  • AS-Path access-list:通過正則表達式過濾。由於 BGP 傳輸海量的路由,上面兩種方式配置操作太麻煩。

使用直連物理口建立 BGP 鄰居:

  1. 在 R1 出站,使用 route-map 過濾 100.1.1.0/24, 100.1.2.0/24 的路由。
  2. 在 R3 入站,使用 prefix-list 過濾 10.1.2.0/24,10.1.3.0/24 路由。
  3. 在 R4 入站,使用 as-path access-list 過濾來自 AS 100 的路由。
# route-map 過濾
R1(config)#access-list 1 permit 100.1.1.0 0.0.0.0
R1(config)#access-list 1 permit 100.1.2.0 0.0.0.0
R1(config)#route-map deny_100.map deny 10
R1(config-route-map)#match ip address 1
R1(config-route-map)#exit
R1(config)#route-map deny_100.map permit 20
R1(config-route-map)#exit
R1(config)#router bgp 100
R1(config-router)#neighbor 12.1.1.2 route-map deny_100.map out
R1(config-router)#exit
R1(config)#end
R1#clear ip bgp 12.1.1.2 out

# prefix-list
R3(config)#ip prefix-list deny_10.pre deny 10.1.2.0/24
R3(config)#ip prefix-list deny_10.pre deny 10.1.3.0/24
R3(config)#ip prefix-list deny_10.pre permit 0.0.0.0/0 le 32
R3(config)#router bgp 200
R3(config-router)#neighbor 23.1.1.2 prefix-list deny_10.pre in
R3#clear ip bgp 23.1.1.2 in

# as-path access-list 
R4(config)#ip as-path access-list 1 deny 100$
R4(config)#ip as-path access-list 1 permit .*

R4(config)#router bgp 300
R4(config-router)#neighbor 34.1.1.3 filter-list 1 in
R4#clear ip bgp 34.1.1.3 in

BGP - Peer Group

考慮到可能需要建立多個相同 peer 的情況,為了簡化 BGP 對鄰居的參數配置,通過 BGP-Peer Group 屬性,將需要相同配置和策略的 peer 宣告進一個 Peer Group 中。

限制:對於一個 Peer-Group 來說,所有 Peer(鄰居)必須全為 IGP 鄰居,或者 EGP 鄰居。

假設有這樣的場景:

在 AS 100 中,有多台路由器,需要建立全互聯的 IGP 鄰居,並使用環回口建立。

在配置過程中,很多配置都一樣。所以可以通過 Peer Group,將要建立鄰居的路由器鄰居地址放在一起,這樣僅需要配置一次,就相當於和 Peer Group 中所有的鄰居建立了 IGP 關系。

R1 和 R2,R3 建立 IBGP 關系,並使用環回口,並建立 Peer Group.

這里由於想通過環回口建立 R1,R2,R3 之間的關系,所以需要通過在內部使用 IGP - OSPF 傳遞相關的路由,保證 TCP 可達。才能建立鄰居關系。

# R1 Peer-Group 配置
router bgp 100
 bgp router-id 1.1.1.1
 # 聲明 group,並配置統一命令
 neighbor AS_100 peer-group
 neighbor AS_100 remote-as 100
 neighbor AS_100 update-source Loopback0
 neighbor AS_100 next-hop-self
 # 將 peer ip 聲明到該 group 中
 neighbor 2.2.2.2 peer-group AS_100
 neighbor 3.3.3.3 peer-group AS_100
router ospf 100
 router-id 1.1.1.1
 network 1.1.1.1 0.0.0.0 area 0
 network 12.1.1.0 0.0.0.255 area 0
 network 13.1.1.0 0.0.0.255 area 0

# R2 正常配置
R2#show running-config | s router
router ospf 100
 router-id 2.2.2.2
 network 2.2.2.2 0.0.0.0 area 0
 network 12.1.1.0 0.0.0.255 area 0
router bgp 100
 bgp router-id 2.2.2.2
 neighbor 1.1.1.1 remote-as 100
 neighbor 1.1.1.1 update-source Loopback0

# R3 正常配置
R3#show running-config | s router
router ospf 100
 router-id 3.3.3.3
 network 3.3.3.3 0.0.0.0 area 0
 network 13.1.1.0 0.0.0.255 area 0
router bgp 100
 bgp router-id 3.3.3.3
 neighbor 1.1.1.1 remote-as 100
 neighbor 1.1.1.1 update-source Loopback0

R1 和 R4,R5 建立 EBGP 關系,並使用 Peer Group,並配置屬性過濾 22 網段的路由。

# R1 建立 EBGP Peer-group 組
router bgp 100
 neighbor AS200_300 peer-group
 neighbor 14.1.1.4 remote-as 200
 neighbor 14.1.1.4 peer-group AS200_300
 neighbor 15.1.1.5 remote-as 300
 neighbor 15.1.1.5 peer-group AS200_300
 # 這里由於 neighbor 的 AS 不一樣,所以需要分開聲明。

# R4 BGP 配置
router bgp 200
 bgp router-id 4.4.4.4
 bgp log-neighbor-changes
 neighbor 14.1.1.1 remote-as 100

# R5 BGP 配置
router bgp 300
 bgp router-id 5.5.5.5
 bgp log-neighbor-changes
 neighbor 15.1.1.1 remote-as 100
 
 # 這里將 2.0 和 3.0 通過 BGP 宣告給 EBGP 鄰居,然后想過濾 3.0 的路由,
 # 這時如果對於 peer 有經常需要改變策略的情況,直接對 Peer-Group 進行操作就可以了。
 # R1 宣告網絡
 network 2.2.2.2 mask 255.255.255.255
 network 3.3.3.3 mask 255.255.255.255
 # 設置策略
R1(config)#ip prefix-list f.pre deny 2.2.2.2/32
R1(config)#ip prefix-list f.pre perm
R1(config)#ip prefix-list f.pre permit 0.0.0.0/0 le 32
R1(config)#router bgp 100
R1(config-router)#neighbor AS200_300 prefix-list f.pre out

# 在 R4 查看,沒有 2.0 的網絡:
R4#show ip bgp
     Network          Next Hop            Metric LocPrf Weight Path
 *>   1.1.1.0/24       14.1.1.1                 0             0 100 i
 *>   3.3.3.3/32       14.1.1.1                11             0 100 i

BGP 認證

BGP 使用 Md5 進行認證,使用 peer-group 的拓撲。

# R2 配置認證
 neighbor 1.1.1.1 remote-as 100 password cisco
 clear ip bgp 1.1.1.1
 
 # R3 配置認證
 neighbor 1.1.1.1 remote-as 100 password cisco
 
 # R1 配置認證
 R1(config-router)#neighbor AS_100 password cisco

BGP 反射器

在 BGP 路由傳遞規則的第二條中,我們知道,從 IBGP 對等體獲得的 BGP,只能發給 EBGP 對等體,不發給 IBGP 對等體(BGP 水平分割)。

但這樣也有問題,比如如下場景中:

根據 BGP 水平分割原則,從 IBGP 學到的路由不能傳給 IBGP,所以這里 R2 R4 R5 都需要和 R3 建立 IBGP 的關系,但如果未來這三台路由器,也從其他 AS 學來路由,所以就需要對這四台設備建立全互聯的 IBGP 關系,建立的總數就是:n(n-1)/2 = 6 條。如果設備的數量多起來后,就需要維護大量的 Peer 關系。造成性能的浪費。

為了學習到 IBGP 的路由,可以通過路由反射器(RR),減少建立 IGP 的全互聯的關系。

路由反射器 RR 具有的角色:

  • 客戶機(Client):與 RR 形成反射鄰居關系的 IBGP 設備。
  • 非客戶機(Non-Client):不是 RR 也不是客戶機的 IBGP 設備。
  • 集群(Cluster):路由反射器及其客戶機的集合。

路由反射器 RR 具有的功能:

  • 允許從 IBGP 學到的路由,反射到其他 IBGP 對等體設備。

路由反射器 RR 反射規則:

  • 從 EBGP 對等體學到的路由,可以發給非客戶機和客戶機。
  • 從非客戶機 IBGP 對等體學到的路由,發布給此 RR 的所有客戶機。
  • 從客戶機學到的路由,發布給此 RR 的所有客戶機和非客戶機。(發起此路由的客戶機除外)

背景:

R1 和 R2 建立,EBGP 關系。

R2,R3,R4,R5 建立 IBGP 關系,並建立 OSPF 保證內部網絡可達。

R5 和 R6 建立 EBGP 關系。

這里想要實現:在 R1 上有 1.0 網絡,R6 上有 6.0 網絡,並配置在環回口上。想要讓 R1 收到 R6 的路由,R6 收到 R1 的路由。

根據 BGP 水平分割原則,R2 從 EBGP 學到的路由,可以傳給 R3,但 R3 是從 IBGP 學到的路由,不能傳給 R4. 所以 1.0 路由再次中斷。

同理,6.0 的路由在 R3 中斷。

正常傳遞 BGP 路由:

# R1
interface Loopback0
 ip address 1.1.1.1 255.255.255.255
interface Ethernet0/0
 ip address 12.1.1.1 255.255.255.0
router bgp 65100
 bgp router-id 1.1.1.1
 bgp log-neighbor-changes
 network 1.1.1.1 mask 255.255.255.255
 neighbor 12.1.1.2 remote-as 65200

# R2 
interface Ethernet0/0
 ip address 12.1.1.2 255.255.255.0
interface Ethernet0/1
 ip address 23.1.1.2 255.255.255.0
router bgp 65200
 bgp router-id 2.2.2.2
 bgp log-neighbor-changes
 neighbor 12.1.1.1 remote-as 65100
 neighbor 23.1.1.3 remote-as 65200
 neighbor 23.1.1.3 next-hop-self
 # 宣告內部網絡給 R1 和 R6
 network 12.1.1.0 mask 255.255.255.0
 network 23.1.1.0 mask 255.255.255.0
router ospf 100
 network 23.1.1.0 0.0.0.255 area 0


# R3
interface Ethernet0/0
 ip address 23.1.1.3 255.255.255.0
 duplex auto
interface Ethernet0/1
 ip address 34.1.1.3 255.255.255.0
interface Ethernet0/2
 no ip address
 shutdown
router bgp 65200
 bgp router-id 3.3.3.3
 bgp log-neighbor-changes
 neighbor 23.1.1.2 remote-as 65200
 neighbor 34.1.1.4 remote-as 65200
 router ospf 100
 network 23.1.1.0 0.0.0.255 area 0
 network 34.1.1.0 0.0.0.255 area 0


# R4
interface Ethernet0/0
 ip address 34.1.1.4 255.255.255.0
interface Ethernet0/1
 ip address 45.1.1.4 255.255.255.0
router bgp 65200
 bgp router-id 4.4.4.4
 neighbor 34.1.1.3 remote-as 65200
 neighbor 45.1.1.5 remote-as 65200
router ospf 100
 network 34.1.1.0 0.0.0.255 area 0
 network 45.1.1.0 0.0.0.255 area 0


# R5
interface Ethernet0/0
 ip address 45.1.1.5 255.255.255.0
interface Ethernet0/1
 ip address 56.1.1.5 255.255.255.0
router bgp 65200
 bgp router-id 5.5.5.5
 neighbor 45.1.1.4 remote-as 65200
 neighbor 45.1.1.4 next-hop-self
 neighbor 56.1.1.6 remote-as 65300
 network 45.1.1.0 mask 255.255.255.0
 network 56.1.1.0 mask 255.255.255.0
router ospf 100
 network 45.1.1.0 0.0.0.255 area 0

# R6
interface Loopback0
 ip address 6.6.6.6 255.255.255.255
interface Ethernet0/0
 ip address 56.1.1.6 255.255.255.0
router bgp 65300
 bgp router-id 6.6.6.6
 network 6.6.6.6 mask 255.255.255.255
 neighbor 56.1.1.5 remote-as 65200

配置反射器:

# R3 將 34.1.1.4 設置成客戶端,自己成為 RR,此時會將 1.0 網絡發給 R4
R3(config)#router bgp 65200
R3(config-router)#neighbor 34.1.1.4  route-reflector-client

# R4 將 45.1.1.5 設置成客戶端,自己成為 RR,此時會將 1.0 網絡發給 R5
R4(config)#router bgp 65200
R4(config-router)#neighbor 45.1.1.5 route-reflector-client

這樣就實現了 R1 的路由傳給 R6。R6 的路由傳給 R1。

現在分析一下這個過程:
1.0 網絡:
由於 R3 是 RR,客戶端是 R4. 所以 RR 會將 1.0 網絡傳給客戶端 R4.
由於 R4 是 RR,客戶端是 R5.從非客戶機學來的路由可以傳給本 RR 的客戶機。所以 RR 會將 1.0 網絡傳給客戶端 R5.
R5 和 R6 是 EBGP,所以將路由傳給 R6.

6.0 網絡:
R5 從 EBGP 學到 6.0 網絡。
由於 R5 是 R4 的客戶機,從客戶機學到的路由,發布給此 RR 的所有客戶機和非客戶機。
R2 是 R3 的客戶機,所以 R2 會收到 R3 發來的路由。
R2 和 R1 是 EBGP,所以會將路由傳給 R1.

配置反射器會不會造成環路?

通過 cluster_list 進行反射器防環:

如上面的拓撲中,R5 和 R1 建立 IBGP 關系,R5 學到的路由會傳給 R1,而 R2 R3 R4 收不到。所以將 R4 配置成 RR,傳遞給 R3。R3 配置成 RR,傳給 R2,R2 配置成 RR,傳給 R1(可能 R1 也有自己的路由需要發送。)。看起來這樣就形成了環路。

但實際上不會,通過 cluster_list 防止環路。在每個 cluster 中,如果經過反射器,反射器就會將自己的 Router-Id 添加到 cluster_list 中。如果發現在 cluster_list 中有自己的 router_id,說明這個路由曾經是自己反射過去的,從而避免環路。

路由的 cluster_list 變化如下:

  • cluster_list: R1_ID
  • cluster_list: R4_ID, R1_ID
  • cluster_list: R3_ID, R4_ID, R1_ID
  • cluster_list: R2_ID, R3_ID, R4_ID, R1_ID
  • R1 檢測發現包含自己的 ID,所以將該路由扔掉。

通過 Originator ID 進行始發者防止環路:

假如 R1 上一個回環口 Io 1 1.1.1.1 的路由,想讓 R3,R4 收到 R1 的路由,注意此時 R1 不是 RR。而 R4 和 R3 是 RR。

1.1.1.1 的路由是 R1 的路由,不是從其他 IBGP 學到的路由,所以能正常傳遞給 R4. R4 作為反射器傳遞給 R3,R3 作為反射器又傳遞給 R1.

但此時 R1 發現該路由的 Originator ID 為自己,所以將該路由丟棄掉。

BGP 聯盟

BGP 聯盟采用在一個 AS 內部,建立多個子 AS 的方法,將一個大 AS 拆分成多個子 AS,讓 AS 內部建立 EBGP 鄰居,解決 IBGP 水平分割的問題。建議使用私有 AS 號(64512 - 65534). 對於外界來說,並不知道該 AS 內部擁有多個子 AS.

# R2
# 聲明子 AS 號
router bgp 65023
 bgp router-id 2.2.2.2
 bgp log-neighbor-changes
 # 指定父 AS 號
 bgp confederation identifier 65200
 neighbor 12.1.1.1 remote-as 65100
 neighbor 23.1.1.3 remote-as 65023
 neighbor 23.1.1.3 next-hop-self

# R3
router bgp 65023
 bgp router-id 3.3.3.3
 # 指定父 AS 號
 bgp confederation identifier 65200
 # 指定另一個子 AS 的號,用於和不使用 BGP 聯盟進行區分
 bgp confederation peers 65045
 neighbor 23.1.1.2 remote-as 65023
 neighbor 34.1.1.4 remote-as 65045
 
 # R4
 router bgp 65045
 bgp router-id 4.4.4.4
# 指定父 AS 號
 bgp confederation identifier 65200
# 指定另一個子 AS 的號,用於和不使用 BGP 聯盟進行區分
 bgp confederation peers 65023
 neighbor 34.1.1.3 remote-as 65023
 neighbor 45.1.1.5 remote-as 65045

# R5
router bgp 65045
 bgp router-id 5.5.5.5
 # 指定父 AS 號
 bgp confederation identifier 65200
 neighbor 45.1.1.4 remote-as 65045
 neighbor 45.1.1.4 next-hop-self
 neighbor 56.1.1.6 remote-as 65300
 
# 在 R1 查看 6.0 的 bgp 路由信息,發現 AS Path 中並沒有子 AS PAth。
R1#show ip bgp 
     Network          Next Hop            Metric LocPrf Weight Path
 *>   1.1.1.1/32       0.0.0.0                  0         32768 i
 *>   6.6.6.6/32       12.1.1.2                           0           65200 65300 i

# 在 R2 中查看 6.0 bgp 路由信息,發現有 65045 的子 AS Path.
R2#show ip bgp
     Network          Next Hop            Metric LocPrf Weight Path
 *>   1.1.1.1/32       12.1.1.1                 0             0 65100 i
 *>i  6.6.6.6/32       45.1.1.5                 0    100      0 (65045) 65300 i

BGP - IPV6

router bgp 200
# 建立正常 Peer 和 IPV4 一樣
neighbor 3003::3 remote-as 200
# 對 neighbor 各種屬性的配置,在 address-famliy 下
address-family ipv6
neighbor 3003::3 activate
neighbor 3003::3 next-hop-self
exit-address-family

配置

實驗1:EBGP 和 IBGP 之間的相互通信

R1 和 R2 之間建立 EBGP 鄰居。

R2 和 R4 之間建立 IBGP 鄰居,使用回環接口。因為回環接口是虛擬接口,不是物理接口。從而可以保證線路的穩定,假設 R2 到 R4 可以存在多條路徑,不會因為某一條斷了,之間鄰居關系就消失。

R2,R3,R4 運行 OSPF,實現 R2,R3,R4 之間的網絡可達。

R4 和 R5 之間建立 EBGP 鄰居。

實現:R1 訪問 5.0 網絡,R5 訪問 1.0 網絡的全網互通。

# R1 
!
interface Loopback1
 ip address 1.1.1.1 255.255.255.0
!
interface Ethernet0/0
 ip address 12.1.1.1 255.255.255.0
 duplex auto
!
!
router bgp 100
 bgp router-id 1.1.1.1
 bgp log-neighbor-changes
 # 宣告的路由
 network 1.1.1.0 mask 255.255.255.0
 # 建立 EBGP 鄰居
 neighbor 12.1.1.2 remote-as 200
!
# 查看鄰居信息 
R1#show ip bgp summary

# 查看 BGP 路由表
1#show ip bgp
BGP table version is 2, local router ID is 1.1.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
              x best-external, a additional-path, c RIB-compressed,
              t secondary path,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path
 *>   1.1.1.0/24       0.0.0.0                  0         32768 i

# R2
!
interface Loopback1
 ip address 2.2.2.2 255.255.255.0
!
interface Ethernet0/0
 ip address 12.1.1.2 255.255.255.0
 duplex auto
!
interface Ethernet0/1
 ip address 23.1.1.2 255.255.255.0
 duplex auto
!
router ospf 100
 router-id 2.2.2.2
 network 2.2.2.2 0.0.0.0 area 0
 network 23.1.1.2 0.0.0.0 area 0
!
router bgp 200
 bgp router-id 2.2.2.2
 bgp log-neighbor-changes
 neighbor 4.4.4.4 remote-as 200
 # 由於是通過虛擬接口建立鄰居,所以建立時需要指定通過哪個接口建立,否則無法建立鄰居關系,物理接口沒有這個問題
 neighbor 4.4.4.4 update-source Loopback1
 # BGP 在默認傳遞路由時,不會更改下一跳地址,默認將其視為一個整體。
 # 而且在傳遞路由時,BGP 只傳遞最優路由,如果不設置,R1 根本不會傳遞 5.5.5.5 的路由。
 # 由於 R3,R4 沒有去往 1.1.1.1 的路由,雖然 1.0 網絡存在在 BGP 路由表中,但不可達,所以將下一跳地址改為 R2 自己
 neighbor 4.4.4.4 next-hop-self
 neighbor 12.1.1.1 remote-as 100
!
# R3 
!
interface Ethernet0/0
 ip address 23.1.1.3 255.255.255.0
 duplex auto
!
interface Ethernet0/1
 ip address 34.1.1.3 255.255.255.0
 duplex auto
!
router ospf 100
 router-id 3.3.3.3
 network 23.1.1.0 0.0.0.255 area 0
 network 34.1.1.0 0.0.0.255 area 0
!
# R4
!
interface Loopback0
 ip address 4.4.4.4 255.255.255.0
!
interface Ethernet0/0
 ip address 34.1.1.4 255.255.255.0
 duplex auto
!
interface Ethernet0/1
 ip address 45.1.1.4 255.255.255.0
 duplex auto
!
router ospf 100
 network 4.4.4.4 0.0.0.0 area 0
 network 34.1.1.4 0.0.0.0 area 0
!
router bgp 200
 bgp router-id 4.4.4.4
 bgp log-neighbor-changes
 neighbor 2.2.2.2 remote-as 200
 neighbor 2.2.2.2 update-source Loopback0
 neighbor 45.1.1.5 remote-as 300
 neighbor 2.2.2.2 next-hop-self
!

# 如果有延遲通過該命令刷新
R2#clear ip bgp interna
# R5
!
interface Loopback5
 ip address 5.5.5.5 255.255.255.0
!
interface Ethernet0/0
 ip address 45.1.1.5 255.255.255.0
 duplex auto
!
router bgp 300
 bgp router-id 5.5.5.5
 bgp log-neighbor-changes
 network 5.5.5.0 mask 255.255.255.0
 neighbor 45.1.1.4 remote-as 200
!

拓展1:BGP 和 IGP 傳遞路由原則

但這時有個問題,R1 和 R5 雖然能夠學習到 BGP 的路由,但依然無法正常通信。R1 使用 Lo 0 接口 ping 不通 5.5.5.5 的接口,原因在於:

R1 想要訪問 5.0 網絡,需要將數據給 R2,R2 想要訪問 5.0 網絡,需要將數據包給 4.0 網絡,而去 4.0 網絡,需要將數據包給 R3. 可是 R3 並沒有去往 5.0 網絡的路由,因此產生了路由黑洞。

換句話說,如果在傳遞 BGP 路由前,先去檢測 IGP 到這條路由是否可達,如果可達就去傳。但該功能默認在思科設備上關閉的,其實現在很多廠商的設備都將該屬性設置是關閉的。

因為 BGP 的目的在於傳遞路由,而不是檢測自己能不能可達。

解決上面的問題也很簡單,將 R3 也建立 IBGP 的鄰居關系就可以了。

在 EBGP 間使用回環接口建立 EBGP 鄰居

在 R1 上配置 11 網絡的回環口,增加默認路由:

# 配合回環接口和靜態路由
R1(config)#int lo 11
R1(config-if)#ip addr 11.11.11.11 255.255.255.255
R1(config-if)#exit
R1(config)#ip route 22.22.22.22 255.255.255.255 12.1.1.2

# 配合 bgp 鄰居
R1(config)#router bgp 100
R1(config-router)#no neighbor 12.1.1.2 remote-as 200
R1(config-router)#neighbor 22.22.22.22 update-source lo 11

在 R2 上配置 22 網絡的回環口,增加默認路由:

R2(config)#int lo 22
R2(config-if)#ip addr 22.22.22.22 255.255.255.255
R2(config)#ip route 11.11.11.11 255.255.255.255 12.1.1.1

R2(config)#router bgp 200
R2(config-router)#no neighbor 12.1.1.1 remote-as 100
R2(config-router)#neighbor 11.11.11.11 remote-as 100
R1(config-router)#neighbor 11.11.111.1 update-source lo 22

R1 查看 EBGP 鄰居,發現無法建立:

R1#show ip bgp summary
BGP router identifier 1.1.1.1, local AS number 100
BGP table version is 4, main routing table version 4
1 network entries using 144 bytes of memory
1 path entries using 84 bytes of memory
1/1 BGP path/bestpath attribute entries using 160 bytes of memory
0 BGP route-map cache entries using 0 bytes of memory
0 BGP filter-list cache entries using 0 bytes of memory
BGP using 388 total bytes of memory
BGP activity 2/1 prefixes, 2/1 paths, scan interval 60 secs

Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
22.22.22.22     4          200       0       0        1    0    0 never    Idle


R1#ping 22.22.22.22
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 22.22.22.22, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/5 ms

發現無法正常建立,原因在於:

EBGP 的直連檢測功能:在建立鄰居時,會檢測下直連的接口是否是物理接口。

如果一定要使用回環接口,可以通過該命令,將網絡層 TTL 值修改為 255, 從而打破直連檢測功能

R1(config)#router bgp 100
R1(config-router)#neighbor 22.22.22.22 ebgp-multihop

R2(config)#router bgp 200
R2(config-router)#neighbor 11.11.11.11 ebgp-multihop

# 發現鄰居可以正常建立了
R1#show ip bgp summary
BGP router identifier 1.1.1.1, local AS number 100
BGP table version is 5, main routing table version 5
2 network entries using 288 bytes of memory
2 path entries using 168 bytes of memory
2/2 BGP path/bestpath attribute entries using 320 bytes of memory
1 BGP AS-PATH entries using 24 bytes of memory
0 BGP route-map cache entries using 0 bytes of memory
0 BGP filter-list cache entries using 0 bytes of memory
BGP using 800 total bytes of memory
BGP activity 3/1 prefixes, 3/1 paths, scan interval 60 secs

Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
22.22.22.22     4          200       6       6        5    0    0 00:01:34        1

但在實際中,不同 AS 一般對應不同的機構,所以使用物理接口比較常見,因為使用回環接口往往需要考慮安全,策略等因素。

實驗2:BGP 選路

這里假設 AS 200 為外部 ISP 的自治系統,AS 100 為內部的自治系統。這里我們想在 AS 100 內進行配置,實現 BGP 的選路操作。

准備工作:

  1. 首先在 AS 100 中,建立 R1,R2,R3 的鄰居關系,通過 IGP - OSPF 實現,路由的互通。然后在 R1,R2,R3 中建立 IBGP 的 Peer 關系。
# 建立如下接口:
R1>show ip inter br
Interface                  IP-Address      OK? Method Status                Protocol
Ethernet0/0                12.1.1.1        YES manual up                    up
Ethernet0/1                13.1.1.1        YES manual up                    up
Ethernet0/2                unassigned      YES unset  administratively down down
Ethernet0/3                unassigned      YES unset  administratively down down
Loopback0                  1.1.1.1         YES manual up                    up
Loopback10                 10.1.1.1        YES manual up                    up
Loopback11                 10.11.11.11     YES manual up                    up

R2>show ip inter br
Interface                  IP-Address      OK? Method Status                Protocol
Ethernet0/0                12.1.1.2        YES manual up                    up
Ethernet0/1                23.1.1.2        YES manual up                    up
Ethernet0/2                24.1.1.2        YES manual up                    up
Ethernet0/3                unassigned      YES unset  administratively down down
Loopback0                  2.2.2.2         YES manual up                    up

R3>show ip inte br
Interface                  IP-Address      OK? Method Status                Protocol
Ethernet0/0                13.1.1.3        YES manual up                    up
Ethernet0/1                23.1.1.3        YES manual up                    up
Ethernet0/2                35.1.1.3        YES manual up                    up
Ethernet0/3                unassigned      YES unset  administratively down down
Loopback0                  3.3.3.3         YES manual up                    up
# 通過回環口,建立 IBGP 鄰居關系
# R1
R1#show running-config | s bgp
router bgp 100
 bgp router-id 1.1.1.1
 bgp log-neighbor-changes
 neighbor 2.2.2.2 remote-as 100
 neighbor 2.2.2.2 update-source Loopback0
 neighbor 3.3.3.3 remote-as 100
 neighbor 3.3.3.3 update-source Loopback0

# R2
R2#show running-config | s bgp
router bgp 100
 bgp router-id 2.2.2.2
 bgp log-neighbor-changes
 neighbor 1.1.1.1 remote-as 100
 neighbor 1.1.1.1 update-source Loopback0
 neighbor 3.3.3.3 remote-as 100
 neighbor 3.3.3.3 update-source Loopback0

# R3
router bgp 100
 bgp router-id 3.3.3.3
 bgp log-neighbor-changes
 neighbor 1.1.1.1 remote-as 100
 neighbor 1.1.1.1 update-source Loopback0
 neighbor 2.2.2.2 remote-as 100
 neighbor 2.2.2.2 update-source Loopback0
  1. 同樣在 AS 200 中,建立 R4,R5,R6 的鄰居關系,通過 IGP - OSPF 實現,路由的互通。然后在 R4,R5,R6 中建立 IBGP 的 Peer關系。

    R4>show ip inter br
    Interface                  IP-Address      OK? Method Status                Protocol
    Ethernet0/0                24.1.1.4        YES manual up                    up
    Ethernet0/1                45.1.1.4        YES manual up                    up
    Ethernet0/2                46.1.1.4        YES manual up                    up
    Ethernet0/3                unassigned      YES unset  administratively down down
    Loopback0                  4.4.4.4         YES manual up                    up
    
    R5>show ip inter br
    Interface                  IP-Address      OK? Method Status                Protocol
    Ethernet0/0                35.1.1.5        YES manual up                    up
    Ethernet0/1                45.1.1.5        YES manual up                    up
    Ethernet0/2                56.1.1.5        YES manual up                    up
    Ethernet0/3                unassigned      YES unset  administratively down down
    Loopback0                  5.5.5.5         YES manual up                    up
    
    R6>show ip inter br
    Interface                  IP-Address      OK? Method Status                Protocol
    Ethernet0/0                46.1.1.6        YES manual up                    up
    Ethernet0/1                56.1.1.6        YES manual up                    up
    Ethernet0/2                unassigned      YES unset  administratively down down
    Ethernet0/3                unassigned      YES unset  administratively down down
    Loopback0                  6.6.6.6         YES manual up                    up
    Loopback10                 10.6.6.6        YES manual up                    up
    Loopback11                 10.66.66.66     YES manual up                    up
    
    # 通過回環口,建立 IBGP 鄰居關系
    # R4
    R1#show running-config | s bgp
    router bgp 200
     bgp router-id 4.4.4.4
     bgp log-neighbor-changes
     neighbor 5.5.5.5 remote-as 200
     neighbor 5.5.5.5 update-source Loopback0
     neighbor 6.6.6.6 remote-as 200
     neighbor 6.6.6.6 update-source Loopback0
    
    # R5
    R2#show running-config | s bgp
    router bgp 200
     bgp router-id 5.5.5.5
     bgp log-neighbor-changes
     neighbor 4.4.4.4 remote-as 200
     neighbor 4.4.4.4 update-source Loopback0
     neighbor 6.6.6.6 remote-as 200
     neighbor 6.6.6.6 update-source Loopback0
    
    # R6
    router bgp 200
     bgp router-id 6.6.6.6
     bgp log-neighbor-changes
     neighbor 4.4.4.4 remote-as 200
     neighbor 4.4.4.4 update-source Loopback0
     neighbor 5.5.5.5 remote-as 200
     neighbor 5.5.5.5 update-source Loopback0
    
  2. 最后在 R2 和 R4,R3 和R5 之間連接 EBGP 的 Peer 關系。

# R2
R2(config)#router bgp 100
R2(config-router)#neighbor 24.1.1.4 remote-as 200

# R4
R4(config)#router bgp 200
R4(config-router)#neighbor 24.1.1.2 remote-as 100

# R3
R3(config)#router bgp 100
R3(config-router)#neighbor 35.1.1.5 remote-as 200

# R5
R5(config-router)#router bgp 200
R5(config-router)#neighbor 35.1.1.3 remote-as 100

在 R1 和 R6 將回環口的路由,宣告到 BGP 中

# R6
R6(config)#router bgp 200
R6(config-router)#network 10.6.6.6 mask 255.255.255.255
R6(config-router)#network 10.66.66.66 mask 255.255.255.255

# R1 查詢 BGP 路由表,發現已經收到了 R6 的兩條路由
R1#show ip bgp
BGP table version is 1, local router ID is 1.1.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
              x best-external, a additional-path, c RIB-compressed,
              t secondary path,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path
 * i  10.6.6.6/32      3.3.3.3                  0    100      0 200 i
 *>i                   2.2.2.2                  0    100      0 200 i
 * i  10.66.66.66/32   3.3.3.3                  0    100      0 200 i
 *>i                   2.2.2.2                  0    100      0 200 i

 
 但可以發現,下一跳地址為 35.1.1.5 和  24.1.1.4 ,但由於當前路由表中,並沒有該路由所以,ping 不同這兩個網段。
 所以需要修改 next-hop
 
 # R2 將傳給其他 IBGP 路由的 next-hop 修改為自己
R2(config)#router bgp 100
R2(config-router)#neighbor 1.1.1.1  next-hop-self
R2(config-router)#neighbor 3.3.3.3  next-hop-self

# R3 
R3(config)#router bgp 100
R3(config-router)#neighbor 1.1.1.1  next-hop-self
R3(config-router)#neighbor 2.2.2.2  next-hop-self

# 同樣的問題也會在 R6 上出現,修改 R5 和 R4 的下一跳
R4(config)#router bgp 200
R4(config-router)#neighbor 5.5.5.5 next-hop-self
R4(config-router)#neighbor 6.6.6.6 next-hop-self
R5(config)#router bgp 200
R5(config-router)#neighbor 4.4.4.4 next-hop-self
R5(config-router)#neighbor 6.6.6.6 next-hop-self
R6#clear ip bgp in

# R6 ping
R6#ping 10.1.1.1 source lo10
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.1.1.1, timeout is 2 seconds:
Packet sent with a source address of 10.6.6.6
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms

目前已經實現,R1 和 R6 的回環地址互通了。

調整 BGP 路徑

先來分析下,目前 10.1.1.1 訪問 10.6.6.6 的情況:

R1#traceroute 10.6.6.6 source 10.1.1.1
Type escape sequence to abort.
Tracing the route to 10.6.6.6
VRF info: (vrf in name/id, vrf out name/id)
  1 12.1.1.2 0 msec 1 msec 0 msec
  2 24.1.1.4 1 msec 1 msec 0 msec
  3 46.1.1.6 1 msec 1 msec *
# 發現出流量走:R1-R2-R4-R6,原因在於,根據之前 BGP 的選路原則 R2 比 R3 建立的連接時間長,所以走 R2。 R4 和 R5 同理。

R6#traceroute 10.1.1.1 source 10.6.6.6
Type escape sequence to abort.
Tracing the route to 10.1.1.1
VRF info: (vrf in name/id, vrf out name/id)
  1 46.1.1.4 0 msec 0 msec 1 msec
  2 24.1.1.2 1 msec 0 msec 1 msec
  3 12.1.1.1 0 msec 1 msec *
# 發現 R6 到 R1:走 R6-R4-R1,同樣 R4 比 R5 的連接時間長,所以走 R2.

需求1:讓 10.1.1.1 訪問 10.6.6.6 的流量走 R1-R3-R5-R6, 回程流量走 R6-R4-R2-R1.

通過調整 Local_preference 和 MED 實現

# Local_preference 影響出流量的路由
# 這里 locPrf 的值相等為100,我們想走 R3,只需將 3.3.3.3 的路由的 LocPrf 值調大。可以在 R1 的 in 方向做策略,或者 R3 的出方向做策略。
R1>show ip bgp
     Network          Next Hop            Metric LocPrf Weight Path
 *>   10.1.1.1/32      0.0.0.0                  0         32768 i
 * i  10.6.6.6/32      3.3.3.3                  0    100      0 200 i
 *>i                   2.2.2.2                  0    100      0 200 i
 *>   10.11.11.11/32   0.0.0.0                  0         32768 i
 * i  10.66.66.66/32   3.3.3.3                  0    100      0 200 i
 *>i                   2.2.2.2                  0    100      0 200 i

# 前綴列表抓取流量
R1(config)#ip prefix-list net-10.6.pre permit 10.6.6.6
# route-map 設置策略,改變 local preference
R1(config)#route-map locpre.map permit 10
R1(config-route-map)#match ip address prefix-list net-10.6.pre
R1(config-route-map)#set local-preference 120

# 在 BGP 鄰居調用
R1(config)#router bgp 100
R1(config-router)#neighbor 3.3.3.3 route-map locpre.map in

# 再次查看路由,發現走 3.3.3.3 網絡
R1#show ip bgp
     Network          Next Hop            Metric LocPrf Weight Path
 *>   10.1.1.1/32      0.0.0.0                  0         32768 i
 *>i  10.6.6.6/32      3.3.3.3                  0    120      0 200 i
 * i                   2.2.2.2                  0    100      0 200 i
 *>   10.11.11.11/32   0.0.0.0                  0         32768 i
 * i  10.66.66.66/32   3.3.3.3                  0    100      0 200 i
 *>i                   2.2.2.2                  0    100      0 200 i
# 修改 MED(Metric),影響進入的路由
# 原來回包走 R2, 雖然現在也走 R2,但是通過第 11 個路徑匹配規則選擇的,所以想將優先級提前。
# 在 R3 上,配置使其發給其他 AS 路由的 Metric 比 R2 小。
# 抓取
R3(config)#ip prefix-list net-1.1.pre permit 10.1.1.1/32 
# 編寫 route-map 策略
R3(config-route-map)#route-m med.map permit 10
R3(config-route-map)#match ip address  net-1.1.pre
R3(config-route-map)#set metric 10
R3(config-route-map)#route-m med.map permit 20
# 應用策略
R3(config)#router bgp 100
R3(config-router)#neighbor 35.1.1.5 route-map med.map out

# 這里模擬器出現了 bug,將 10.11 網絡的 metric 也變成了 10,可以使用 acl 匹配
R3(config-route-map)#access-list 1 permit 10.1.1.1 0.0.0.0
R3(config-route-map)#route-map  med.map permit 10
R3(config-route-map)#match ip address 1

需求2:讓 10.11.11.11 訪問 10.66.66.66 的流量走 R1-R2-R4-R6, 回程流量走 R6-R5-R3-R1.

通過調整 weight 和 AS_PATH 實現

# 通過調整 Weight ,可以影響本路由器發出流量的路由路徑
# 這里可以在 R2 上進行路由策略,控制發給 R1 的路由 weight
# 也可以在 R1 上進行路由策略,控制接收 R2 的路由 weight.
# 目前去往 66 網絡,走 2.2.2.2,原因在於選路的比較原則 11. 現在通過調整 weight,提高優先級,還走 2.2.2.2.
R1#show ip bgp
     Network          Next Hop            Metric LocPrf Weight Path
 *>   10.1.1.2/32      0.0.0.0                  0         32768 i
 * i  10.6.6.6/32      2.2.2.2                  0    100      0 200 i
 *>i                   3.3.3.3                  0    120      0 200 i
 *>   10.11.11.11/32   0.0.0.0                  0         32768 i
 *>i  10.66.66.66/32   2.2.2.2                  0    100      0 200 i
 * i                   3.3.3.3                  0    100      0 200 i
R1(config)#ip access-list standard weight.acl
R1(config-std-nacl)#permit 10.6.6.6 0.0.0.0
R1(config-std-nacl)#exit
R1(config)#route-map weight.map permit 10
R1(config-route-map)#match ip address  weight.acl
R1(config-route-map)#set weight 30
R1(config-route-map)#exit
R1(config)#route-map weight.map permit 20
R1(config-route-map)#exit
R1(config)#router bgp 100
R1(config-router)#neighbor 2.2.2.2 route-map weight.map in

# 可以看到 weight 變為 30
R1#show ip bgp
     Network          Next Hop            Metric LocPrf Weight Path
 *>   10.1.1.1/32      0.0.0.0                  0         32768 i
 *>i  10.6.6.6/32      2.2.2.2                  0    100     30 200 i
 * i                   3.3.3.3                  0    120      0 200 i
 *>   10.11.11.11/32   0.0.0.0                  0         32768 i
 *>i  10.66.66.66/32   2.2.2.2                  0    100      0 200 i
 * i                   3.3.3.3                  0    100      0 200 i
# 調整 AS_PATH, 對於 R6 來說,對於 AS_PATH 會優先選擇短的。
# 所以在 R2 上,增加 AS_PATH 的長度。讓 R6 選擇 R3 傳來的。
R6>show ip bgp
     Network          Next Hop            Metric LocPrf Weight Path
 *>i  10.1.1.1/32      4.4.4.4                  0    100      0 100 i
 *>   10.6.6.6/32      0.0.0.0                  0         32768 i
 *>i  10.11.11.11/32   4.4.4.4                  0    100      0 100 i
 * i                   5.5.5.5                  0    100      0 100 i
 *>   10.66.66.66/32   0.0.0.0                  0         32768 i

# 抓取 10.11.11.11 的流量
R2(config)#access-list 1 permit 10.11.11.11 0.0.0.0
# 改變發布給其他 router 的 as path
R2(config)#route-map as.map permit 10
R2(config-route-map)#match ip address 1
# 這里添加兩個 100 是比較好的做法。添加其他 AS 也可以,比如 300,但假設 300 真的存在,由於 BGP 的規則,可能會被丟棄。
R2(config-route-map)#set as-path prepend 100 100
R2(config-route-map)#exit
R2(config)#route-map as.map permit 20
R2(config)#router bgp 100
R2(config-router)#neighbor 24.1.1.4 route-map as.map out

# 可以看到 R4 學到的 10.11.11.11 的路由 AS PATH 為 100 100 100
R4>show ip bgp
BGP table version is 11, local router ID is 4.4.4.4
     Network          Next Hop            Metric LocPrf Weight Path
 *>   10.1.1.2/32      24.1.1.2                               0 100 i
 *>i  10.6.6.6/32      6.6.6.6                  0    100      0 i
 *    10.11.11.11/32   24.1.1.2                               0 100 100 100 i
 *>i                   5.5.5.5                  0    100      0 100 i
 *>i  10.66.66.66/32   6.6.6.6                  0    100      0 i

實驗3:BGP 路由聚合

預配:

R1,R2 配置相關接口
R1,R2,R3,R4 配置不同 AS,並建立 BGP Peer.

# 配置完后,查看 R3 BGP 路由表
R3#show ip bgp

     Network          Next Hop            Metric LocPrf Weight Path
 *>   10.1.0.0/24      13.1.1.1                 0             0 100 i
 *>   10.1.1.0/24      13.1.1.1                 0             0 100 i
 *>   10.1.2.0/24      13.1.1.1                 0             0 100 i
 *>   10.1.3.0/24      13.1.1.1                 0             0 100 i
 *>   20.1.0.0/24      23.1.1.2                 0             0 200 i
 *>   20.1.1.0/24      23.1.1.2                 0             0 200 i
 *>   20.1.2.0/24      23.1.1.2                 0             0 200 i
 *>   20.1.3.0/24      23.1.1.2                 0             0 200 i
 *>   100.1.0.0/24     13.1.1.1                 0             0 100 i
 *>   100.1.1.0/24     13.1.1.1                 0             0 100 i
 *>   100.1.2.0/24     23.1.1.2                 0             0 200 i
 *>   100.1.3.0/24     23.1.1.2                 0             0 200 i

方法一:手動聚合

在 R3 上,將 R1 和 R2 100.0 網絡的路由進行聚合:

# 配置 NULL0 接口,避免路由環路。
ip route 100.1.0.0 255.255.252.0 Null0

# 宣告匯總網絡
R3(config)#router bgp 300
R3(config-router)#network 100.1.0.0 mask 255.255.252.0

# 在 R4 上查看, 可以看到多出了  10.1.0.0/22 的路由
R4>show ip route
      100.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
B        100.1.0.0/22 [20/0] via 34.1.1.3, 00:00:11
B        100.1.0.0/24 [20/0] via 34.1.1.3, 00:00:11
B        100.1.1.0/24 [20/0] via 34.1.1.3, 00:00:11
B        100.1.2.0/24 [20/0] via 34.1.1.3, 00:00:11
B        100.1.3.0/24 [20/0] via 34.1.1.3, 00:00:11

# 因為聚合的路由已經存在了,最好去除明細路由
# 抓取 prefix
ip prefix-list deny100.pre seq 5 permit 100.1.0.0/24
ip prefix-list deny100.pre seq 10 permit 100.1.1.0/24
ip prefix-list deny100.pre seq 15 permit 100.1.2.0/24
ip prefix-list deny100.pre seq 20 permit 100.1.3.0/24
# route--map deny
route-map d100.map deny 10
match ip address prefix-list deny100.pre
route-map d100.map permit 20

配置 NULL0 的作用:假設有另一個 ISP 網絡,並將 10.0/16 網絡分給了 R3,假設 R3 上連接了一個 ISP 的網絡,並配置了一條默認路由,將流量指向 ISP 的接口,此時 R3 的一個接口 down 了,但發給此接口的流量不會丟棄,會走默認路由發給 ISP, 但由於 ISP 分給 R3 的網絡的 10.0/16 會再把路由傳回來,從而形成環路,直到 TTL 達到 255

方法二:BGP 自動匯總

# 使用 BGP 自動匯總
R3(config)#router bgp 300
R3(config-router)#aggregate-address 100.1.0.0 255.255.252.0
# 查看 R3 路由表,同樣多出一條 NULL 接口
      100.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
B        100.1.0.0/22 [200/0], 00:00:16, Null0
B        100.1.0.0/24 [20/0] via 13.1.1.1, 01:13:12
B        100.1.1.0/24 [20/0] via 13.1.1.1, 01:13:12
B        100.1.2.0/24 [20/0] via 23.1.1.2, 01:02:29
B        100.1.3.0/24 [20/0] via 23.1.1.2, 01:02:29

# 在 R4 查看
R4>show ip bgp
     Network          Next Hop            Metric LocPrf Weight Path
 *>   10.1.0.0/24      34.1.1.3                               0 300 100 i
 *>   10.1.1.0/24      34.1.1.3                               0 300 100 i
 *>   10.1.2.0/24      34.1.1.3                               0 300 100 i
 *>   10.1.3.0/24      34.1.1.3                               0 300 100 i
 *>   20.1.0.0/24      34.1.1.3                               0 300 200 i
 *>   20.1.1.0/24      34.1.1.3                               0 300 200 i
 *>   20.1.2.0/24      34.1.1.3                               0 300 200 i
 *>   20.1.3.0/24      34.1.1.3                               0 300 200 i
 *>   100.1.0.0/24     34.1.1.3                               0 300 100 i
 *>   100.1.0.0/22     34.1.1.3                 0             0 300 i
 *>   100.1.1.0/24     34.1.1.3                               0 300 100 i
 *>   100.1.2.0/24     34.1.1.3                               0 300 200 i
 *>   100.1.3.0/24     34.1.1.3                               0 300 200 i
# 在 R4 查看被聚合后的路由 
R4>show ip bgp 100.1.0.0/22
BGP routing table entry for 100.1.0.0/22, version 113
Paths: (1 available, best #1, table default)
  Not advertised to any peer
  Refresh Epoch 13
  300, (aggregated by 300 3.3.3.3) # 聚合者屬性
    34.1.1.3 from 34.1.1.3 (3.3.3.3)
      Origin IGP, metric 0, localpref 100, valid, external, atomic-aggregate, best # atomic-aggregate 原子聚合屬性
      rx pathid: 0, tx pathid: 0x0

將聚合后的路由 100.1.0.0/22 還原, 原來的 AS_PATH:

# 在 R4 上查看 100.1.0.0/22 的 AS_PATH, 是 300,
# 但始發者是 AS 100 和 200. 所以這里最好加上屬性,防止未來可能產生的環路
R3(config)#router bgp 300
# 添加 as-set 屬性,表示打開記錄之前始發 as 的路徑
R3(config-router)#aggregate-address 100.1.0.0 255.255.252.0 as-set

# 在 R4 上查看
R4>show ip bgp
     Network          Next Hop            Metric LocPrf Weight Path
 *>   10.1.0.0/24      34.1.1.3                               0 300 100 i
 *>   10.1.1.0/24      34.1.1.3                               0 300 100 i
 *>   10.1.2.0/24      34.1.1.3                               0 300 100 i
 *>   10.1.3.0/24      34.1.1.3                               0 300 100 i
 *>   20.1.0.0/24      34.1.1.3                               0 300 200 i
 *>   20.1.1.0/24      34.1.1.3                               0 300 200 i
 *>   20.1.2.0/24      34.1.1.3                               0 300 200 i
 *>   20.1.3.0/24      34.1.1.3                               0 300 200 i
 *>   100.1.0.0/24     34.1.1.3                               0 300 100 i
  # 這里的 {100,200} 表示始發是由 AS 100 和 200 聚合而來,並且沒有先后順序
 *>   100.1.0.0/22     34.1.1.3                 0             0 300 {100,200} i 
 *>   100.1.1.0/24     34.1.1.3                               0 300 100 i
 *>   100.1.2.0/24     34.1.1.3                               0 300 200 i
 *>   100.1.3.0/24     34.1.1.3                               0 300 200 i
# 僅發送匯總路由給 R4
R3(config)#router bgp 300
 R3(config-router)#aggregate-address 100.1.0.0 255.255.252.0 summary-only
 
 # 在 R4上,僅有匯總路由,沒有明細路由
R4>show ip bgp
     Network          Next Hop            Metric LocPrf Weight Path
 *>   10.1.0.0/24      34.1.1.3                               0 300 100 i
 *>   10.1.1.0/24      34.1.1.3                               0 300 100 i
 *>   10.1.2.0/24      34.1.1.3                               0 300 100 i
 *>   10.1.3.0/24      34.1.1.3                               0 300 100 i
 *>   20.1.0.0/24      34.1.1.3                               0 300 200 i
 *>   20.1.1.0/24      34.1.1.3                               0 300 200 i
 *>   20.1.2.0/24      34.1.1.3                               0 300 200 i
 *>   20.1.3.0/24      34.1.1.3                               0 300 200 i
 *>   100.1.0.0/22     34.1.1.3                 0             0 300 i

在 R1 上配置 community 屬性,查看 R3 在聚合后,R4 是否聚合 community 屬性:

# R1 配置 route-map,設置 community 屬性
R3(config)#route-map bgp_comm.map permit 10
R3(config)#match ip address 1
R3(config)#set community 100
R3(config)#route-map bgp_comm.map permit 20

# bgp 應用 route-map,並打開 send-community
R3(config)#router bgp 100
R3(config)# neighbor 13.1.1.3 send-community
R3(config)# neighbor 13.1.1.3 route-map bgp_comm.map out

# R3 同樣設置 send-community:
router bgp 300
 aggregate-address 100.1.0.0 255.255.252.0 as-set summary-only
 neighbor 34.1.1.4 send-community

# R4 查看發現,有 community 屬性
R4#show ip bgp 100.1.0.0/22
BGP routing table entry for 100.1.0.0/22, version 120
Paths: (1 available, best #1, table default)
  Not advertised to any peer
  Refresh Epoch 14
  300 {100,200}, (aggregated by 300 3.3.3.3)
    34.1.1.3 from 34.1.1.3 (3.3.3.3)
      Origin IGP, metric 0, localpref 100, valid, external, best
      Community: 100 # 有該屬性
      rx pathid: 0, tx pathid: 0x0

# 同樣如果在 R2 上配置,不同的 community 為 200,同樣也會傳遞到 R4 中。

可以發現,如果聚合前路由含有 community 的屬性,在聚合后也會含有 community 屬性,但需要開啟 as-set 和 send-community

通過 suppress-map 選擇通告部分明細路由:

# 通過 route-map 抓取,想要抑制的網段
R3(config)#access-list 10 permit 10.1.2.0 0.0.0.0
R3(config)#route-map supressed.map permit 10
R3(config-route-map)#match ip address 10

# 在 BGP 上調用,通過 aggregate-address 宣告聚合后的網段,通過 as-set 保留該網段的起始發布者,通過 suppress-map 抑制匹配的路由發送
R3(config-router)#aggregate-address 10.1.0.0 255.255.252.0 as-set suppress-map supressed.map

R3#show ip bgp
     Network          Next Hop            Metric LocPrf Weight Path
 *>   10.1.0.0/24      13.1.1.1                 0             0 100 i
 *>   10.1.0.0/22      0.0.0.0                       100  32768 100 i
 *>   10.1.1.0/24      13.1.1.1                 0             0 100 i
 s>   10.1.2.0/24      13.1.1.1                 0             0 100 i
 *>   10.1.3.0/24      13.1.1.1                 0             0 100 i
 *>   20.1.0.0/24      23.1.1.2                 0             0 200 i
 *>   20.1.1.0/24      23.1.1.2                 0             0 200 i
 *>   20.1.2.0/24      23.1.1.2                 0             0 200 i
 *>   20.1.3.0/24      23.1.1.2                 0             0 200 i
 s>   100.1.0.0/24     13.1.1.1                 0             0 100 i # 發現該網段被抑制
 *>   100.1.0.0/22     0.0.0.0                       100  32768 {100,200} i
 s>   100.1.1.0/24     13.1.1.1                 0             0 100 i
 s>   100.1.2.0/24     23.1.1.2                 0             0 200 i
 s>   100.1.3.0/24     23.1.1.2                 0             0 200 i


# 在 R4 上查看,發現后匯總的路由 10.1.0.0/22 ,未匯總的路由  10.1.0.0/24, 10.1.1.0/24,10.1.3.0/24 
# 沒有 10.1.2.0/24 ,說明被抑制
R4>show ip bgp

     Network          Next Hop            Metric LocPrf Weight Path
 *>   10.1.0.0/24      34.1.1.3                               0 300 100 i
 *>   10.1.0.0/22      34.1.1.3                 0             0 300 100 i
 *>   10.1.1.0/24      34.1.1.3                               0 300 100 i
 *>   10.1.3.0/24      34.1.1.3                               0 300 100 i
 *>   20.1.0.0/24      34.1.1.3                               0 300 200 i
 *>   20.1.1.0/24      34.1.1.3                               0 300 200 i
 *>   20.1.2.0/24      34.1.1.3                               0 300 200 i
 *>   20.1.3.0/24      34.1.1.3                               0 300 200 i
 *>   100.1.0.0/22     34.1.1.3                 0             0 300 {100,200} i

修改匯總后的 BGP 屬性,比如修改 origin 屬性:

# 設置要修改網段的屬性
R3(config)#ip prefix-list att.pre permit 100.1.0.0/22
R3(config)#route-map att.map permit 10
R3(config-route-map)#match ip address att.pre
R3(config-route-map)#set origin incomplete

# 通過設置 attribute-map 修改屬性
R3(config)#router bgp
R3(config)#router bgp 300
R3(config-router)#aggregate-address 100.1.0.0 255.255.252.0 summary-only attribute-map att.map

# 在 R4 查看 origin 變成 ?
R4>show ip bgp
     Network          Next Hop            Metric LocPrf Weight Path
 *>   10.1.0.0/24      34.1.1.3                               0 300 100 i
 *>   10.1.0.0/22      34.1.1.3                 0             0 300 100 i
 *>   10.1.1.0/24      34.1.1.3                               0 300 100 i
 *>   10.1.3.0/24      34.1.1.3                               0 300 100 i
 *>   20.1.0.0/24      34.1.1.3                               0 300 200 i
 *>   20.1.1.0/24      34.1.1.3                               0 300 200 i
 *>   20.1.2.0/24      34.1.1.3                               0 300 200 i
 *>   20.1.3.0/24      34.1.1.3                               0 300 200 i
 *>   100.1.0.0/22     34.1.1.3                 0             0 300 ?     # 變成 ?

通過 advertise-map,宣告保留傳遞的明細路由的屬性

# 在 R1 上增加  20.1.4.0/24 的網段,並通告給 bgp
# 在 R3 聚合 20 網段的路由,並通過 summary-only 僅通告匯總后的路由,並且讓 R4 收到的匯總路由僅包含 R1 通告網絡的 BGP 的屬性
# 就可以使用 advertise-map

R3(config)#access-list 5 permit 20.1.4.0
R3(config)#route-map adv.map permit 10
R3(config-route-map)#match ip address 5
 
R3(config)#router bgp 300
R3(config-router)# aggregate-address 20.1.0.0 255.255.0.0 as-set summary-only advertise-map adv.map

# R4 上匯總后的路由,僅保留 advtise 上的屬性
R4#show ip bgp
     Network          Next Hop            Metric LocPrf Weight Path
 *>   10.1.0.0/24      34.1.1.3                               0 300 100 i
 *>   10.1.0.0/22      34.1.1.3                 0             0 300 100 i
 *>   10.1.1.0/24      34.1.1.3                               0 300 100 i
 *>   10.1.3.0/24      34.1.1.3                               0 300 100 i
 *>   20.1.0.0/16      34.1.1.3                 0             0 300 100 i # as=200 被抑制了 
 *>   100.1.0.0/22     34.1.1.3                 0             0 300 ?

參考

BGP-NULL0

IBGP和EBGP 的區別


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM