BGP的彙總、屬性分類、團體屬性

一、BGP的彙總
    1、最實用的方法:用network加一條指向null0的靜態路由做彙總:不通告明細,只通告彙總路由。只能在產生明細路由的路由器上做。
    2、標準方法:aggregate-address。優點:在任何地方都可以做。自動產生指向NULL0的路由。
      (1)R4(config-router)#aggregate-address 4.1.0.0 255.255.252.0 summary-only 
          只傳彙總路由。在起源路由器上用這條命令。
      (2)R1(config-router)#aggregate-address 4.1.0.0 255.255.252.0 summary-only as-set
          在非起源路由器上用這條命令。加上as-set的原因:在非起源路由器上做彙總會丟失以前的AS path,產生的彙總路由會從這個做彙總的路由器所在的AS算起,這在某些情況下會有產生環路的風險。as set參數就是還原as path屬性(好像還可以還原其他屬性)。例如:在一個路由器上彙總兩個AS傳過來的明細路由,as-set參數會給路由條目打上這兩個AS號{200,400} 13,大括號裏的號碼是隨機的,當這條彙總路由通過其他路徑傳到明細路由器上時,由於as-path中有自己AS的號碼,這條路由將被丟棄。(寫下來就明白一點了,這個大括號裏面的as號只是爲了防環,並不參與選路。)
      (3)精確控制只彙總哪些精確路由條目
          R1(config)#ip prefix-list 2 permit 4.1.2.0/24
          R1(config)#ip prefix-list 3 permit 4.1.3.0/24
          R1(config)#route-map aaa permit 10
          R1(config-route-map)#match ip address prefix-list 2 3
          R1(config-route-map)#router bgp 123
          R1(config-router)#aggregate-address 4.1.0.0 255.255.252.0 suppress-map aaa  as-set
          R1(config-router)#do sh ip b
            BGP table version is 15, 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
            Origin codes: i - IGP, e - EGP, ? - incomplete
            Network          Next Hop            Metric LocPrf Weight Path
            *>i4.1.0.0/24      2.2.2.2                  0    100      0 400 i
            *> 4.1.0.0/22      0.0.0.0                      100  32768 400 i
            *>i4.1.1.0/24      2.2.2.2                  0    100      0 400 i
            s>i4.1.2.0/24      2.2.2.2                  0    100      0 400 i
            s>i4.1.3.0/24      2.2.2.2                  0    100      0 400 i
            *>i5.1.1.0/24      3.3.3.3                  0    100      0 500 i
          R1(config-router)#
          可以看出以上BGP表中有兩條路由被抑制了。
          注意:在這裏ip prefix-list和route-map都只是匹配,動作在彙總中實施。相反的情況,在route-map中採取動作,在neighbor命令後掛上這個route-map,則是控制路由條目的傳遞,非彙總。
    3、自動彙總:一般關閉
二、BGP的屬性
    1、分類:公認的或可選的;強制的與自覺的;傳遞的與非傳遞的;部分的
    2、特點:前三類是不可同選(廢話)
    3、合法組合:
      (1)公認的:所有運行BGP的路由器都必須要識別並且要能夠標識,還要能夠傳遞給其他鄰居
          A:公認強制:這些屬性必須出現的路由描述中,而且必須被識別:as-path;next-hop;起源;
          B:公認自覺:在路由描述中可以出現也可以不出現,但必須被識別:本地優先級
      (2)可選的:不一定所有的路由器都支持,
          A:可選傳遞:可以不被識別,但須被傳遞。只有可選傳遞的屬性才能被標記爲部分(這個是什麼意思?)
          B:可選非傳遞:不支持則刪除該屬性:MED
