BGP十三條選路---實驗(上)

十三條選路原則

  1. 權重weight
  2. 本地優先級(Local Preference)——AS內部傳遞,默認100,越大越優
  3. 優選本地始發路由(相信自己)——後面舉例說明
  4. AS-path(越小越優)——學習到該條目經過多少AS區域
  5. 起源屬性oragin(i---IGP學習到的、e---EBGP學習到的、?重複發進來的)(優先級:i>e>?)---可修改
  6. MED多出口鑑別器(鄰居一跳AS內傳遞)
  7. EBGP(200)路由優於IBGP(20)路由——一般不會有這種情況
  8. BGP優選到下一跳IGP度量值低的
  9. 執行等價負載均衡---默認1:最多16\需要配置
  10. 優選最古老的路由
  11. 比較EBGP鄰居的RID(越小越優)
  12. cluster-list 長度、越短越優
  13. 優選最小的鄰居地址的路由

    基本配置模板(本實驗使用GNS3模擬器)

    BGP十三條選路---實驗(上)

    這裏EGP使用物理口相互建立鄰居,IGP使用環回口建立鄰居
    物理口建立鄰居不需要學習到對方的環回口----方便
    環回口建立鄰居比較穩定---穩定(只要還要一個物理口爲up則一直爲up)

    命令:

    R1:

    //需注意是從用戶模式開始配置的
    en
    conf t
    hostname R1
    int lo1
    ip add 1.1.1.1 255.255.255.255
    no sh
    int f0/0
    ip add 12.1.1.1 255.255.255.0
    no sh
    int f1/0
    ip add 24.1.1.1 255.255.255.0
    no sh
    router bgp 100
    bgp router-id 1.1.1.1
    nei 12.1.1.2 remote-as 1
    nei 24.1.1.3 remote-as 1
    net 1.1.1.1 mask 255.255.255.255  //必須與路由表中的相一致
    exit
    do wr   //保存配置,方便後續實驗

R2:

en
conf t
hostname R2
int f0/0
ip add 12.1.1.2 255.255.255.0
no sh
exit
int lo1
ip add 2.2.2.2 255.255.255.255
no sh
exit
int f1/0
ip add  32.1.1.2 255.255.255.0
no sh
exit
router bgp 1
bgp router-id 2.2.2.2
nei 12.1.1.1 remote-as 100
nei 4.4.4.4 remote-as 1
nei 4.4.4.4 update-source lo1  //修改更新源---默認互聯物理口(即TCP報文從那裏發出去)
nei 4.4.4.4 next-hop-self      //大家可以試試不加這條命令
exit
router eigrp 100
net 12.1.1.0 0.0.0.255
net 32.1.1.0 0.0.0.255
net 2.2.2.2 0.0.0.0  //爲了後面IGP鄰居能夠建立起鄰居
exit
IGP學習到外部EBGP的路由,原封不動發送給IGP鄰居的,如果不指定下一跳,則會導致不是最優(也去不了)R2去R1環回口默認是直接發送給R1,而R3根本不可能直接發送給R1。(連接不同AS路由器上做)

R4:

en
conf t
hostname R4
int f0/0
ip add 32.1.1.4 255.255.255.0
no sh
exit
int lo0
ip add 11.11.11.11 255.255.255.255
no sh
int lo1
ip add 4.4.4.4 255.255.255.255
no sh
exit
int s2/0
ip add  52.1.1.4 255.255.255.255
no sh
exit
router bgp 1
bgp router-id 4.4.4.4
nei 2.2.2.2 remote-as 1
nei 2.2.2.2 update-source lo1
nei 3.3.3.3 remote-as 1
nei 3.3.3.3 update-source lo1
exit
router eigrp 100
net 32.1.1.0 0.0.0.255
net 4.4.4.0 0.0.0.255
net 52.1.1.0 0.0.0.255
exit

R3:

