深入淺出 BGP:從 iBGP/eBGP 到 Route Reflector
BGP (Border Gateway Protocol) 是網際網路的「標準語言」,屬於 EGP (外部閘道協定),用於在不同的自治系統 (AS) 之間交換路由資訊,決定數據傳輸的最佳路徑。
網路協定依據「運作範圍」分為兩大類:
| 特性 | IGP (內部閘道協定) | EGP (外部閘道協定) |
|---|---|---|
| 全名 | Interior Gateway Protocol | Exterior Gateway Protocol |
| 運作範圍 | 單一 AS 內部 | 不同 AS 之間 |
| 主要目標 | 速度:快速收斂,找最短路徑。 | 控制:政策路由 (Policy),選最「好」的路徑。 |
| 常見協定 | OSPF, RIP, IS-IS, EIGRP | BGP (目前唯一) |
| 生活比喻 | 國內導航:從台北開車到高雄,要在意路況、距離、紅綠燈 (在意速度)。 | 國際航班:從台灣飛往美國,要考慮簽證、航權、政治因素 (在意政策與可達性)。 |
BGP 就像是國際外交官與國內郵差的結合:
就像 IP 位址有分 Public (公網) 與 Private (內網) 一樣,AS Number 也有區分。私有 AS 僅能在企業內部或與 ISP 約定使用,不可在網際網路上廣播。
| 類型 | 2-Byte Range (傳統) | 4-Byte Range (新式) | 用途類似於 |
|---|---|---|---|
| Public AS (公有) | 1 - 64511 | 1 - 4199999999 | 全球唯一的電話號碼 (+886...) |
| Private AS (私有) | 64512 - 65534 | 4200000000 - 4294967294 | 公司內部分機 (Ext. 1234) |
* 註:AS 0, 23456, 65535 等為保留用途。
BGP 是一種 路徑向量 (Path Vector) 協定,它不只看距離,更看「路徑屬性」(Attributes)。
以下展示 BGP 的三種關鍵架構場景:基礎對接、Full Mesh 的困境、以及 Route Reflector 的解決方案。
說明:跨越 AS 邊界使用 eBGP,AS 內部傳遞外部路由使用 iBGP。
說明:根據 iBGP Split Horizon 規則,若無 RR,所有路由器必須兩兩互連 (N*(N-1)/2),管理極其困難。
說明:所有 Client 只需與 RR 建立鄰居關係。RR 打破 Split Horizon 規則,將路由「反射」給其他 Client,大幅簡化架構。
情境: 「快樂科技公司」是一家中型企業,因為業務擴張,決定向 TWNIC 申請自己的網段 (203.0.113.0/24) 和 AS 號碼 (AS 65001),並與 ISP (AS 3462) 建立連線。
# 1. 基礎介面設定 (假設 Port 1 接 ISP) create vlan isp_link configure vlan isp_link tag 100 configure vlan isp_link add port 1 configure vlan isp_link ipaddress 192.0.2.2/30 enable ipforwarding vlan isp_link # 2. 啟動 BGP 並設定本地 AS (65001 - Private AS Example) enable bgp configure bgp as-number 65001 configure bgp routerid 192.0.2.2 # 3. 建立 eBGP 鄰居關係 (ISP AS 3462) create bgp neighbor 192.0.2.1 remote-AS 3462 enable bgp neighbor 192.0.2.1 # 4. 宣告自己的網段 (需先有路由存在) configure bgp add network 203.0.113.0/24
情境: 企業內部有多個核心節點需要交換 BGP 路由。為了避免每台設備都要互聯 (Full Mesh) 造成管理災難,決定將 HQ 核心交換器設為 Route Reflector (RR),分公司設備設為 Client。
# --- 設定 HQ Core (RR Server) --- enable bgp configure bgp as-number 65000 configure bgp routerid 10.0.0.1 # 建立 iBGP Neighbor (指向 Branch A) create bgp neighbor 10.0.0.2 remote-AS 65000 enable bgp neighbor 10.0.0.2 # 關鍵指令:將此鄰居設為 Client,啟用反射功能 configure bgp neighbor 10.0.0.2 route-reflector-client # 建立 iBGP Neighbor (指向 Branch B) create bgp neighbor 10.0.0.3 remote-AS 65000 enable bgp neighbor 10.0.0.3 configure bgp neighbor 10.0.0.3 route-reflector-client # --- 設定 Branch A (RR Client) --- # Client 端不需要知道誰是 RR,只需當作一般 iBGP 設定即可 enable bgp configure bgp as-number 65000 configure bgp routerid 10.0.0.2 # 建立指向 HQ 的連線 create bgp neighbor 10.0.0.1 remote-AS 65000 enable bgp neighbor 10.0.0.1 # 注意:Client 端不需要設定 route-reflector-client 指令