三、BGP的團體屬性
    1、性質:可選傳遞屬性,如別的路由器不識別則直接傳遞,如識別才按照這個屬性進行過濾
    2、目的:對路由條目設置相應屬性,使得其在BGP域中自動進行過濾,在一臺路由器上完成過濾,減少配置任務
    3、本質:打標記
    4、配置
      拓撲:R4、R2、R1、R3、R5五臺路由串連,R4屬於AS400,R2、R1、R3屬於大AS123,R2、R1屬於小AS65100,R3屬於小AS65200,R5屬於AS500.在R4上起四個環回口,通告進BGP(路由能夠傳遞的前提已經做好)
      要求:R2能收到四條路由,R1收到3條,R3收到2條,R5收到1條,要求用BGP團體屬性。
      配置示例一:
      (1)匹配路由條目
            R4(config)#ip prefix-list 0 permit 4.1.0.0/24
            R4(config)#ip prefix-list 1 permit 4.1.1.0/24
            R4(config)#ip prefix-list 2 permit 4.1.2.0/24
            R4(config)#ip prefix-list 3 permit 4.1.3.0/24
      (2)設置條目屬性
            R4(config)#route-map comm permit 10
            R4(config-route-map)#match ip address prefix-list 0
            R4(config-route-map)#set community no-advertise          這個屬性在下一跳生效後不再向其他路由器宣告
            R4(config)#route-map comm permit 20
            R4(config-route-map)#match ip address prefix-list 1
            R4(config-route-map)#set community local-AS              這個屬性在下一跳生效後將只在小AS65100內傳遞
            R4(config)#route-map comm permit 30
            R4(config-route-map)#match ip address prefix-list 2
            R4(config-route-map)#set community no-export            這個屬性在下一跳生效後將只在大AS123內傳遞
            R4(config)#route-map comm permit 40
            R4(config-route-map)#match ip address prefix-list 3
            R4(config-route-map)#set community none                  這個讓它正常傳遞,也可以只per 40其他爲空
      (3)在BGP進程裏調用
            R4(config)#router bgp 400
            R4(config-router)#neighbor 202.100.0.2 route-map comm out出站方向,在下一跳起作用
      (4)讓路由器發送這些團體屬性(可選傳遞屬性,識別方能起作用,要在每個路由上做)
            R4(config-router)#neighbor 202.100.0.2 send-community
            不打這條命令的話查看R1的BGP路由條目:
            R1#sh ip bgp 4.1.1.0
              BGP routing table entry for 4.1.1.0/24, version 4
              Paths: (1 available, best #1, table Default-IP-Routing-Table)
              Advertised to update-groups:
                      2       
                400
              2.2.2.2 (metric 1) from 2.2.2.2 (2.2.2.2)
              Origin IGP, metric 0, localpref 100, valid, confed-internal, best
            在R2打上這條命令
              R2(config)#router bgp 65100
              R2(config-router)#neighbor 1.1.1.1 send-community
            查看R1BGP條目:
              R1#sh ip bgp 4.1.1.0
                BGP routing table entry for 4.1.1.0/24, version 8
                Paths: (1 available, best #1, table Default-IP-Routing-Table, not advertised outside local AS)
                  Flag: 0x880
                  Not advertised to any peer
                  400
                2.2.2.2 (metric 1) from 2.2.2.2 (2.2.2.2)
                Origin IGP, metric 0, localpref 100, valid, confed-internal, best
                Community: local-AS
                R1#
            最後一行顯示的就是團體屬性。注意每臺路由器上針對相應鄰居都得打上send-community(不過在這個實驗中好像只需要在前面三臺路由器上做就可以了,因爲4.1.2.0傳到R3就不再傳了,4.1.3.0沒有團體屬性)
      配置示例二:
        (1)匹配路由條目
            R4(config)#ip prefix-list 0 permit 4.1.0.0/24
            R4(config)#ip prefix-list 1 permit 4.1.1.0/24
            R4(config)#ip prefix-list 2 permit 4.1.2.0/24
            R4(config)#ip prefix-list 3 permit 4.1.3.0/24
        (2)設置條目團體屬性並調用發送
            R4(config)#route-map comm permit 10
            R4(config-route-map)#match ip address prefix-list 0
            R4(config-route-map)#set community 1234       
            R4(config)#route-map comm permit 20
            R4(config-route-map)#match ip address prefix-list 1
            R4(config-route-map)#set community 400:5678              前面的400通常爲AS號,後面的隨便,vpn裏會有類似形式
            R4(config)#route-map comm permit 30
            R4(config-router)#nei 202.100.0.2 route-map ano out
            R4(config-router)#neighbor 202.100.0.2 send-community
        (3) 在其他路由上再次設置團體屬性
            R2(config)#ip community-list 1 permit 1234              匹配團體列表
            R2(config)#ip community-list 2 permit 400:5678           
            R2(config)#route-map ano permit 10
            R2(config-route-map)#match community 1                  調用團體列表1
            R2(config-route-map)#set metric 600
            R2(config)#route-map ano permit 20
            R2(config-route-map)#match community 2
            R2(config-route-map)#set local-preference 50            再次設置團體屬性
            R2(config)#route-map ano permit 30
        (3)再次在在BGP進程裏調用
            R2(config-router)#nei 1.1.1.1 route-map ano out
        (4)再次讓路由器發送這些團體屬性
            R2(config-router)#neighbor 1.1.1.1 send-community
            R1#sh ip b
              BGP table version is 22, 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
            Origin codes: i - IGP, e - EGP, ? - incomplete
              Network          Next Hop            Metric LocPrf Weight Path
            *>i4.1.0.0/24      2.2.2.2                600    100      0 400 i
            *>i4.1.1.0/24      2.2.2.2                  0    50      0 400 i
            *>i4.1.2.0/24      2.2.2.2                  0    100      0 400 i
            *>i4.1.3.0/24      2.2.2.2                  0    100      0 400 i
            *> 5.1.1.0/24      3.3.3.3                  0    100      0 (65200) 500 i
            可以看出,相應條目的metric和本地優先級都改過來了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章