en
conf t
hostname R3
int f0/0
ip add  24.1.1.3 255.255.255.0
no sh
exit
int lo1
ip add 3.3.3.3 255.255.255.255
no sh
exit
int s2/0
ip add 52.1.1.3 255.255.255.0
no sh
exit
router bgp 1
bgp router-id 3.3.3.3
nei 24.1.1.1 remote-as 100
nei 4.4.4.4 remote-as 1
nei 4.4.4.4 next-hop-self
nei 4.4.4.4 update-source lo1
exit
router eigrp 100
net 52.1.1.0 0.0.0.255
net 3.3.3.3 0.0.0.0
net 24.1.1.0 0.0.0.255
exit
do wr

(大家要看看R4的s2/0起來沒有,我這邊就是要多打一邊)--
我們可以看到R4通過學習到R1的1.1.1.1的路由,最優的()是
>i1.1.1.1/32 2.2.2.2


一、權重Weight(cisco私有)

傳播範圍:本路由內(不可傳遞)
缺省值:本路由器=32768,其他=0

兩種配置方法:

    1. OSFP內配置 針對鄰居
    1. route-map 針對條目

拓撲圖

BGP十三條選路---實驗(上)

第一種:

現在R4去往1.1.1.1走的是R2,我們來對它進行修改,使其走向R3

   Network          Next Hop            Metric LocPrf Weight Path
*>i1.1.1.1/32       2.2.2.2                  0    100      0 100 i
* i                        3.3.3.3                  0    100      0 100 i
*> 11.11.11.11/32   0.0.0.0                  0         32768 i

R4:

//用戶模式開始
en
conf t
router bgp 1
neighbor 3.3.3.3 weight 100 //將鄰居3.3.3.3發送的條目權重值改爲100
記得在特權模式下軟清一下:clear ip bgp * so
————————————————————————————————————————————————————————————————————————————————————————————
可以看到確實是走R3了
   Network          Next Hop            Metric LocPrf Weight Path
* i1.1.1.1/32       2.2.2.2                  0    100      0 100 i
*>i                      3.3.3.3                  0    100    100 100 i
*> 11.11.11.11/32   0.0.0.0                  0         32768 i

確實是很方便,但是會導致什麼情況呢!

大家看我在R1再宣告一條路由
en
conf t
int lo2
ip add 8.8.8.8 255.255.255.255
no sh
exit
router bgp 100
net 8.8.8.8 mask 255.255.255.255

再看R4的BGP路由表
   Network          Next Hop            Metric LocPrf Weight Path
* i1.1.1.1/32       2.2.2.2                  0    100      0 100 i
*>i                 3.3.3.3                  0    100    100 100 i
*>i8.8.8.8/32       3.3.3.3                  0    100    100 100 i
* i                 2.2.2.2                  0    100      0 100 i
*> 11.11.11.11/32   0.0.0.0                  0         32768 i
還是走R3--就有點不太靈活了!

Weight第二種

利用前綴列表或access-list抓取相應的條目
R4:

en
conf t
access-list 10 permit 1.1.1.1 //抓取對應的條目
route-map Weight permit //route-map來修改權重
            match ip address 10 //綁定我們寫好的ACL列表
            set weight 100
            exit
router bgp 1
neighbor 3.3.3.3 route-map Weight in //接收方向調用

//這樣我們可以看到只有R3傳過來的1.1.1.1 纔會加100weight
   Network          Next Hop            Metric LocPrf Weight Path
* i1.1.1.1/32       2.2.2.2                  0    100      0 100 i
*>i                      3.3.3.3                  0    100    100 100 i
*>i8.8.8.8/32       2.2.2.2                  0    100      0 100 i
*> 11.11.11.11/32   0.0.0.0                  0         32768 i

本地優先級(Local Preference)

傳播範圍:AS內進行傳播
缺省值:100
比較方式:越大越優
BGP十三條選路---實驗(上)
同樣R4去往1.1.1.1 走R3



第一種(修改本地默認優先級)

R3:

//用戶模式開始配置
en
conf t
router bgp 1
bgp default locall-preference 110
//軟清理一下
R3#clear ip bgp * so
//沒有so則硬清,生產環境不要硬清

R4上查看:


   Network          Next Hop            Metric LocPrf Weight Path
