CCNP路由實驗之七 動態路由之BGPhtml
動態路由協議能夠自動的發現遠程網絡,只要網絡拓撲結構發生了變化,路由器就會相互交換路由信息,不只可以自動獲知新增長的網絡,還能夠在當前網絡鏈接失敗時找出備用路徑。根據是否在一個自治域內部使用,動態路由協議分爲內部網關協議(IGP)和外部網關協議(EGP)。這裏的自治域指一個具備統一管理機構、統一路由策略的網絡。自治域內部採用的路由選擇協議稱爲內部網關協議,經常使用的有RIP、EIGRP、OSPF、IS-IS;外部網關協議主要用於多個自治域之間的路由選擇,經常使用的是BGP和BGP-4。在一個路由器中,可同時配置靜態路由和一種或多種動態路由。它們各自維護的路由表都提供給轉發程序,但這些路由表的表項間可能會發生衝突。這種衝突可經過配置各路由表的優先級來解決。一般靜態路由具備默認的最高優先級,當其它路由表表項與它矛盾時,均按靜態路由轉發。linux
簡介正則表達式
BGP用來鏈接Internet上獨立系統的路由選擇協議。它是Internet工程任務組制定的一個增強的、完善的、可伸縮的協議。BGP4支持CIDR尋址方案,該方案增長了Internet上的可用IP地址數量。BGP是爲取代最初的外部網關協議EGP設計的,也被認爲是一個路徑矢量協議。 BGP 是惟一一個用來處理像因特網大小的網絡的協議,也是惟一可以妥善處理好不相關路由域間的多路鏈接的協議。BGP系統的主要功能是和其餘的 BGP 系統交換網絡可達信息。網絡可達信息包括列出的自治系統(AS)的信息。這些信息有效地構造了 AS 互聯的拓樸圖並由此清除了路由環路,同時在 AS 級別上可實施策略決策。儘管BGP協議是爲自治系統間的路由選擇而設計,但它也能夠用於自治系統內部,是一類雙重路由選擇協議。兩個能夠在自治系統之間進行通訊的BGP相鄰結點必須存在於同一個物理鏈路上。位於同一個自治系統內的BGP路由器能夠互相通訊,以確保它們對整個自治系統的全部信息都相同,並且經過信息交換後,它們將決定自治系統內哪一個BGP路由器做爲鏈接點來負責接收來自自治系統外部的信息。有些自治系統僅僅做爲一個數據傳輸的通道,這些自治系統既不是數據的發起端,也不是數據的接收端。BGP協議必須與存在於這些自治系統內部的路由協議打交道,以使數據能正確經過它們。BGP協議的路由刷新消息由「網絡號:自治系統路徑」對所組成,每個自治系統路徑都是一系列自治系統的名字字符串,它記錄了通向最終目標所通過的網絡。BGP與RIP和OSPF的不一樣之處在於BGP使用TCP做爲其傳輸層協議。兩個運行BGP的系統之間創建一條TCP(端口179)鏈接,便是單播的路由協議,它們交換整個BGP路由表。從這個時候開始,在路由表發生變化時,再發送更新信號。BGP是一個距離向量協議,可是與(通告到目的地址跳數的)RIP不一樣的是,BGP列舉了到每一個目的地址的路由(自治系統到達目的地址的序列號)。這樣就排除了一些距離向量協議的問題。採用16bit數字表示自治系統標識。儘管BGP協議保持通向特定目標的全部路徑的路由選擇表,但在路由選擇刷新消息中僅僅說明最佳路徑。BGP協議的路由度量方法能夠是一個任意單位的數,它指明某一個特定路徑可供參考的程度,這些度量方法一般都是由網絡管理人員經過配置文件來設置。可參考的程度能夠基於任何數字準則,例如最終系統計數(計數越小時路徑越佳)、數據鏈路的類型。redis
BGP 的兩種鄰居——IBGP和EBGP,BGP的鄰居關係(或稱通訊對端/對等實體)是經過人工配置實現的,對等實體之間經過TCP(端口179)會話交互數據。BGP路由器會週期地發送19字節的保持存活keep-alive消息來維護鏈接(默認週期爲30秒)。在路由協議中,只有BGP使用TCP做爲傳輸層協議。同一個自治系統(AS)中的兩個或多個對等實體之間運行的BGP 被稱爲 IBGP(Internal/Interior BGP)。歸屬不一樣的AS的對等實體之間運行的BGP稱爲EBGP(External/Exterior BGP)。在AS邊界上與其餘AS交換信息的路由器被稱做邊界路由器(border/edge router)。在互聯網操做系統(Cisco IOS)中,IBGP通告的路由的距離爲200,優先級比EBGP和任何內部網關協議(IGP)通告的路由都低。其餘的路由器實現中,優先級順序也是EBGP高於IGP,而IGP又高於IBGP。在創建鄰居關係的時候,咱們都採用Loopback地址來創建,但要保證Loopback地址可達,採用Loopback地址創建的鄰居不會應爲鏈路的down而斷。網絡
IBGP路由通告:BGP Speaker 從IBGP得到的路由不會通告給它的IBGP鄰居(在必定的程度上能避免AS內的環路),就會形成不是與該路由器創建鄰居不能學到路由,解決方案:①採用全鏈接②採用RR反射器③採用聯盟的方式。負載均衡
EBGP路由通告:BGP Speaker 從EBGP得到的路由會向全部的BGP對等體通告(包括IBGP和EBGP)ide
咱們知道,在自治系統內部使用IGP路由協議;而在不一樣自治系統之間使用BGP路由協議,EBGP用於在不一樣自治系統之間,IBGP也是應用於自治系統內部,此時就要理解他們之間的關係:oop
IGP的能力限制,IGP處理路由的條目有限,而目前internet上核心路由器的路由表已經超過10萬條。假如沒有IBGP,那麼這些路由只能採起重分發的方式直接導入到IGP中,這樣作的缺點很明顯:第一,IGP協議的做者並無打算讓IGP來處理如此大量的路由,IGP自己也沒法處理這樣大的路由數量;第二,若是非要讓IGP來處理,那麼根據IGP的處理原則,假如這10萬路由中任何一條路由發生變化,那麼運行IGP的路由器就不得不從新計算路由這種計算量對於絕大多數路由器來講是沒法負擔的性能
路由環路的問題。BGP是靠路由屬性來防止路由環路的,例如AS_PATH屬性,假如說沒有IBGP協議,那麼當全部BGP路由重分發到IGP中後,路由屬性必然丟失,這就破壞了BGP的路由環路防止機制,產生了路由環路的隱患。學習
IBGP之間是TCP鏈接,也就意味着IBGP鄰居採用的是邏輯鏈接的方式,兩個IBGP鏈接不必定存在實際的物理鏈路。因此須要有IGP來提供路由,以完成BGP路由的遞歸查找。 BGP協議自己實際上並不發現路由,BGP將路由發現的工做所有移交給了IGP協議,它自己着重於路由的控制。所以,若是沒有IGP,那麼BGP也就毫無用處了。
EBGP與IBGP的區別:
路由環路的避免措施不同,IBGP強制規定ibgp speaker不容許把從一個ibgp鄰居學習到的前綴傳遞給其它ibgp鄰居,所以IBGP要求邏輯全鏈接。EBGP沒有這樣的要求,EBGP對路由環路的避免是經過AS_PATH屬性來實現的。
使用的BGP屬性不一樣,例如IBGP能夠傳遞LOCAL_PREF(本地優先屬性),而EBGP不行。
IBGP有同步的要求,而EBGP沒有同步的要求
IBGP不須要IBGP鄰居之間有物理鏈接,只須要邏輯鏈接便可,而EBGP下通常狀況下都要求EBGP鄰居之間存在物理鏈接。
BGP屬性:
路由器發送關於目標網絡的BGP更新消息,更新的度量值被稱爲路徑屬性。屬性能夠是公認的或可選的、強制的或自由決定的、傳遞的或非傳遞的。屬性也能夠是部分的。並不是組織的和有組合的都是合法的,路徑屬性分爲4類:公認必遵、公認自決、可選過渡、可選非過渡。其中公認必遵、公認自決爲
公認屬性;可選過渡、可選非過渡爲非公認屬性被稱爲可選的,可選屬性能夠是傳遞的或非傳遞的,可選屬性不要求全部的BGP實現都支持。對於不支持的可選傳遞屬性,路由器將其原封不動的傳遞給其餘BGP路由器,在這種狀況下,屬性被標記爲部分的。對於可選非傳遞屬性,路由器必須將其刪除,而不將其傳遞給其餘BGP路由器。
(1)公認必遵(Well-Known Mandatory)是公認全部BGP實現都必須識別的屬性,這些屬性被傳遞給BGP鄰居。公認強制屬性必須出如今路由描述中,公認自由決定屬性能夠不出如今路由描述中,以下:
ORIGIN(起源):這個屬性說明了源路由是怎樣放到BGP表中的。有三個可能的源IGP,EGP,以及INCOMPLETE.路由器在多個路由選擇的處理中使用這個信息。路由器選擇具備最低ORIGIN類型的路徑。
AS_PATH(AS路徑):指出包含在UPDATE報文中的路由信息所通過的自治系統的序列。
Next_HOP(下一跳)聲明路由器所得到的BGP路由的下一跳,對EBGP會話來講,下一跳就是通告該路由的鄰居路由器的源地址。
(2)公認自決(Well-Known Discretionary)
LOCAL_PREF(本地優先級):本地優先級屬性是用於告訴自治系統內的路由器在有多條路徑的時候,怎樣離開自治系統。本地優先級越高,路由優先級越高。
ATOMIC_AGGREGATE(原子聚合):原子聚合屬性指出已被丟失了的信息。
(3)可選過渡(Optional Transitive)
AGGREGATOR(聚合者):此屬性標明瞭實施路由聚合的BGP路由器ID和聚合路由的路由器的AS號。
COMMUNITY(團體):此屬性指共享一個公共屬性的一組路由器。
(4)可選非過渡(Optional Nontransitive)
MED(多出口區分):該屬性通知AS之外的路由器採用哪一條路徑到達AS,它也被認爲是路由的外部度量,低MED值表示高的優先級。
ORIGINATOR_ID(起源ID):路由反射器會附加到這個屬性上,它攜帶本AS路由器的路由器ID,用以防止環路。
CLUSTER_LIST(簇列表):此屬性顯示了採用的反射路徑。
BGP術語
BGP兩個版本:BGP4因特網上所用的主要區域間路由選擇協議的第4版,它支持CIDR並使用路由集合機制減少路由表的大小;BGP4+使BGP4可以支持多種網絡層協議,如IPv6和IPX等
BGP鄰居就是BGP對等體(peer),BGP鄰居關係就是對等體關係。每一個鄰居都要手動指定。在大規模網絡中十分麻煩
BGP Peer Group它至關因而一個容器,這個容器擁有着BGP參數和策略,只要將BGP鄰居放入這個容器中,那麼該鄰居便可得到容器的全部參數和策略,從而大大簡化爲每一個鄰居重複配置相同參數和策略。Peer Group惟一的限制就是,同一個Peer Group中的全部鄰居,必須所有爲iBGP鄰居,或者所有爲eBGP鄰居,也就是說不能將iBGP鄰居和eBGP鄰居同時混雜在同一個Peer Group中,可是若是所有都爲eBGP鄰居,這些鄰居能夠是任意AS的,而沒必要全部鄰居都是同一個AS的。在使用Peer Group配置鄰居後,能夠對Peer Group配置參數和策略,也能夠對Peer Group中的單個鄰居配置參數和策略。Peer Group配置減小工做量的同時,也能保證鄰居策略的多樣化。
BGP團體:能夠簡化路由策略的管理,使多個AS中的一組BGP路由器共享相同的策略。團體是一個路由屬性,在BGP對等體之間傳播,它並不受到AS範圍的限制。
路由反射器:爲保證IBGP對等體之間的連通性,須要在IBGP對等體之間創建全鏈接關係。假設在一個AS內部有n臺路由器,那麼應該創建的IBGP鏈接數就爲n(n-1)/2。當IBGP對等體數目不少時,對網絡資源和CPU資源的消耗都很大。利用路由反射能夠解決這一問題。在一個AS內,其中一臺路由器做爲路由反射器RR(Route Reflector),其它路由器做爲客戶機(Client)與路由反射器之間創建IBGP鏈接。路由反射器在客戶機之間傳遞(反射)路由信息,而客戶機之間不須要創建BGP鏈接。既不是反射器也不是客戶機的BGP路由器被稱爲非客戶機(Non-Client)。非客戶機與路由反射器之間,以及全部的非客戶機之間仍然必須創建全鏈接關係。路由反射器和它的客戶機組成了一個集羣(Cluster)。某些狀況下,爲了增長網絡的可靠性和防止單點故障,能夠在一個集羣中配置一個以上的路由反射器。這時,位於相同集羣中的每一個路由反射器都要配置相同的Cluster_ID,以免路由循環。
聯盟:處理AS內部的IBGP網絡鏈接激增的另外一種方法,它將一個自治系統劃分爲若干個子自治系統,每一個子自治系統內部的IBGP對等體創建全鏈接關係,子自治系統之間創建聯盟內部EBGP鏈接關係。在不屬於聯盟的BGP發言者看來,屬於同一個聯盟的多個子自治系統是一個總體,外界不須要了解內部的子自治系統狀況,聯盟ID就是標識聯盟這一總體的自治系統號。聯盟的缺陷是:從非聯盟方案向聯盟方案轉變時,要求路由器從新進行配置,邏輯拓撲也要改變。
BGP三種路由類型
AS間路由發生在不一樣AS的兩個或多個BGP路由器之間,這些系統的對等路由器使用BGP來維護一致的網絡拓撲視圖,AS間通訊的BGP鄰居必須處於相同的物理網絡。因特網就是使用這種路由的實例,由於它由多個AS(或稱管理域)構成,許多域爲構成因特網的研究機構、公司和實體。BGP常常用於爲因特網內提供最佳路徑而作路由選擇。
AS內部路由發生在同一AS內的兩個或多個BGP路由器間,同一AS內的對等路由器用BGP來維護一致的系統拓撲視圖。BGP也用於決定哪一個路由器做爲外部AS的鏈接點。再次重申,因特網提供了AS間路由的實例。一個組織,如大學,能夠利用BGP在其本身的管理域(或稱AS)內提供最佳路由。BGP協議既能夠提供AS間也能夠提供AS內部路由。
貫穿(pass-through)AS路由發生在經過不運行BGP的AS交換數據的兩個或多個BGP對等路由器間。在貫穿AS環境中,BGP通訊既不源自AS內,目的也不在該AS內的節點,BGP必須與AS內使用的路由協議交互以成功地經過該AS傳輸BGP通訊
8、BGP路由更新:與其它路由協議同樣,BGP維護路由表、發送路由更新信息且基於路由metric決定路由。BGP系統的主要功能是交換其它BGP系統的網絡可達信息,包括AS路徑的列表信息,此信息可用於創建AS系統鏈接圖,以消除路由環,及執行AS策略肯定。
每一個BGP路由器維護到特定網絡的全部可用路徑構成的路由表,可是它並不清除路由表,它維持從對等路由器收到的路由信息直到收到增值(incremental)更新。
BGP設備在初始數據交換和增值更新後交換路由信息。當路由器第一次鏈接到網絡時,BGP路由器交換它們的整個BGP路由表,相似的,當路由表改變時,路由器發送路由表中改變的部分。BGP路由器並不週期性發送路由更新,且BGP路由更新只包含到某網絡的最佳路徑。
BGP用單一的路由metric決定到給定網絡的最佳路徑。這一metric含有指定鏈路優先級的任意單元值,BGP的metric一般由網管賦給每條鏈路。賦給一條鏈路的值能夠基於任意數目的尺度,包括途經的AS數目、穩定性、速率、延遲或代價等。
9、BGP消息類型
初始消息在對等路由器間打開一個BGP通訊會話,是創建傳輸協議後發送的第一個消息,初始消息由對等設備發送的keep-alive消息確認,且必須獲得確認後才能夠交換更新、通知和keep-alive消息。
更新消息用於提供到其它BGP系統的路由更新,使路由器能夠創建網絡拓撲的一致視圖。更新用TCP發送以保證傳輸的可靠性。 更新消息能夠從路由表中清除一條或多條失效路由,同時發佈若干路由。
通知消息在檢查到有錯誤時發送。通知消息用於關閉一條活動的會話,並通知其它路由器爲什麼關閉該會話。
keep-alive消息通知對等BGP路由器該設備仍然alive。keep-alive消息發佈足夠頻繁以防止會話過時
10、BGP數據包分組
標記 - 含有認證值。
長度 - 指示消息的總長度,以字節計。
類型 - 標識消息類型爲下列類型之一: 初始 、更新 、通知 、keep-alive 、數據(爲可選域,含有上層信息)
初始消息格式:BGP初始消息由BGP信頭和附加域構成,在信頭的類型域中標識爲BGP初始消息的BGP分組包含下列各域,這些域爲兩個BGP路由器創建對等關係提供了交換方案:
版本 - 提供BGP版本號,使接收者能夠確認它是否與發送者運行同一版本協議。自治系統 - 提供發送者的AS號。
保持時間(Hold-time)- 在發送者被認爲失效前最長的不接收消息的秒數。
BGP標識 - 提供發送者的標識(IP地址),在啓動時決定,對全部本地接口和全部對等BGP路由器而言都是相同的。
可選參數長度 - 標識可選參數域的長度(若是存在的話)。
可選參數 - 包含一組可選參數。目前只定義了一個可選參數類型:認證信息。認證信息含有下列兩個域:
認證碼:標識使用的認證類型。
認證數據:包含由認證機制使用的數據。
C)更新消息格式:BGP更新消息由BGP信頭和附加域構成,收到更新消息分組後,路由器就能夠從其路由表中增長或刪除指定的表項以保證路由的準確性。更新消息包含下列域:
失效路由長度 - 標識失效路由域的總長度或該域不存在。
失效路由 - 包含一組失效路由的IP地址前綴。
總路徑屬性長度 - 標識路徑屬性域的總長度或該域不存在。
路徑屬性 - 描述發佈路徑的屬性,可能的值以下:
源:必選屬性,定義路徑信息的來源。
AS路徑:必選屬性,由一系列AS路徑段組成。
下一跳:必選屬性,定義了在網絡層可達信息域中列出的應用做到目的地下一跳的邊
緣路由器的IP地址。
多重出口區分:可選屬性,用於在到相鄰AS的多個出口間進行區分。
本地優先權:可選屬性,用以指定發佈路由的優先權等級。
原子聚合:可選屬性,用於發佈路由選擇信息。
聚合:可選屬性,包含聚合路由信息。
網絡層可達信息 - 包含一組發佈路由的IP地址前綴。
D)通知消息格式:通知消息分組用於給對等路由器通知某種錯誤狀況。
錯誤碼 - 標識發生的錯誤類型。下面爲定義的錯誤類型:
消息頭錯:指出消息頭出了問題,如不可接受的消息長度、標記值或消息類型。
初始消息錯:指出初始消息出了問題,如不支持的版本號,不可接受的AS號或IP地址或
不支持的認證碼。
更新消息錯:指更新消息出了問題,如屬性列表殘缺、屬性列表錯誤或無效的下一跳屬性。
保持時間過時:指出保持時間已過時,這以後BGP節點就被認爲已失效。
有限狀態機錯:指示指望以外的事件。
終止:發生嚴重錯誤時根據BGP設備的請求關閉BGP鏈接。
錯誤子碼 - 提供關於報告的錯誤的更具體的信息。
錯誤數據 - 包含基於錯誤碼和錯誤子碼域的數據,用於檢測通知消息發送的緣由。
11、BGP鄰居協商創建會話的5種狀態:
Idle:查找路由表,該過程BGP對它的資源進行初始化,復位一個鏈接重試計時器, 發起一條TCP 鏈接,並開始傾聽遠程對等體所發起的鏈接。
Connect:找到路由表後進行TCP三次握手,TCP 鏈接成功,則轉到OpenSent狀態,TCP鏈接失敗,則轉到active 狀態,將嘗試再次鏈接。
Open Sent:握上手後發送Open message消息,等待其對等體發送打開消息,若是出錯,則發送一條出錯消息並退回空閒狀態,若是無錯,則開始發送Keepalive 並復位keepalive 計時器。
Open Confirm:收到對方發來的Open消息,若是收到keepalive 消息,BGP 就進入established狀態,鄰居關係協商完成;若是系統收到一條更新或keepalive 消息,它將從新啓動保持計時器;若是收到Notification消息,BGP 就退回到空閒狀態。
Established:會話創建,鄰居關係協商過程最終狀態;這時BGP將開始與它的對等體交換路由更新數據包。
BGP協議的特色
BGP是一種AS(自治區域)外部路由協議,主要負責本自治區域和外部的自治區域間的路由可達信息的交換。所以,它所關心的拓撲結構是AS(自治區域)的拓撲結構,BGP經過UPDATE消息中路由的AS屬性來構造AS的拓撲結構圖,進一步經過此結構圖來選擇路由。
與OSPF,RIP等IGP協議相比,BGP的拓撲圖要更抽象和粗略一些。由於IGP協議構造的是AS內部的路由器的拓撲結構圖。IGP把路由器抽象成若干端點,把路由器之間的鏈路抽象成邊,根據鏈路的狀態等參數和必定的度量標準,每條邊配以必定的權值,生成拓撲圖。根據此拓撲圖選擇代價(兩點間通過的邊的權值和)最小的路由。這裏有一個假設,即路由器(端點)轉發數據包是沒有的代價的。而在BGP中,拓撲圖的端點是一個AS區域,邊是AS之間的鏈路。此時,數據包通過一個端點(AS自治區域)時的代價就不能假設爲0了,此代價要由IGP來負責計算。這體現了EGP和IGP是分層的關係。即IGP負責在AS內部選擇花費最小的路由,EGP負責選擇AS間花費最小的路由。BGP做爲EGP的一種,選擇路由時考慮的是AS間的鏈路花費,AS區域內的花費(由BGP路由器配置)等因素。
如上所述,內部網關協議IGP需引入AS自治區域內部網絡拓撲圖其它各點的路由,同時向其它端點發送本端點(路由器)所知的路由,如直接路由、靜態路由等。做爲外部網關協議,BGP發送和引入路由的單位是整個AS自治區域,即BGP要發送本地路由器所在的AS內部的全部路由,引入其它AS自治區域的全部路由(假設不使用路由策略控制發送和引入)。其路由數量顯然要遠遠大於IGP發送和引入的路由數量。所以,相似於IGP那樣定時對外廣播路由信息是不可取的。BGP採用發送路由增量(Incremental)的方法,完成所有路由信息的通告和維護:初始化時發送全部的路由給BGP對端(BGP Peer),同時在本地保存了已經發送給BGP對端的路由信息。當本地的BGP收到了一條新路由時(如經過IGP注入了新路由或加入了新的靜態路由),與保存的已發送信息進行比較,如未發送過,則發送,如已發送過則與已經發送的路由進行比較,如新路由花費更小,則發送此新路由,同時更新已發送信息,反之則不發送。當本地BGP發現一條路由失效時(如對應端口失效),如此路由已發送過,則向BGP對端發送一個退出路由消息。
BGP遇到的挑戰和限制
(1)I-BGP的Full-Mesh問題: BGP路由協議分爲I-BGP和E-BGP兩個部分。I-BGP用於自治域內的路由器之間,E-BGP用於自治域間的路由器之間。若是一個AS內部存在非bgp路由器,那麼就出現了BGP和IGP的邊界,須要在邊界路由器將BGP路由發佈到igp中,才能保證AS所通告到外部的BGP路由在AS內部是連通的.其實是要求BGP路由和igp路由的同步。若是將BGP路由發佈到igp中,因爲BGP路由主要是來自AS外部的路由(來自internet),那麼結果是igp路由器要維護數以萬計的外部路由,對路由器的CPU和memeory以及AS內部的鏈路帶寬的佔用將帶來巨大的開銷. 所以AS內部全部路由器應儘量運行fullmesh iBGP,就能夠關閉全部路由器的同步而不影響路由的通告和連通性.。可是此時另外一個問題來了,當AS內部路由器數量不少時,須要創建N*(N-1)/2個ibgp會話,帶來過分的系統開銷,擴展性很差,目前這個問題解決辦法有兩種:聯盟和路由反射。 另外爲避免在AS內部的循環路由,BGP不會向內部BGP PEER通告它從其餘內部BGP PEER中得到的路由,此時利用路由反射能夠解決這一問題。在一個AS內,其中一臺路由器做爲路由反射器RR(Route Reflector),其它路由器做爲客戶機(Client)與路由反射器之間創建IBGP鏈接。路由反射器在客戶機之間傳遞(反射)路由信息,而客戶機之間不須要創建BGP鏈接。
(2)更改路由策略時路由振盪的問題 : BGP屬於增量更新的路由協議,當有新的路由要發佈時,路由器會向鄰居發送Update信息,而若是要刪除某條路由時,就會發送Withdraw信息。BGP路由的Flap的定義是:當一條路由在被收回(Withdraw)後,又被廣播(Update)出來,視爲一次Flap。因爲任何一條路由的收回和更新都會致使一臺路由器整個路由表從新計算,所以當Flap的狀況比較多時,對路由器設備的負載將產生巨大的壓力。根據筆者在實際工做中的經驗,通常狀況下,一臺高端路由器在計算BGP路由的時候,CPU的負載基本上在80%~90%左右,有時甚至達到100%,佔用了幾乎全部的CPU資源。雖然目前大部分的高端路由器都將路由計算的模塊與轉發模塊分佈在不一樣的硬件上,來減小主CPU忙致使的路由器性能降低的問題,可是路由表的頻繁變化和更新,對整個設備的運行仍是有必定的影響的,並且這樣的計算會隨着路由的收回或廣播,繼續向自治域內部擴展,使內部的路由器產生一樣的問題。目前解決的辦法:Damping
(3)其餘因素影響路由器的性能: 如路由的數目、BGP路由表的大小和路由計算的方式等 另外,網絡越大,路由條目越多,配置和管理的工做也就越複雜,這就須要在網絡設計的時候儘可能簡化配置,下降管理人員的工做強度,避免人爲緣由形成故障。解決辦法有: peer group 、路由聚合
實驗一:BGP基本配置
R1配置:
R1#conf t
R1(config)#int s0/0
R1(config-if)#ip add 192.168.12.1255.255.255.0
R1(config-if)#clock rate 64000
R1(config-if)#ip router isis //將接口宣告到ISIS路由進程
R1(config-if)#no sh
R1(config-if)#exit
R1(config)#router isis //開啓ISIS內部路由協議
R1(config-router)#net49.0001.1111.1111.1111.00
R1(config-router)#exit
R1(config)#router bgp 65501 //開啓bgp進程,自治號位65501
R1(config-router)#no synchronization //關閉同步
R1(config-router)#network 192.168.12.0 mask255.255.255.0 //宣告網絡到BGP進程
R1(config-router)#neighbor192.168.12.2 remote-as 65501 //手動配置R2爲鄰居
R1(config-router)#neighbor192.168.23.2 remote-as 65501 //手動配置R3爲鄰居
R2配置:
R2#conft
R2(config)#ints0/0
R2(config-if)#ipadd 192.168.12.2 255.255.255.0
R2(config-if)#iprouter isis
R2(config-if)#clockrate 64000
R2(config-if)#nosh
R2(config-if)#exit
R2(config)#ints0/1
R2(config-if)#ipadd 192.168.23.1 255.255.255.0
R2(config-if)#clockrate 64000
R2(config-if)#iprouter isis
R2(config-if)#nosh
R2(config-if)#exit
R2(config)#routerisis
R2(config-router)#net49.0001.2222.2222.2222.00
R2(config-router)#exit
R2(config)#routerbgp 65501
R2(config-router)#nosynchronization
R2(config-router)#net192.168.12.0 mask 255.255.255.0
R2(config-router)#net192.168.23.0 mask 255.255.255.0
R2(config-router)#neighbor192.168.12.1 remote-as 65501
R2(config-router)#neighbor192.168.23.2 remote-as 65501
R3配置:
R3#conft
R3(config)#ints0/0
R3(config-if)#ipadd 192.168.23.2 255.255.255.0
R3(config-if)#iprouter isis
R3(config-if)#clockrate 64000
R3(config-if)#nosh
R3(config-if)#exit
R3(config)#ints0/1
R3(config-if)#ipadd 192.168.34.1 255.255.255.0
R3(config-if)#iprouter isis
R3(config-if)#clockrate 64000
R3(config-if)#nosh
R3(config-if)#exit
R3(config)#routerisis
R3(config-router)#net49.0001.3333.3333.3333.00
R3(config-router)#exit
R3(config)#routerbgp 65501
R3(config-router)#nosyn
R3(config-router)#net192.168.23.0 mask 255.255.255.0
R3(config-router)#net192.168.34.0 mask 255.255.255.0
R3(config-router)#nei192.168.12.1 remote-as 65501
R3(config-router)#nei192.168.23.1 remote-as 65501
R3(config-router)#nei192.168.34.2 remote-as 65502
R4配置:
R4#conft
R4(config)#ints0/0
R4(config-if)#ipadd 192.168.34.2 255.255.255.0
R4(config-if)#clockrate 64000
R4(config-if)#nosh
R4(config-if)#exit
R4(config)#intlo 0
R4(config-if)#ipadd 4.4.4.4 255.255.255.255
R4(config-if)#exit
R4(config)#routerbgp 65502
R4(config-router)#nosyn
R4(config-router)#net4.4.4.4 mask 255.255.255.255
R4(config-router)#net192.168.34.0 mask 255.255.255.0
R4(config-router)#nei192.168.34.1 remote-as 65501
R4(config-router)#exit
完成以上配置後,全網互通就能夠互通了,此時咱們查看下R1和R4的路由表,發現有一條帶B標記的路由到達對方。同時查看BGP鄰居
R1#ship rou
Codes:C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O -OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 -OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPFexternal type 2
i - IS-IS, su - IS-IS summary, L1 -IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidatedefault, U - per-user static route
o - ODR, P - periodic downloaded staticroute
Gatewayof last resort is not set
C 192.168.12.0/24 is directly connected,Serial0/0
4.0.0.0/32 is subnetted, 1 subnets
B 4.4.4.4 [200/0] via192.168.34.2, 00:20:09
iL1 192.168.23.0/24 [115/20] via 192.168.12.2, Serial0/0
iL1 192.168.34.0/24 [115/30] via 192.168.12.2, Serial0/0
R1#ship bgp summary
BGProuter identifier 192.168.12.1, local AS number 65501
BGPtable version is 9, main routing table version 9
4network entries using 468 bytes of memory
6path entries using 312 bytes of memory
4/3BGP path/bestpath attribute entries using 496 bytes of memory
1BGP AS-PATH entries using 24 bytes of memory
0BGP route-map cache entries using 0 bytes of memory
0BGP filter-list cache entries using 0 bytes of memory
BGPusing 1300 total bytes of memory
BGPactivity 4/0 prefixes, 6/0 paths, scan interval 60 secs
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
192.168.12.2 465501 61 60 9 0 0 00:55:01 2
192.168.23.2 465501 48 46 9 0 0 00:41:44 3
分析:
在自治區域65501內各路由器經過ISIS路由協議,創建到達彼此的路由條目。而後各路由器開啓BGP協議,BGP協議根據路由表與其餘路由器創建iBGP對等體關係(鄰居),彼此交互路由信息。接着R3與物理連接的R4上的自治區域65502的BGP協議創建EBGP關係,彼此交換路由信息。
實驗2、使用環回口創建IBGP鄰居關係
其實IBGP和EBGP均可以用環回口或者物理接口創建鄰居,可是一般EBGP用物理接口創建鄰居,由於EBGP之間牽扯到多跳的問題,且EBGP鄰居之間沒有任何IGP協議的支持,因此環回口是不可達的,雖然能夠在臨界路由器上配置一條默認路由來可達,可是還要配置nei x.x.x.x 的多跳,由於EBGP默認只傳一跳。
對於IBGP之間,由於有IGP的協議支持,因此環回口都是可達的,最重要的就是環回口的穩定性大大優於物理接口。 並且使用環回接口能夠充分利用鄰居間的多條鏈路實現冗餘
R1配置:
R1#conf t
R1(config)#int s0/0
R1(config-if)#ip add 192.168.12.1255.255.255.0
R1(config-if)#clock rate 64000
R1(config-if)#ip router isis //將接口宣告到ISIS路由進程
R1(config-if)#no sh
R1(config-if)#exit
R1(config)#int s0/1
R1(config-if)#ip add 192.168.13.1255.255.255.0
R1(config-if)#clock rate 64000
R1(config-if)#ip router isis
R1(config-if)#no sh
R1(config)#int lo0
R1(config-if)#ip add 1.1.1.1255.255.255.255
R1(config-if)#ip router isis
R1(config-if)#exit
R1(config)#router isis //開啓ISIS內部路由協議
R1(config-router)#net49.0001.1111.1111.1111.00
R1(config-router)#exit
R1(config)#router bgp 65501 //開啓bgp進程,自治號位65501
R1(config-router)#bgp router-id 1.1.1.1 //設置BGP路由ID
R1(config-router)#no synchronization //關閉同步
R1(config-router)#network 192.168.12.0 mask255.255.255.0 //宣告網絡到BGP進程
R1(config-router)#network 192.168.13.0 mask 255.255.255.0////宣告網絡到BGP進程
R1(config-router)#nei2.2.2.2 remote-as 65501 //指定與R2環回口創建鄰居
R1(config-router)#nei2.2.2.2 update-source loopback 0//指定本端更新端口爲環回口
R1(config-router)#nei2.2.2.2 next-hop-self //要求下一跳更新源
R1(config-router)#nei3.3.3.3 remote-as 65501//指定與R3環回口創建鄰居
R1(config-router)#nei3.3.3.3 update-source loopback 0//指定本端更新端口爲環回口
R1(config-router)#NEI3.3.3.3 next-hop-self //要求下一跳更新源
R2配置:
R2#conft
R2(config)#ints0/0
R2(config-if)#ipadd 192.168.12.2 255.255.255.0
R2(config-if)#iprouter isis
R2(config-if)#clockrate 64000
R2(config-if)#nosh
R2(config-if)#exit
R2(config)#ints0/1
R2(config-if)#ipadd 192.168.23.1 255.255.255.0
R2(config-if)#clockrate 64000
R2(config-if)#iprouter isis
R2(config-if)#nosh
R2(config-if)#exit
R2(config)#intlo0
R2(config-if)#ipadd 2.2.2.2 255.255.255.255
R2(config-if)#iprouter isis
R2(config-if)#exit
R2(config)#routerisis
R2(config-router)#net49.0001.2222.2222.2222.00
R2(config-router)#exit
R2(config)#routerbgp 65501
R2(config-router)#bgprouter-id 2.2.2.2
R2(config-router)#nosynchronization
R2(config-router)#net192.168.12.0 mask 255.255.255.0
R2(config-router)#net192.168.23.0 mask 255.255.255.0
R2(config-router)#nei1.1.1.1 remote-as 65501
R2(config-router)#nei1.1.1.1 update-source loopback 0
R2(config-router)#nei1.1.1.1 next-hop-self
R2(config-router)#nei3.3.3.3 remote-as 65501
R2(config-router)#nei3.3.3.3 update-source loopback 0
R2(config-router)#nei3.3.3.3 next-hop-self
R3配置:
R3#conft
R3(config)#ints0/0
R3(config-if)#ipadd 192.168.23.2 255.255.255.0
R3(config-if)#iprouter isis
R3(config-if)#clockrate 64000
R3(config-if)#nosh
R3(config-if)#exit
R3(config)#ints0/1
R3(config-if)#ipadd 192.168.34.1 255.255.255.0
R3(config-if)#iprouter isis
R3(config-if)#clockrate 64000
R3(config-if)#nosh
R3(config-if)#exit
R3(config)#intlo0
R3(config-if)#ipadd 3.3.3.3 255.255.255.255
R3(config-if)#iprouter isis
R3(config-if)#exit
R3(config)#routerisis
R3(config-router)#net49.0001.3333.3333.3333.00
R3(config-router)#exit
R3(config)#routerbgp 65501
R3(config-router)#bgprouter-id 3.3.3.3
R3(config-router)#nosyn
R3(config-router)#net192.168.23.0 mask 255.255.255.0
R3(config-router)#net192.168.34.0 mask 255.255.255.0
R3(config-router)#net192.168.13.0 mask 255.255.255.0
R3(config-router)#nei1.1.1.1 remote-as 65501
R3(config-router)#nei1.1.1.1 update-source loopback 0
R3(config-router)#nei1.1.1.1 next-hop-self
R3(config-router)#nei2.2.2.2 remote-as 65501
R3(config-router)#nei2.2.2.2 update-source loopback 0
R3(config-router)#nei2.2.2.2 next-hop-self
R3(config-router)#nei192.168.34.2 remote-as 65502
R4配置:
R4#conft
R4(config)#ints0/0
R4(config-if)#ipadd 192.168.34.2 255.255.255.0
R4(config-if)#clockrate 64000
R4(config-if)#nosh
R4(config-if)#exit
R4(config)#intlo 0
R4(config-if)#ipadd 4.4.4.4 255.255.255.255
R4(config-if)#exit
R4(config)#routerbgp 65502
R4(config-router)#nosyn
R4(config-router)#net4.4.4.4 mask 255.255.255.255
R4(config-router)#net192.168.34.0 mask 255.255.255.0
R4(config-router)#nei192.168.34.1 remote-as 65501
R4(config-router)#exit
此時全網已經互通,而且查看R1的BGP鄰居:
R1#ship bgp summary
BGProuter identifier 1.1.1.1, local AS number 65501
BGPtable version is 31, main routing table version 31
5network entries using 585 bytes of memory
8path entries using 416 bytes of memory
4/3BGP path/bestpath attribute entries using 496 bytes of memory
1BGP AS-PATH entries using 24 bytes of memory
0BGP route-map cache entries using 0 bytes of memory
0BGP filter-list cache entries using 0 bytes of memory
BGPusing 1521 total bytes of memory
BGPactivity 15/10 prefixes, 22/14 paths, scan interval 60 secs
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
2.2.2.2 4 65501 201 197 31 0 0 03:12:37 2
3.3.3.3 4 65501 207 207 31 0 0 03:20:41 4
實驗3、去掉私有AS
R1配置:
R1#conf t
R1(config)#int lo0
R1(config-if)#ip add 1.1.1.1 255.255.255.0
R1(config-if)#exit
R1(config)#int s0/0
R1(config-if)#clock rate 64000
R1(config-if)#ip add 192.168.12.1 255.255.255.0
R1(config-if)#no sh
R1(config-if)#exit
R1(config)#router bgp 65501
R1(config-router)#bgp router-id 1.1.1.1
R1(config-router)#net 192.168.12.0 mask 255.255.255.0
R1(config-router)#net 1.1.1.0 mask 255.255.255.0
R1(config-router)#nei 192.168.12.2 remote-as 100
R2配置:
R2#conf t
R2(config)#int s0/0
R2(config-if)#clock rate 64000
R2(config-if)#ip add 192.168.12.2 255.255.255.0
R2(config-if)#no sh
R2(config-if)#exit
R2(config)#int s0/1
R2(config-if)#clock rate 64000
R2(config-if)#ip add 192.168.23.1 255.255.255.0
R2(config-if)#no sh
R2(config-if)#exit
R2(config)#router bgp 100
R2(config-router)#bgp router-id 2.2.2.2
R2(config-router)#net 192.168.12.0 mask 255.255.255.0
R2(config-router)#net 192.168.23.0 mask 255.255.255.0
R2(config-router)#nei 192.168.12.1 remote-as 65501
R2(config-router)#nei 192.168.23.2 remote-as 200
R3配置:
R3#conf t
R3(config)#int s0/0
R3(config-if)#clock rate 64000
R3(config-if)#ip add 192.168.23.2 255.255.255.0
R3(config-if)#no sh
R3(config-if)#exit
R3(config)#router bgp 200
R3(config-router)#bgp router-id 3.3.3.3
R3(config-router)#net 192.168.23.0 mask 255.255.255.0
R3(config-router)#nei 192.168.23.1 remote-as 100
完成配置後,此時全網互通正常,咱們來看看R3的BGP路由表,
R3#sh ip bgp
BGP table version is 5, 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 192.168.23.1 0 100 65501 i
*> 192.168.12.0 192.168.23.1 0 0 100 i
* 192.168.23.0 192.168.23.1 0 0 100 i
*> 0.0.0.0 0 32768 i
此時會發現AS65501這個私有自治號(AS大於65500的都是私有).注意在公網上是不能有私有AS號的 ,此時咱們使用neighbor x.x.x.x remove-private-as 命令能夠強制BGP丟棄私有AS編號,一般這個命令配置在外部的BGP鄰居上,當向外發佈的更新路由中含有私有AS編號的時候,這個私有的AS編號將被過濾,而後再次查看R3的BGP路由表
R2#conf t
R2(config)#router bgp 100
R2(config-router)#nei 192.168.23.2remove-private-as
R2(config-router)#do clear ip bgp * soft out
R3#sh ip bgp
BGP table version is 6, 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 192.168.23.1 0 100 i
*> 192.168.12.0 192.168.23.1 0 0 1 00 i
* 192.168.23.0 192.168.23.1 0 0 100 i
*> 0.0.0.0 0 32768 i
當配置這條命令的時候須要注意如下的幾個注意事項.
這條命令只能使用在EBGP的鄰居上
若是更新路由中只含有私有的AS編號那麼BGP會過濾掉這些私有編號
若是在AS_PATH路徑中既包含私有的又包含公有的AS編號那麼BGP將不會對私有的AS編號進行過濾
若是在AS_PATH中包含有EBGP鄰居的AS編號那麼BGP也不會將私有的AS編號進行過濾
若是AS_PATH 包含聯盟那麼只有當私有AS編號出如今聯盟後面的時候BGP纔會將私有的AS編號清除
實驗4、BGP的Weight屬性 (Cisco私有)
R1配置:
R1#conf t
R1(config)#int lo0
R1(config-if)#ip add 1.1.1.1 255.255.255.0
R1(config-if)#exit
R1(config)#int s0/0
R1(config-if)#ip add 192.168.12.1 255.255.255.0
R1(config-if)#clock rate 64000
R1(config-if)#no sh
R1(config-if)#exit
R1(config)#int s0/1
R1(config-if)#ip add 192.168.13.1 255.255.255.0
R1(config-if)#clock rate 64000
R1(config-if)#no sh
R1(config-if)#exit
R1(config)#router bgp 100
R1(config-router)#bgp router-id 1.1.1.1
R1(config-router)#net 1.1.1.0 mask 255.255.255.0
R1(config-router)#net 192.168.12.0 mask 255.255.255.0
R1(config-router)#net 192.168.13.0 mask 255.255.255.0
R1(config-router)#nei 192.168.12.2 remote-as 200
R1(config-router)#nei 192.168.13.2 remote-as 200
R2配置:
R2#conf
R2(config)#int s0/0
R2(config-if)#clock rate 64000
R2(config-if)#ip add 192.168.12.2 255.255.255.0
R2(config-if)#no sh
R2(config-if)#exit
R2(config)#int s0/1
R2(config-if)#clock rate 64000
R2(config-if)#ip add 192.168.24.1 255.255.255.0
R2(config-if)#no sh
R2(config-if)#exit
R2(config)#router bgp 200
R2(config-router)#bgp router-id 2.2.2.2
R2(config-router)#net 192.168.12.0 mask 255.255.255.0
R2(config-router)#net 192.168.24.0 mask 255.255.255.0
R2(config-router)#nei 192.168.12.1 remote-as 100
R2(config-router)#nei 192.168.24.2 remote-as 200
R2(config-router)#nei 192.168.24.2 remote-as 200
R3配置:
R3#conf t
R3(config)#int s0/0
R3(config-if)#clock rate 64000
R3(config-if)#ip add 192.168.13.2 255.255.255.0
R3(config-if)#no sh
R3(config-if)#exit
R3(config)#int s0/1
R3(config-if)#ip add 192.168.34.1 255.255.255.0
R3(config-if)#clock rate 64000
R3(config-if)#no sh
R3(config-if)#exit
R3(config)#router bgp 200
R3(config-router)#bgp router-id 3.3.3.3
R3(config-router)#net 192.168.13.0 mask 255.255.255.0
R3(config-router)#net 192.168.34.0 mask 255.255.255.0
R3(config-router)#nei 192.168.13.1 remote-as 100
R3(config-router)#nei 192.168.34.2 remote-as 200
R4配置:
R4#conf t
R4(config)#int s0/0
R4(config-if)#clock rate 64000
R4(config-if)#ip add 192.168.24.2 255.255.255.0
R4(config-if)#no sh
R4(config-if)#exit
R4(config)#int s0/1
R4(config-if)#ip add 192.168.34.2 255.255.255.0
R4(config-if)#clock rate 64000
R4(config-if)#no sh
R4(config-if)#exit
R4(config)#router bgp 200
R4(config-router)#bgp router-id 4.4.4.4
R4(config-router)#net 192.168.24.0 mask 255.255.255.0
R4(config-router)#net 192.168.34.0 mask 255.255.255.0
R4(config-router)#nei 192.168.24.1 remote-as 200
R4(config-router)#nei 192.168.34.1 remote-as 200
查看R4的BGP路由表,咱們發現R4到1.1.1.1的網絡走的是R2.
R4#sh ip bgp
BGP table version is 9, 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 192.168.12.1 0 100 0 100 i
* i 192.168.13.1 0 100 0 100 i
*>i192.168.12.0 192.168.24.1 0 100 0 i
* i 192.168.13.1 0 100 0 100 i
* i192.168.13.0 192.168.12.1 0 100 0 100 i
*>i 192.168.34.1 0 100 0 i
* i192.168.24.0 192.168.24.1 0 100 0 i
*> 0.0.0.0 0 32768 i
* i192.168.34.0 192.168.34.1 0 100 0 i
*> 0.0.0.0 0 32768 i
此時經過調整Weight來改變選路,使R4到1.1.1.1網絡走R3,而後查看R4
R4#conf t
R4(config)#router bgp 200
R4(config-router)#nei 192.168.34.1 weight 100 //設置此鄰居傳過來的bgp路由的權重設置成100.
R4(config-router)#do clear ip bgp * in //不中斷鄰居關係,更新bgp路由
R4(config-router)#do sh ip bgp
BGP table version is 12, 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 192.168.12.1 0 100 0 100 i
*>i 192.168.13.1 0 100 100 100 i
* i192.168.12.0 192.168.24.1 0 100 0 i
*>i 192.168.13.1 0 100 100 100 i
* i192.168.13.0 192.168.12.1 0 100 0 100 i
*>i 192.168.34.1 0 100 100 i
* i192.168.24.0 192.168.24.1 0 100 0 i
*> 0.0.0.0 0 32768 i
* i192.168.34.0 192.168.34.1 0 100 100 i
*> 0.0.0.0 0 32768 i
根據調整weight值,R4如今到1.1.1.0網絡走了R3,可是這個調整同時影響了其餘路由條目,這不是咱們但願的。可見neighbor x.x.x.x weight xxx配置方法雖然最簡單,可是它並不能精確地針對某條路由實現weight值的改變,實際上當將某個鄰居的weight設置好之後,那麼這個鄰居通告過來的全部路由都會被本地路由器加上相同的weigh權重,那麼應該如何合理的設置Weight值呢?下面進一步調整
R4#conf t
R4(config)#access-list 1 permit 1.1.1.0 0.0.0.255 //建立訪問控制列表
R4(config)#route-map weight_100 permit 1 //建立策略
R4(config-route-map)#match ip add 1 將訪問控制列表應用到策略中
R4(config-route-map)#set weight 100 //對符合條件的條目設置weight爲100
R4(config-route-map)#exit
R4(config)#route-map weight_100 permit 2//建立空的策略,容許其餘不變
R4(config-route-map)#exit
R4(config)#router bgp 200
R4(config-router)#no nei 192.168.34.1 weight 100 //清除以前的設置
R4(config-router)#nei 192.168.34.1 route-map weight_100 in//將策略應用到進方向
R4(config-router)#do clear ip bgp * soft in //不中斷鄰居關係,更新bgp路由
R4#sh ip bgp
BGP table version is 14, 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 192.168.12.1 0 100 0 100 i
*>i 192.168.13.1 0 100 100 100 i
*>i192.168.12.0 192.168.24.1 0 100 0 i
* i 192.168.13.1 0 100 0 100 i
* i192.168.13.0 192.168.12.1 0 100 0 100 i
*>i 192.168.34.1 0 100 0 i
* i192.168.24.0 192.168.24.1 0 100 0 i
*> 0.0.0.0 0 32768 i
* i192.168.34.0 192.168.34.1 0 100 0 i
*> 0.0.0.0 0 32768 i
此時達到咱們的理想了,總結:
(1) Weight只具備本地意義他不能被路由器傳遞只在本路由其上有效.
(2) Weight:是思科的私有屬性
(3)在cisco中,weight屬性的優先級是最高的.在其餘廠商中,從Local_pref屬性開始。
(3)weight屬性默認會設置爲32768.其餘路由的權重默認爲0.
(4)若是有多條前往同一個目的路由器,那麼將會選擇權重高地路由優先。
(5)weight是一個入站策略只能用in的方向,用out方向是無效的,由於這個屬性不會傳遞到鄰居去的。
實驗5、BGP的next-hop-self屬性
R1配置:
R1#conf t
R1(config)#int lo 0
R1(config-if)#ip add 1.1.1.1 255.255.255.255
R1(config-if)#exit
R1(config)#int s0/0
R1(config-if)#clock rate 64000
R1(config-if)#ip add 192.168.12.1 255.255.255.0
R1(config-if)#no sh
R1(config-if)#exit
R1(config)#router bgp 65501
R1(config-router)#net 1.1.1.1 mask 255.255.255.255
R1(config-router)#net 192.168.12.0mask 255.255.255.0
R1(config-router)#bgp router-id 1.1.1.1
R1(config-router)#nei 192.168.12.2 remote-as 65502
R2配置:
R2#conf t
R2(config)#int s0/0
R2(config-if)#clock rate 64000
R2(config-if)#ip add 192.168.12.2 255.255.255.0
R2(config-if)#no sh
R2(config-if)#exit
R2(config)#int s0/1
R2(config-if)#clock rate 64000
R2(config-if)#ip add 192.168.23.1 255.255.255.0
R2(config-if)#no sh
R2(config-if)#exit
R2(config)#router bgp 65502
R2(config-router)#bgp router-id 2.2.2.2
R2(config-router)#net 192.168.23.0 mask 255.255.255.0
R2(config-router)#nei 192.168.12.1 remote-as 65501
R2(config-router)#nei 192.168.23.2 remote-as 65502
R3配置:
R3#conf t
R3(config)#int s0/0
R3(config-if)#clock rate 64000
R3(config-if)#ip add 192.168.23.2 255.255.255.0
R3(config-if)#no sh
R3(config-if)#exit
R3(config)#router bgp 65502
R3(config-router)#bgp router-id 3.3.3.3
R3(config-router)#net 192.168.23.0 mask 255.255.255.0
R3(config-router)#nei 192.168.23.1 remote-as 65502
R3(config-router)#net 3.3.3.3 mask 255.255.255.255
此時咱們查看R3的路由表,會發現根本沒有學習到R1的路由。查看R3的BGP路由你會發現存在兩條R1的路由,指向的下一跳是192.168.12.0網段,可是倒是無效的路由由於,R3並無192.168.12.0的路由。緣由是對於IBGP,起源AS內部的路由的NEXT-HOP就是通告該路徑的鄰居的ip(若是有設定更新源,則爲更新源地址)。而對於EBGP從外部AS注入進來的路由的NEXT-HOP通常會不變地帶入IBGP中,也始終指向的是下一個AS(即本AS對端的EBGP鄰居接口IP)。
R3#sh ip rou
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRPexternal, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1,E2 - OSPF external type 2
i - IS-IS, su - IS-ISsummary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * -candidate default, U - per-user static route
o - ODR, P - periodicdownloaded static route
Gateway of last resort is not set
3.0.0.0/32 issubnetted, 1 subnets
C 3.3.3.3 isdirectly connected, Loopback0
C 192.168.23.0/24 isdirectly connected, Serial0/0
R3#sh ip bgp
BGP table version is 10, local router IDis 3.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.1/32 192.168.12.1 0 100 0 65501 i
*> 3.3.3.3/32 0.0.0.0 0 32768 i
* i192.168.12.0 192.168.12.1 0 100 0 65501 i
*> 192.168.23.0 0.0.0.0 0 32768 i
要想解決這個問題有三種方法:
R2上在BGP進程中使用Network命令宣告本身的直連網絡
R2與R3之間運行某種IGP路由協議,並在IGP中宣告本身的網絡
R2中使用BGPnext-hop-self,強迫路由器通告本身是發送BGP更新的下一跳,一樣若是R1內部的自治區域還有其餘路由,那麼R1也要作配置。即:
R2#conf t
R2(config)#routerbgp 65502
R2(config-router)#nei192.168.23.2 next-hop-self
總結:
1、BGP協議路由更新有個前提條件:下一條路由可達,若是不可達,則不會把接受到的路由裝入路由表並更新給其他的peer。而一般狀況下,下一條路由可達須要依賴IGP,不多網絡會把bgp import到IGP的。
2、根據要求1,EBGP傳送路由給peer時缺省會把next-hop設定爲本身。
3、IBGP傳送路由給peer時缺省不會改變next-hop,爲了知足1,AS邊界路由器(EBGP/IBGP)在傳送路由給IBGP peer時一般須要設置next-hop-self,不然IBGP peer會因路由的下一跳不可達而拒絕IBGP Peer路由。BGP通常只在解析路由的下一跳,爲了防止下跳不可達的問題,就用策略了。EBGP給ibgp的時候,通常就要用這個了。但在MPLS中,有時候卻不用這個也是能夠的。用直鏈接口創建外部鄰居,並把與外部鄰居的直連的端口運行與as同樣的igp,爲passive模式.能夠解決。
實驗6、BGP 的MED屬性和local Pref
R1的配置:
R1#conf t
R1(config)#int e0/0
R1(config-if)#ip add 192.168.12.1 255.255.255.0
R1(config-if)#no sh
R1(config-if)#exit
R1(config)#int s1/0
R1(config-if)#clock rate 64000
R1(config-if)#ip add 192.168.13.1 255.255.255.0
R1(config-if)#no sh
R1(config-if)#exit
R1(config)#int lo 0
R1(config-if)#ip add 1.1.1.1 255.255.255.255
R1(config-if)#no sh
R1(config-if)#exit
R1(config)#router bgp 65501
R1(config-router)#bgp router-id 1.1.1.1
R1(config-router)#net 192.168.12.0 mask 255.255.255.0
R1(config-router)#net 192.168.13.0 mask 255.255.255.0
R1(config-router)#net 1.1.1.1 mask 255.255.255.255
R1(config-router)#nei 192.168.12.2 remote-as 65501
R1(config-router)#nei 192.168.13.2 remote-as 65502
R1(config-router)#nei 192.168.12.2 next-hop-self
R2配置:
R2#conf t
R2(config)#int e0/0
R2(config-if)#ip add 192.168.12.2 255.255.255.0
R2(config-if)#no sh
R2(config-if)#exit
R2(config)#int s1/0
R2(config-if)#clock rate 64000
R2(config-if)#ip add 192.168.24.1255.255.255.0
R2(config-if)#no sh
R2(config-if)#exit
R2(config)#int lo0
R2(config-if)#ip add 2.2.2.2 255.255.255.255
R2(config-if)#exit
R2(config)#router bgp 65501
R2(config-router)#bgp router-id 2.2.2.2
R2(config-router)#net 192.168.12.0 mask 255.255.255.0
R2(config-router)#net 192.168.24.0 mask 255.255.255.0
R2(config-router)#net 2.2.2.2 mask 255.255.255.255
R2(config-router)#nei 192.168.12.1 remote-as 65501
R2(config-router)#nei 192.168.24.2 remote-as 65502
R2(config-router)#nei 192.168.12.1 next-hop-self
R3配置:
R3#conf t
R3(config)#int s1/0
R3(config-if)#clock rate 64000
R3(config-if)#ip add 192.168.13.2 255.255.255.0
R3(config-if)#no sh
R3(config-if)#exit
R3(config)#int e0/0
R3(config-if)#ip add 192.168.34.1 255.255.255.0
R3(config-if)#no sh
R3(config-if)#exit
R3(config)#int lo0
R3(config-if)#ip add 3.3.3.3 255.255.255.255
R3(config-if)#exit
R3(config)#router bgp 65502
R3(config-router)#bgp router-id 3.3.3.3
R3(config-router)#net 3.3.3.3 mask 255.255.255.255
R3(config-router)#net 192.168.13.0 mask 255.255.255.0
R3(config-router)#net 192.168.34.0 mask 255.255.255.0
R3(config-router)#nei 192.168.13.1 remote-as 65501
R3(config-router)#nei 192.168.34.2 remote-as 65502
R3(config-router)#nei 192.168.34.2 next-hop-self
R4配置:
R4#CONF T
R4(config)#int e0/0
R4(config-if)#ip add 192.168.34.2 255.255.255.0
R4(config-if)#no sh
R4(config-if)#exit
R4(config)#int s1/0
R4(config-if)#clock rate 64000
R4(config-if)#ip add 192.168.24.2 255.255.255.0
R4(config-if)#no sh
R4(config-if)#exit
R4(config)#int lo0
R4(config-if)#ip add 4.4.4.4 255.255.255.255
R4(config-if)#exit
R4(config)#router bgp 65502
R4(config-router)#bgp router-id 4.4.4.4
R4(config-router)#net 192.168.24.0 mask 255.255.255.0
R4(config-router)#net 192.168.34.0 mask 255.255.255.0
R4(config-router)#net 4.4.4.4 mask 255.255.255.255
R4(config-router)#nei 192.168.24.1 remote-as 65501
R4(config-router)#nei 192.168.34.1 remote-as 65502
R4(config-router)#nei 192.168.34.1 next-hop-self
完成以上配置後應該全網互通。此時咱們查看R1的路由表
R1#sh ip rou
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRPexternal, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2- OSPF external type 2
i - IS-IS, su - IS-ISsummary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * -candidate default, U - per-user static route
o - ODR, P - periodicdownloaded static route
Gateway of last resort is not set
C 192.168.12.0/24 is directlyconnected, Ethernet0/0
1.0.0.0/32 is subnetted, 1subnets
C 1.1.1.1 is directlyconnected, Loopback0
C 192.168.13.0/24 is directlyconnected, Serial1/0
2.0.0.0/32 is subnetted, 1subnets
B 2.2.2.2 [200/0] via192.168.12.2, 00:05:53
3.0.0.0/32 is subnetted, 1subnets
B 3.3.3.3 [20/0] via192.168.13.2, 00:02:40
4.0.0.0/32 is subnetted, 1subnets
B 4.4.4.4 [20/0] via192.168.13.2, 00:03:10
B 192.168.24.0/24 [200/0] via192.168.12.2, 00:05:54
B 192.168.34.0/24 [20/0] via192.168.13.2, 00:03:11
R2#sh ip rou
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRPexternal, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2- OSPF external type 2
i - IS-IS, su - IS-ISsummary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * -candidate default, U - per-user static route
o - ODR, P - periodicdownloaded static route
Gateway of last resort is not set
C 192.168.12.0/24 is directlyconnected, Ethernet0/0
1.0.0.0/32 is subnetted, 1subnets
B 1.1.1.1 [200/0] via192.168.12.1, 00:06:57
B 192.168.13.0/24 [200/0] via192.168.12.1, 00:06:57
2.0.0.0/32 is subnetted, 1subnets
C 2.2.2.2 is directlyconnected, Loopback0
3.0.0.0/32 is subnetted, 1subnets
B 3.3.3.3 [20/0] via192.168.24.2, 00:03:54
4.0.0.0/32 is subnetted, 1subnets
B 4.4.4.4 [20/0] via192.168.24.2, 00:35:09
C 192.168.24.0/24 is directlyconnected, Serial1/0
B 192.168.34.0/24 [20/0] via192.168.24.2, 00:35:10
根據路由表發現R1到達3.3.3.3和4.4.4.4網絡都是從R3走;R2到達3.3.3.3和4.4.4.4網絡都是從R4走。可是咱們但願實現分流策略,即R1和R2到達4.4.4.4走R4,同時R1與R2到達R3的網絡3.3.3.3時走R3出去。此時咱們可使用BGP的MED屬性實現要求:
R3#conf t
R3(config)#access-list 1 permit 4.4.4.4 0.0.0.0 //在R3上標示出要施加策略的網絡
R3(config)#route-map no4 permit 10 //建立一條容許的route-map策略
R3(config-route-map)#match ip addrees 1 //將策略應用到匹配的網絡
R3(config-route-map)#set metric 1 //設置策略改變網絡的metric參數
R3(config-route-map)#exit
R3(config)#route-map no4 permit 11 //建立一條空route-map策略,容許其餘全部不變
R3(config-route-map)#exit
R3(config)#router bgp 65502
R3(config-router)#nei 192.168.13.1 route-map no4 out //將route-map策略傳輸給鄰居
R3(config-router)#end
R3#clear ip bgp * soft out //不中斷BGP鄰居關係,向本路由器的全部BGP鄰居從新發送一次BGP路由信息
R4#conf t
R4(config)#access-list 1 permit 3.3.3.3 0.0.0.0
R4(config)#route-map no3 permit 10
R4(config-route-map)#match ip address 1
R4(config-route-map)#set metric 1
R4(config-route-map)#exit
R4(config)#route-map no3 permit 11
R4(config-route-map)#exit
R4(config)#router bgp 65502
R4(config-router)#nei 192.168.24.1 route-map no3 out
R3(config-router)#end
R4#clear ip bgp * soft out
再次查看R1和R2的路由表,此時已經達到咱們的目的。
R1#sh ip rou
Codes: C - connected, S - static, R - RIP, M - mobile, B- BGP
D - EIGRP,EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPFNSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF externaltype 1, E2 - OSPF external type 2
i - IS-IS,su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-ISinter area, * - candidate default, U - per-user static route
o - ODR, P -periodic downloaded static route
Gateway of last resort is not set
C 192.168.12.0/24 is directly connected, Ethernet0/0
1.0.0.0/32 issubnetted, 1 subnets
C 1.1.1.1 isdirectly connected, Loopback0
C 192.168.13.0/24 is directly connected, Serial1/0
2.0.0.0/32 issubnetted, 1 subnets
B 2.2.2.2[200/0] via 192.168.12.2, 00:23:35
3.0.0.0/32 issubnetted, 1 subnets
B 3.3.3.3[20/0] via 192.168.13.2, 00:07:24
4.0.0.0/32 issubnetted, 1 subnets
B 4.4.4.4[200/0] via 192.168.12.2, 00:03:13
B 192.168.24.0/24[200/0] via 192.168.12.2, 00:23:36
B 192.168.34.0/24 [20/0] via 192.168.13.2, 00:08:06
2#sh ip rou
Codes: C - connected, S - static, R - RIP, M - mobile, B- BGP
D - EIGRP,EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPFNSSA external type 2
E1 - OSPFexternal type 1, E2 - OSPF external type 2
i - IS-IS,su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-ISinter area, * - candidate default, U - per-user static route
o - ODR, P -periodic downloaded static route
Gateway of last resort is not set
C 192.168.12.0/24 is directly connected, Ethernet0/0
1.0.0.0/32 issubnetted, 1 subnets
B 1.1.1.1[200/0] via 192.168.12.1, 00:23:16
B 192.168.13.0/24 [200/0] via 192.168.12.1, 00:23:16
2.0.0.0/32 issubnetted, 1 subnets
C 2.2.2.2 isdirectly connected, Loopback0
3.0.0.0/32 issubnetted, 1 subnets
B 3.3.3.3[200/0] via 192.168.12.1, 00:03:25
4.0.0.0/32 issubnetted, 1 subnets
B 4.4.4.4[20/0] via 192.168.24.2, 00:02:54
C 192.168.24.0/24 is directly connected, Serial1/0
B 192.168.34.0/24 [20/0] via 192.168.24.2, 00:02:55
咱們要實現R3與R4到網絡1.1.1.1走R3,R3與R4到網絡2.2.2.2走R4,也可使用修改MED的方法。可是咱們還有另外一種方法就是BGP的Local Pref 即本地優先。查看R3的路由表:
R3#sh ip rou
Codes: C - connected, S - static, R - RIP, M - mobile, B- BGP
D - EIGRP,EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPFNSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPFexternal type 1, E2 - OSPF external type 2
i - IS-IS,su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-ISinter area, * - candidate default, U - per-user static route
o - ODR, P -periodic downloaded static route
Gateway of last resort is not set
B 192.168.12.0/24 [20/0] via 192.168.13.1, 00:35:57
1.0.0.0/32 issubnetted, 1 subnets
B 1.1.1.1[20/0] via 192.168.13.1, 00:35:57
C 192.168.13.0/24 is directly connected, Serial1/0
2.0.0.0/32 issubnetted, 1 subnets
B 2.2.2.2[20/0] via 192.168.13.1, 00:35:57
3.0.0.0/32 issubnetted, 1 subnets
C 3.3.3.3 isdirectly connected, Loopback0
4.0.0.0/32 issubnetted, 1 subnets
B 4.4.4.4[200/0] via 192.168.34.2, 00:31:05
B 192.168.24.0/24 [200/0] via 192.168.34.2, 00:31:06
C 192.168.34.0/24 is directly connected, Ethernet0/0
而後進行以下修改改變選路:
R3#conf t
R3(config)#access-list 2 permit 1.1.1.0 0.0.0.255
R3(config)#route-map no2 permit 22
R3(config-route-map)#match ip address 2
R3(config-route-map)#set local-preference 200
R3(config-route-map)#exit
R3(config)#route-map no2 permit 23
R3(config-route-map)#exit
R3(config)#router bgp 65502
R3(config-router)#nei 192.168.34.2 route-map no2 out
R3(config-router)#end
R3# clear ip bgp * soft out
R4#conf t
R4(config)#access-list 2 permit 2.2.2.0 0.0.0.255
R4(config)#route-map no1 permit 22
R4(config-route-map)#match ip address 2
R4(config-route-map)#set local-preference 200
R4(config-route-map)#exit
R4(config)#route-map no1 permit 23
R4(config-route-map)#exit
R4(config)#router bgp 65502
R4(config-router)#nei 192.168.34.1 route-map no1 out
R4(config-router)#end
R4#clear ip bgp * soft out
配置完成後R3和R已經達到咱們的目的,此時查看R3的路由表:
R3#sh ip rou
Codes: C - connected, S - static, R - RIP, M - mobile, B- BGP
D - EIGRP,EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPFNSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPFexternal type 1, E2 - OSPF external type 2
i - IS-IS,su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-ISinter area, * - candidate default, U - per-user static route
o - ODR, P -periodic downloaded static route
Gateway of last resort is not set
B 192.168.12.0/24 [20/0] via 192.168.13.1, 00:08:32
1.0.0.0/32 issubnetted, 1 subnets
B 1.1.1.1[20/0] via 192.168.13.1, 00:08:32
C 192.168.13.0/24 is directly connected, Serial1/0
2.0.0.0/32 issubnetted, 1 subnets
B 2.2.2.2[200/0] via 192.168.34.2, 00:02:08
3.0.0.0/32 issubnetted, 1 subnets
C 3.3.3.3 isdirectly connected, Loopback0
4.0.0.0/32 issubnetted, 1 subnets
B 4.4.4.4[200/0] via 192.168.34.2, 00:08:32
B 192.168.24.0/24 [200/0] via 192.168.34.2, 00:08:34
C 192.168.34.0/24 is directly connected, Ethernet0/0
總結:
MED屬性可選非傳遞,至關於IGP中的Metic值,它告訴另一個鄰居AS中的BGP Router,從哪一個入口進來我本地AS的纔是最優的:鄰居AS中的BGP Router根據這個MED值來選擇到達某個網絡的最佳路徑,MED值越小越好。另外鄰居AS不會再將這個MED屬性值通告給鄰居AS,當鄰居AS中的BGP Router將那些網絡條目通告給它另外的EBGP鄰居時,會將這個MED值刪掉MED屬性值默認爲0,值越低優先級越高。謹記MED是影響他人的AS。
Local_Pref屬性是公認自由決定,只用在和IBGP鄰居間 的Update分組更新中,這個屬性字段是不會傳遞給EBGP鄰居的,它告訴本地AS中的BGP Router,從哪一個出口出去纔是最優的:同一個AS中的BGP Router根據這個Local_Pref值來選擇到達某個網絡的最佳路徑當Router要將路由條目通告給其EBGP鄰居的時候,會將這個Local_Pref屬性刪掉。Local-pref屬性的默認值爲100,值越高優先級越高。謹記Local_Pref是影響本身的AS。
實驗7、AS-PATH屬性
Internet配置:
Internet#conf t
Internet(config)#int lo0
Internet(config-if)#ip add 202.100.100.1255.255.255.0
Internet(config-if)#exit
Internet(config)#int s0/0
Internet(config-if)#clock rate 64000
Internet(config-if)#ip add 192.168.12.1 255.255.255.0
Internet(config-if)#no sh
Internet(config-if)#exit
Internet(config)#int s0/1
Internet(config-if)#clock rate 64000
Internet(config-if)#ip add 192.168.13.1255.255.255.0
Internet(config-if)#no sh
Internet(config-if)#exit
Internet(config)#router bgp 300
Internet(config-router)#bgp router-id1.1.1.1
Internet(config-router)#net 192.168.12.0mask 255.255.255.0
Internet(config-router)#net 192.168.13.0mask 255.255.255.0
Internet(config-router)#net202.100.100.0 mask 255.255.255.0
Internet(config-router)#nei 192.168.12.2remote-as 100
Internet(config-router)#nei 192.168.13.2remote-as 100
Unicom配置:
Unicom#conf t
Unicom(config)#int s0/0
Unicom(config-if)#clock rate 64000
Unicom(config-if)#ip add 192.168.12.2255.255.255.0
Unicom(config-if)#no sh
Unicom(config-if)#exit
Unicom(config)#int s0/1
Unicom(config-if)#clock rate 64000
Unicom(config-if)#ip add 192.168.24.1255.255.255.0
Unicom(config-if)#no sh
Unicom(config-if)#exit
Unicom(config)#router bgp 100
Unicom(config-router)#bgp router-id2.2.2.2
Unicom(config-router)#net 192.168.12.0mask 255.255.255.0
Unicom(config-router)#net 192.168.23.0mask 255.255.255.0
Unicom(config-router)#nei 192.168.12.1remote-as 300
Unicom(config-router)#nei 192.168.24.2remote-as 65501
Telecom配置:
Telecom#conf t
Telecom(config)#int s0/0
Telecom(config-if)#clock rate 64000
Telecom(config-if)#ip add 192.168.13.2 255.255.255.0
Telecom(config-if)#no sh
Telecom(config-if)#exit
Telecom(config)#int s0/1
Telecom(config-if)#clock rate 64000
Telecom(config-if)#ip add 192.168.34.1 255.255.255.0
Telecom(config-if)#no sh
Telecom(config-if)#exit
Telecom(config)#router bgp 100
Telecom(config-router)#bgp router-id 3.3.3.3
Telecom(config-router)#net 192.168.13.0 mask255.255.255.0
Telecom(config-router)#net 192.168.34.0 mask255.255.255.0
Telecom(config-router)#nei 192.168.13.1 remote-as 300
Telecom(config-router)#nei 192.168.34.2 remote-as 65501
Guest配置:
Guest#conf t
Guest(config)#int lo0
Guest(config-if)#ip add 4.4.4.4 255.255.255.0
Guest(config-if)#exit
Guest(config)#int s0/0
Guest(config-if)#clock rate 64000
Guest(config-if)#ip add 192.168.24.2 255.255.255.0
Guest(config-if)#no sh
Guest(config-if)#exit
Guest(config)#int s0/1
Guest(config-if)#clock rate 64000
Guest(config-if)#ip add 192.168.34.2 255.255.255.0
Guest(config-if)#no sh
Guest(config-if)#exit
Guest(config)#router bgp 65501
Guest(config-router)#bgp router-id 4.4.4.4
Guest(config-router)#net 192.168.24.0 mask255.255.255.0
Guest(config-router)#net 192.168.34.0 mask255.255.255.0
Guest(config-router)#net 4.4.4.0 mask 255.255.255.0
Guest(config-router)#nei 192.168.24.1 remote-as 100
Guest(config-router)#nei 192.168.34.1 remote-as 100
完成配置後,咱們來看看Unicom的BGP路由表,你會發現根本學習不到Telecom的 AS 100路由條目,同時查看Telecom的BGP路由表也會找不到Unicom的AS100路由條目。
Unicom#sh ip bgp
BGP table version is 8, local router ID is 2.2.2.2
Status codes: s suppressed, d damped, h history, *valid, > best, i - internal,
rRIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 4.4.4.0/24 192.168.24.2 0 0 65501 i
* 192.168.12.0 192.168.12.1 0 0 300 i
*> 0.0.0.0 0 32768 i
*> 192.168.13.0 192.168.12.1 0 0 300 i
* 192.168.24.0 192.168.24.2 0 0 65501 i
*> 0.0.0.0 0 32768 i
*> 192.168.34.0 192.168.24.2 0 0 65501 i
*> 202.100.100.0 192.168.12.1 0 0 300 i
其實這是由於Unicom與Telecom的AS號相同,觸犯了BGP的防環機制。即當某臺BGP路由器從其外部對等體接收到的某條路由的AS-Path中包含已有的本身的AS號,那麼該路由器就知道該路由出現了環路,須要丟包處理。此時咱們修改Telecom的AS爲200,並從新與其餘路由創建關係.而後再次查看Unicom的BGP路由表
Telecom#conf t
Telecom(config)#no router bgp 100
Telecom(config)#router bgp 200
Telecom(config-router)#bgp router-id 3.3.3.3
Telecom(config-router)#net 192.168.13.0 mask 255.255.255.0
Telecom(config-router)#net 192.168.34.0 mask 255.255.255.0
Telecom(config-router)#nei 192.168.13.1 remote-as 300
Telecom(config-router)#nei 192.168.34.2 remote-as 65501
Internet# conf t
Internet(config)#router bgp 300
Internet(config-router)#no nei 192.
Internet(config-router)#no nei 192.168.13.2 remote-as 100
Internet(config-router)#nei 192.168.13.2 remote-as 200
Guest#conft
Guest(config)#routerbgp 65501
Guest(config-router)#nonei 192.168.34.1 remote-as 100
Guest(config-router)#nei192.168.34.1 remote-as 200
Unicom#sh ipbgp
BGP table version is 8, local router ID is 2.2.2.2
Status codes: s suppressed, d damped, h history, *valid, > best, i - internal,
rRIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 4.4.4.0/24 192.168.24.2 0 0 65501 i
* 192.168.12.0 192.168.12.1 0 0 300 i
*> 0.0.0.0 0 32768 i
* 192.168.13.0 192.168.24.2 0 65501 200i
*> 192.168.12.1 0 0 300 i //最優
* 192.168.24.0 192.168.24.2 0 0 65501 i
*> 0.0.0.0 0 32768 i
* 192.168.34.0 192.168.12.1 0 300 200 i
*> 192.168.24.2 0 0 65501 I //最優
*> 202.100.100.0 192.168.12.1 0 0 300 i
如今全網已經正常了,咱們不妨看一看Unicom 的BGP路由表中的Path屬性,即AS-PATH屬性,它是公認必遵屬性,該屬性用一串AS號來描述去往的指定目的地AS間路徑或路由,當BGP speaker發起一條路由,將在AS_Path中增長本身的AS號。也就是說,這條路由每通過一個AS區域,就會加上一個AS號,用來標示路徑的優先級。當weight值相同,Local Pre相同,Metric相同時,As號疊加得越多,說明通過的AS越多,那麼這個路由的優先級也越低。相反,通過的AS越少,那麼說明路由越優先.越優先的路由,最早進入路由表,下面用Unicom的路由表代表
Unicom#sh ip rou
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRPexternal, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA externaltype 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type1, E2 - OSPF external type 2
i - IS-IS, su - IS-ISsummary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area,* - candidate default, U - per-user static route
o - ODR, P - periodicdownloaded static route
Gateway of last resort is not set
C 192.168.12.0/24 isdirectly connected, Serial0/0
B 192.168.13.0/24 [20/0] via 192.168.12.1, 00:37:52
4.0.0.0/24 is subnetted,1 subnets
B 4.4.4.0 [20/0] via192.168.24.2, 00:31:12
B 202.100.100.0/24 [20/0]via 192.168.12.1, 00:47:34
C 192.168.24.0/24 isdirectly connected, Serial0/1
B 192.168.34.0/24 [20/0] via 192.168.24.2, 00:31:12
那麼咱們是否能夠修改AS—PATH屬性,達到調整選路的目的呢?請看下面,這裏咱們改變一條試試效果:
Unicom#conf t
Unicom(config)#access-list 1 permit 192.168.13.00.0.0.255 //建立訪問控制網絡
Unicom(config)#route-map net13 permit 10 //建立策略
Unicom(config-route-map)#match ip add 1 //將訪問控制列表應用到策略
Unicom(config-route-map)#set as-path prepend 400 500 //對符合策略網絡追加AS號
Unicom(config-route-map)#exit
Unicom(config)#route-map net13 permit 11 //建立容許其餘不變的策略
Unicom(config-route-map)#exit
Unicom(config)#router bgp 100
Unicom(config-router)#nei 192.168.12.1 route-map net13in //將策略應用到鄰居的進方向
Unicom(config-router)#do clear ip bgp * soft in //不中斷鄰居關係,請求鄰居更新bgp路由信息
Unicom#sh ip bgp
BGP table version is 9, local router ID is 2.2.2.2
Status codes: s suppressed, d damped, h history, *valid, > best, i - internal,
rRIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 4.4.4.0/24 192.168.24.2 0 0 65501 i
* 192.168.12.0 192.168.12.1 0 0 300 i
*> 0.0.0.0 0 32768 i
*> 192.168.13.0 192.168.24.2 0 65501 200 i
* 192.168.12.1 0 0 400 500 300 i
* 192.168.24.0 192.168.24.2 0 0 65501 i
*> 0.0.0.0 0 32768 i
* 192.168.34.0 192.168.12.1 0 300 200 i
*> 192.168.24.2 0 0 65501 i
*> 202.100.100.0 192.168.12.1 0 0 300 i
Unicom#sh ip rou
Codes: C - connected, S - static, R - RIP, M - mobile,B - BGP
D -EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPFNSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPFexternal type 1, E2 - OSPF external type 2
i -IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-ISinter area, * - candidate default, U - per-user static route
o - ODR,P - periodic downloaded static route
Gateway of last resort is not set
C 192.168.12.0/24 is directly connected, Serial0/0
B 192.168.13.0/24 [20/0] via 192.168.24.2, 00:01:38
4.0.0.0/24 is subnetted, 1 subnets
B 4.4.4.0[20/0] via 192.168.24.2, 01:02:45
B 202.100.100.0/24 [20/0] via 192.168.12.1, 01:19:08
C 192.168.24.0/24 is directly connected, Serial0/1
B 192.168.34.0/24 [20/0] via 192.168.24.2, 01:02:45
此次咱們來看看Internet AS中的BGP路由表
Internet#sh ip bgp
BGP table version is 10, local router ID is 1.1.1.1
Status codes: s suppressed, d damped, h history, *valid, > best, i - internal,
rRIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
* 4.4.4.0/24 192.168.13.2 0 200 65501 i
*> 192.168.12.2 0 100 65501 i
* 192.168.12.0 192.168.12.2 0 0 100 i
*> 0.0.0.0 0 32768 i
* 192.168.13.0 192.168.12.2 0 100 65501 200 i
* 192.168.13.2 0 0 200 i
*> 0.0.0.0 0 32768 i
* 192.168.24.0 192.168.13.2 0 200 65501 i
*> 192.168.12.2 0 0 100 i
*> 192.168.34.0 192.168.13.2 0 0 200 i
* 192.168.12.2 0 100 65501 i
*> 202.100.100.0 0.0.0.0 0 32768 i
對於Internet它根本不用知道Guest的網絡,若是須要過濾掉Guest的網絡傳送到Intetnet。這是就要使用AS_PATH過濾列表,它是一種相似於ACL的列表,只是它匹配的不是網絡,而是AS號。編寫AS_PATH的ACL要利用正則表達式,這是從linux中發展出來的命令系統。下面進行配置,並觀察Internet的BGP路由是否還有4.4.4.0網絡。
Internet#conft
Internet(config)#ipas-path access-list 1 deny 65501$ //建立AS-PATH過濾列表,拒絕由AS65501發起的路由
Internet(config)#ipas-path access-list 1 permit .* //建立AS-PATH容許其餘路由
Internet(config)#routerbgp 300
Internet(config-router)#nei192.168.12.2 filter-list 1 in //將AS-PATH策略應用到鄰居的進方向
Internet(config-router)#nei192.168.13.2 filter-list 1 in//將AS-PATH策略應用到鄰居的進方向
Internet(config-router)#doclear ip bgp * soft in//不中斷鄰居關係,更新BGP路由
Internet#sh ip bgp
BGP table version is 12, local router ID is 1.1.1.1
Status codes: s suppressed, d damped, h history, *valid, > best, i - internal,
rRIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
* 192.168.12.0 192.168.12.2 0 0 100 i
*> 0.0.0.0 0 32768 i
* 192.168.13.0 192.168.12.2 0 100 65501 200 i
* 192.168.13.2 0 0 200 i
*> 0.0.0.0 0 32768 i
*> 192.168.24.0 192.168.12.2 0 0 100 i
*> 192.168.34.0 192.168.13.2 0 0 200 i
*> 202.100.100.0 0.0.0.0 0 32768 i
注意:AS_PATH的ACL,根據BGP路由的AS_PATH屬性決定路由的接受與拒絕。正則表達式經常使用操做符:
符號 |
說明 |
。 |
匹配任意字符,包括特殊字符,空格。 |
* |
匹配*前面字符中0次或屢次。 |
+ |
匹配+前面字符中1次或屢次。 |
? |
匹配?前面字符中0次或1次。 |
^ |
匹配字符串的開始。 |
$ |
匹配字符串的結束。 |
_ |
匹配一個符號,如逗號、左大括號、右大括號、左括號、右括號和空格等符號,在表達式的開頭或結尾時還可做起始符、結束符(同^ ,$)。 |
( ) |
匹配一個變化的字符或一個獨立的匹配,一般和"|"一塊兒使用。 |
| |
邏輯或,交替匹配 |
[ ] |
表示一組字符的集合,若是集合中第一個字符爲"^",則表示補集 |
- |
鏈接符 |
\ |
轉義操做符,去除特殊字符的特殊意義 |
實驗8、BGP的origin屬性
R1配置:
R1#CONF T
R1(config)#int s0/0
R1(config-if)#clock rate 64000
R1(config-if)#ip add192.168.12.1 255.255.255.0
R1(config-if)#no sh
R1(config-if)#exit
R1(config)#router bgp 100
R1(config-router)#bgprouter-id 1.1.1.1
R1(config-router)#net192.168.12.0 mask 255.255.255.0
R1(config-router)#nei192.168.12.2 remote-as 300
R2配置:
R2#conf t
R2(config)#int s0/0
R2(config-if)#clock rate 64000
R2(config-if)#ip add192.168.23.1 255.255.255.0
R2(config-if)#no sh
R2(config-if)#exit
R2(config)#router bgp 200
R2(config-router)#exit
R2(config)#int lo0
R2(config-if)#ip add 1.1.1.1255.255.255.0
R2(config-if)#exit
R2(config)#router bgp 200
R2(config-router)#net192.168.23.0 mask 255.255.255.0
R2(config-router)#nei192.168.23.2 remote-as 300
R3配置:
R3#conf t
R3(config)#int s0/0
R3(config-if)#clock rate 64000
R3(config-if)#ip add192.168.12.2 255.255.255.0
R3(config-if)#no sh
R3(config-if)#exit
R3(config)#int s0/1
R3(config-if)#clock rate 64000
R3(config-if)#ip add192.168.23.2 255.255.255.0
R3(config-if)#no sh
R3(config-if)#exit
R3(config)#router bgp 300
R3(config-router)#net 192.168.12.0mask 255.255.255.0
R3(config-router)#net192.168.23.0 mask 255.255.255.0
R3(config-router)#nei192.168.12.1 remote-as 100
R3(config-router)#nei192.168.23.1 remote-as 200
查看一下R3的BGP路由表:
R3#sh ip bgp
BGP table version is 5, localrouter ID is 192.168.23.2
Status codes: s suppressed, ddamped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e -EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
* 192.168.12.0 192.168.12.1 0 0 100 i
*> 0.0.0.0 0 32768 i
* 192.168.23.0 192.168.23.1 0 0 200 i
*> 0.0.0.0 0 32768 i
接着分別在R1和R2上進行以下修改:
R1(config)#conf t
R1(config)#iproute 1.1.1.0 255.255.255.0 null0 //建立指向空端口的靜態路由
R1(config)#routerbgp 100
R1(config-router)#redistributestatic //將靜態路由重分發到BGP進程
R1(config-router)#doclear ip bgp * soft out
R2#conf t
R2(config)#routerbgp 200
R2(config-router)#net1.1.1.0 mask 255.255.255.0//將Loopback0網絡宣告到BGP中
R2(config-router)#do clear ip bgp * soft out
再次觀察R3的BGP路由表:
R3#sh ip bgp
BGP table versionis 7, local router ID is 192.168.23.2
Status codes: ssuppressed, d damped, h history, * 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 192.168.23.1 0 0 200 i //最優
* 192.168.12.1 0 0 100 ?
* 192.168.12.0 192.168.12.1 0 0 100 i
*> 0.0.0.0 0 32768 i
* 192.168.23.0 192.168.23.1 0 0 200 i
*> 0.0.0.0 0 32768 i
R3#sh ip bgp1.1.1.1
BGP routing tableentry for 1.1.1.0/24, version 7
Paths: (2available, best #1, table Default-IP-Routing-Table)
Advertised to update-groups:
1
200
192.168.23.1 from 192.168.23.1(192.168.23.1)
Origin IGP, metric 0, localpref 100,valid, external, best
100
192.168.12.1 from 192.168.12.1 (1.1.1.1)
Origin incomplete, metric 0, localpref100, valid, external
這裏引出了BGP路由的origin屬性。這個屬性有3個值,分別爲:
IGP:當使用 bgp network 命令宣告進BGP中。在BGP路由表中起源於IGP的路由用「i」表示
EGP:經過BGP學習到的路由。在BGP路由表中起源於EGP的路由用「e」表示(淘汰了)
incomplete:當路由重分佈進BGP時,即沒法肯定路由的始發者時,在BGP路由表中用「?」表示
這三個值得優先級是:IGP>EGP>Incompelete。
實驗9、BGP的路由過濾prefix-list和Distribute-list
R1配置:
R1#conf t
R1(config)#int lo0
R1(config-if)#ip add 172.168.0.1255.255.255.0
R1(config-if)#exit
R1(config)#int lo1
R1(config-if)#ip add 172.168.1.1255.255.255.0
R1(config-if)#exit
R1(config)#int lo2
R1(config-if)#ip add 172.168.2.1255.255.255.0
R1(config-if)#exit
R1(config)#int lo3
R1(config-if)#ip add 172.168.3.1255.255.255.0
R1(config-if)#exit
R1(config)#int s0/0
R1(config-if)#clock rate 64000
R1(config-if)#ip add 192.168.12.1255.255.255.0
R1(config-if)#no sh
R1(config-if)#exit
R1(config)#router bgp 100
R1(config-router)#net 192.168.12.0 mask255.255.255.0
R1(config-router)#net 172.168.0.0 mask255.255.255.0
R1(config-router)#net 172.168.1.0 mask255.255.255.0
R1(config-router)#net 172.168.2.0 mask255.255.255.0
R1(config-router)#net 172.168.3.0 mask255.255.255.0
R1(config-router)#nei 192.168.12.2remote-as 200
R2配置:
R2#conf t
R2(config)#int s0/0
R2(config-if)#clock rate 64000
R2(config-if)#ip add 192.168.12.2255.255.255.0
R2(config-if)#no sh
R2(config-if)#exit
R2(config)#int s0/1
R2(config-if)#clock rate 64000
R2(config-if)#ip add 192.168.23.1255.255.255.0
R2(config-if)#no sh
R2(config-if)#exit
R2(config)#router bgp 200
R2(config-router)#net 192.168.12.0 mask255.255.255.0
R2(config-router)#net 192.168.23.0 mask255.255.255.0
R2(config-router)#nei 192.168.12.1remote-as 100
R2(config-router)#nei 192.168.23.2remote-as 300
R3配置:
R3#conf t
R3(config)#int s0/0
R3(config-if)#clock rate 64000
R3(config-if)#ip add 192.168.23.2255.255.255.0
R3(config-if)#no sh
R3(config-if)#exit
R3(config)#router bgp 300
R3(config-router)#net 192.168.23.0 mask255.255.255.0
R3(config-router)#nei 192.168.23.1remote-as 200
完成以上配置後,查看R3的BGP路由表
R3#sh ip bgp
BGP table version is 8, localrouter ID is 192.168.23.2
Status codes: s suppressed, ddamped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP,? - incomplete
Network Next Hop Metric LocPrf Weight Path
*>172.168.0.0/24 192.168.23.1 0 200 100 i
*> 172.168.1.0/24 192.168.23.1 0 200 100 i
*> 172.168.2.0/24 192.168.23.1 0 200 100 i
*> 172.168.3.0/24 192.168.23.1 0 200 100 i
*> 192.168.12.0 192.168.23.1 0 0 200 i
* 192.168.23.0 192.168.23.1 0 0 200 i
*> 0.0.0.0 0 32768 i
此時咱們使用prefix-list讓R3學不到172.168.0.0網段,而後再次查看R3的路由表
R2#conf t
R2(config)#ip prefix-list bgpbldeny 172.168.0.0/24 //建立拒絕的前綴過濾列表
R2(config)#ip prefix-list bgpblpermit 0.0.0.0/0 le 32//建立容許其餘的前綴列表
R2(config)#router bgp 200
R2(config-router)#nei192.168.23.2 prefix-list bgpbl out//將前綴列表應用到鄰居的出方向
R2(config-router)#do clear ipbgp * soft out//不中段鄰居關係,更新BGP路由信息
R3#sh ip bgp
BGP table version is 9, localrouter ID is 192.168.23.2
Status codes: s suppressed, ddamped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP,? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 172.168.1.0/24 192.168.23.1 0 200 100 i
*> 172.168.2.0/24 192.168.23.1 0 200 100 i
*> 172.168.3.0/24 192.168.23.1 0 200 100 i
*> 192.168.12.0 192.168.23.1 0 0 200 i
* 192.168.23.0 192.168.23.1 0 0 200 i
*> 0.0.0.0 0 32768 i
咱們還可使用Prefix-list過濾掉R1發起172.168.1.0的路由,可是我想使用另外一個方法就是Distribute-list,配置以下
R1(config)#conf t
R1(config)#access-list 10 deny 172.168.1.00.0.0.255//建立訪問控制列表拒絕指定網絡
R1(config)#access-list 10 permit any//設置訪問控制列表容許其餘網絡
R1(config)#router bgp 100
R1(config-router)#nei 192.168.12.2distribute-list 10 out//將控制列表應用到鄰居的出方向
R1(config-router)#do clear ip bgp * softout//不中斷鄰居關係,更新BGP路由
配置完成後R2和R3的BGP路由表中就不會有172.168.1.0網段了
R3#sh ip bgp
BGP table version is 10, local router ID is192.168.23.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
*> 172.168.2.0/24 192.168.23.1 0 200 100 i
*> 172.168.3.0/24 192.168.23.1 0 200 100 i
*> 192.168.12.0 192.168.23.1 0 0 200 i
* 192.168.23.0 192.168.23.1 0 0 200 i
*> 0.0.0.0 0 32768 i
實驗10、BGP路由匯聚
在BGP下有三種生成匯聚地址的方法:謹記BGP宣告網絡的前提是該路由條目存在路由表中
第一種,自動彙總(默認爲關閉狀態),BGP的自動路由彙總特性,並非像RIP這些普通距離矢量協議或EIGRP高級距離矢量協議同樣在主類的邊界進行彙總,其主要是將本地多個相同主類網絡下的無類路由向主類網絡進行彙總,而且向鄰居路由器通告此條路由。而無論其自己是否處於主類邊界。auto-summary命令做用的對象:重分佈進bgp的igp或直連或靜態路由.若是這些路由是子網路由,在進bgp表時將被自動彙總成有類路由條目.auto-summary命令不做用的對象:network通告的路由,ibgp或ebgp鄰居通告的路由.若是是此類產生的路由,在showip bgp表中將是子網路由,這些路由再經過ibgp或ebgp通告給鄰居時,根據此原則,不管鄰居是否啓用auto-summary,接收到的都將是子網路由條目.只要在showip bgp表中存在的路由,都會不變地傳給ibgp或ebgp的鄰居,而無論鄰居或本身是否啓用auto-summary命令.
第二種,在路由表中爲聚合路由創建一條靜態路由條目後使用network命令將它公佈出去。經過用靜態路由指一條彙總地址到null0當中去,讓這條路由條目存在於路由表中再去通告一個彙總地址這樣的方式去作彙總。可是其它的BGP路由器並不知道是在哪裏彙總的,致使不容易排錯,且不能對彙總路由作策略。只能在產生明細路由的路由器上作。
第三種,使用 aggregate-address 命令生成聚合地址。此方式爲BGP真正的路由彙總,它須要在本路由器上經過network命令先通告明細路由加入到BGP表中,也能夠經過重分發來完成。aggregate-address 匯聚命令的選項
summary-only :該命令加入後,aggregate-address 宣告的路由中,明細路由將不會宣告。
supress-map :該命令用來抑制aggregate-address 宣告的路由中不包含某條明細路由。
attribute-map: 該命令能夠改變聚合路由的屬性,例如能夠改變聚合路由的ORIGIN屬性,
AS-Set :不寫該命令時,聚合路由的as-path是基於生成聚合路由的as-path,而不是明細路由的as-path,加入該命令後,聚合路由將繼承明細路由的全部屬性,包括as-path。
Advertise Map:設置匯聚路由的組成不包含特定明細路由,這樣聚合路由就不會繼承特定明細路由的屬性。當在對BGP路由進行聚合的時候,用AS-SET屬性對被聚合的路由將攜帶明細路由的AS號,利用advertise-map(外加route-map)來控制匯聚路由究竟對哪些明細路由進行匯聚,最後將匯聚後的BGP路由放入BGP表。
R1配置:
R1#conf t
R1(config)#int lo0
R1(config-if)#ip add172.168.0.1 255.255.255.0
R1(config-if)#exit
R1(config)#int lo1
R1(config-if)#ip add172.168.1.1 255.255.255.0
R1(config-if)#exit
R1(config)#int lo2
R1(config-if)#ip add172.168.2.1 255.255.255.0
R1(config-if)#exit
R1(config)#int lo3
R1(config-if)#ip add172.168.3.1 255.255.255.0
R1(config-if)#exit
R1(config)#int s0/0
R1(config-if)#clock rate 64000
R1(config-if)#ip add192.168.12.1 255.255.255.0
R1(config-if)#no sh
R1(config-if)#exit
R1(config)#router bgp 100
R1(config-router)#bgp router-id1.1.1.1
R1(config-router)#nei192.168.12.2 remote-as 100
R1(config-router)#net192.168.12.0 mask 255.255.255.0
R1(config-router)#net172.168.0.0 mask 255.255.255.0
R1(config-router)#net172.168.1.0 mask 255.255.255.0
R1(config-router)#net172.168.2.0 mask 255.255.255.0
R1(config-router)#net172.168.3.0 mask 255.255.255.0
R2配置:
R2#conf t
R2(config)#int s0/0
R2(config-if)#clock rate 64000
R2(config-if)#ip add192.168.12.2 255.255.255.0
R2(config-if)#no sh
R2(config-if)#exit
R2(config)#int s0/1
R2(config-if)#clock rate 64000
R2(config-if)#ip add192.168.23.1 255.255.255.0
R2(config-if)#no sh
R2(config-if)#exit
R2(config)#router bgp 100
R2(config-router)#bgp router-id 2.2.2.2
R2(config-router)#nei192.168.12.1 remote-as 100
R2(config-router)#nei192.168.23.2 remote-as 200
R2(config-router)#net192.168.12.0 mask 255.255.255.0
R2(config-router)#net192.168.23.0 mask 255.255.255.0
R3配置:
R3#conf t
R3(config)#int s0/0
R3(config-if)#clock rate 64000
R3(config-if)#ip add192.168.23.2 255.255.255.0
R3(config-if)#no sh
R3(config-if)#exit
R3(config)#router bgp 200
R3(config-router)#bgp router-id3.3.3.3
R3(config-router)#net192.168.23.0 mask 255.255.255.0
R3(config-router)#nei192.168.23.1 remote-as 100
此時查看R3的路由表BGP路由表,發現已經學到了R1宣告的BGP路由,可是咱們發現這些路由能夠彙總成主類路由,以減小路由表。
R3#sh ip bgp
BGP table version is 8, localrouter ID is 3.3.3.3
Status codes: s suppressed, ddamped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP,? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 172.168.0.0/24 192.168.23.1 0 100 i
*> 172.168.1.0/24 192.168.23.1 0 100 i
*> 172.168.2.0/24 192.168.23.1 0 100 i
*> 172.168.3.0/24 192.168.23.1 0 100 i
*> 192.168.12.0 192.168.23.1 0 0 100 i
* 192.168.23.0 192.168.23.1 0 0 100 i
*> 0.0.0.0 0 32768 i
方法一:啓用BGP自動彙總auto-summary,而後查看R3配置:
R1#conf t
R1(config)#router bgp 100
R1(config-router)#no net172.168.0.0 mask 255.255.255.0//清除以前的宣告的網絡
R1(config-router)#no net172.168.1.0 mask 255.255.255.0//清除以前的宣告的網絡
R1(config-router)#no net172.168.2.0 mask 255.255.255.0//清除以前的宣告的網絡
R1(config-router)#no net172.168.3.0 mask 255.255.255.0//清除以前的宣告的網絡
R1(config-router)#auto-summary//啓動自動彙總
R1(config-router)#net172.168.0.0//宣告彙總的主類網絡
R1(config-router)#do clear ip *bgp soft//不中斷鄰居關係,更新BGP路由表
R3#sh ip bgp
BGP table version is 15, localrouter ID is 3.3.3.3
Status codes: s suppressed, ddamped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP,? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 172.168.0.0 192.168.23.1 0 100 I//彙總成主類
*> 192.168.12.0 192.168.23.1 0 0 100 i
* 192.168.23.0 192.168.23.1 0 0 100 i
*> 0.0.0.0 0 32768 i
方法二:手工添加一條彙總的靜態路由,再經過Network宣告,而後查看R3路由表
R1#conf t
R1(config)#ip route 172.168.0.0255.255.252.0 null 0//添加一條靜態路由指向null0
R1(config)#router bgp 100
R1(config-router)#no net172.168.0.0 mask 255.255.255.0//清除以前宣告的網絡
R1(config-router)#no net 172.168.1.0mask 255.255.255.0
R1(config-router)#no net172.168.2.0 mask 255.255.255.0
R1(config-router)#no net172.168.3.0 mask 255.255.255.0
R1(config-router)#net172.168.0.0 mask 255.255.252.0 //宣告剛纔添加的靜態路由
R1(config-router)#do clear ipbgp * soft//不中斷鄰居關係,更新bgp路由
R3#sh ip bgp
BGP table version is 25, localrouter ID is 3.3.3.3
Status codes: s suppressed, ddamped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP,? - incomplete
Network