* i1.1.1.1/32       2.2.2.2                  0    100      0 100 i
*>i                      3.3.3.3                  0    110      0 100 i
*>i8.8.8.8/32       3.3.3.3                  0    110      0 100 i
* i                          2.2.2.2                  0    100      0 100 i
*> 11.11.11.11/32   0.0.0.0                  0         32768 i
//確實是可以,與上面情況一致,不太靈活

第二種(in/out修改)

IN方向

R4:

//用戶模式開始配置
en
conf t
access-list 10 permit 1.1.1.1 //抓取路由條目
route-map Local permit
            match ip address 10  //與ACL相綁定
            set local-preference 110 //修改本地優先級
            exit
router bgp 1
neighbor 3.3.3.3 route-map Local in  //in方向進行調用

查看R4 BGP路由表

   Network          Next Hop            Metric LocPrf Weight Path
* i1.1.1.1/32       2.2.2.2                  0    100      0 100 i
*>i                      3.3.3.3                  0    110      0 100 i
*>i8.8.8.8/32       2.2.2.2                  0    100      0 100 i
*> 11.11.11.11/32   0.0.0.0                  0         32768 i
我們看到只有3.3.3.3發出來的條目1.1.1.1被加上*>和對應的本地優先級

OUT方向

R3:

//用戶模式開始配置
en
conf t
ip prefix-list Local-out permit 1.1.1.1/32  //前綴列表抓取條目
route-map Local-out permit  
                    match ip address prefix-list Local-out  //綁定前綴列表
                    set local-preference 120  //修改BGP本地優先級
                    exit
router bgp 1
nei 4.4.4.4 route-map Local-out out //out方向調用

R4 BGP路由:

   Network          Next Hop            Metric LocPrf Weight Path
* i1.1.1.1/32       2.2.2.2                  0    100      0 100 i
*>i                      3.3.3.3                  0     120      0 100 i
*>i8.8.8.8/32       2.2.2.2                  0    100      0 100 i
*> 11.11.11.11/32   0.0.0.0                  0         32768 i

BGP十三條選路---實驗(上)

優選本地始發的路由(看現象)

R1上看去往1.1.1.1下一跳是不是0.0.0.0

做個小案例:
R4:

//用戶模式開始配置
//R4去往1.1.1.1 這個路由一般走R2或R3
en
conf t
ip route 1.1.1.1 255.255.255.255 null 0
router bgp 1
net 1.1.1.1 mask 255.255.255.255
exit
do sh ip bgp
//相信自己,將Next Hop改爲自己0.0.0.0
   Network          Next Hop            Metric LocPrf Weight Path
*> 1.1.1.1/32       0.0.0.0                  0         32768 i

AS-path(越短越優)

如果收到本區域的AS則丟棄
邊界路由器上做,針對對方IGP內
R1:

en
conf t
access-list 10 permit 1.1.1.1
route-map AS-Path
                match ip address 10
              set as-path prepend 2 4 5 6 7 8 
                exit
router bgp 1
                neighbor 12.1.1.2 route-map AS-Path out 

如果收到本區域內的AS

R1:

en
conf t
access-list 10 permit 1.1.1.1
route-map AS-Path
                match ip address 10
              set as-path prepend 1 2 4 5 6 7 8 
                exit
router bgp 1
                neighbor 12.1.1.2 route-map AS-Path out 

R2直接就丟棄了(氣死我了)

強制要求R2接收(嘿嘿)
BGP十三條選路---實驗(上)
R2-in方向:

//用戶模式配置
en
conf t
router bgp 1
            neighbor 12.1.1.1 allowas-in

再來查看R2的BGP路由表:
   Network          Next Hop            Metric LocPrf Weight Path
*> 1.1.1.1/32       12.1.1.1                 0             0 100 1 2 3 4 5 6 7 8 i
*>i11.11.11.11/32   4.4.4.4                  0    100      0 i

限制AS

//用戶模式配置
en
conf t
router bgp 1
        bgp maxas-limit [數量]
        R5(config-router)#bgp bestpath as-path ignore //忽略AS-path
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章