BGP的度量值屬性

    MULTI_EXIT_DISC(多出口標識符)簡稱MED,MED用於影響相鄰兩個自治系統的路由決策,被稱爲外部度量值,其值越小越優先,Cisco中爲metric,默認值爲0,MED只能在AS之間傳遞,收到此屬性的AS路由器不會再將其傳遞給任何其它的第三方AS,但會傳遞給他的iBGP鄰居;html

    一條相同的BGP條目經過不一樣的EBGP鄰居學到時,只有在AS號相同時才進行MED比較,當從不一樣的EBGP鄰居收到相同的路由,可是AS號不同時,是不會比較MED值的,若是路由器上配置了bgp always-compare-med,就會忽略AS號不同,始終進行MED值的比較。ide

    下面經過實驗進行分析spa

wKiom1SJXpPBzVNwAAEJ5-yswUg886.jpg

圖1code

如上圖,R1上通告三個網段192.168.1.0/24192.168.2.0/24192.168.3.0/24;修改MED值,使R3訪問192.168.3.0/24R4,訪問192.168.1.0/24等兩網段走R2,配置以下:router

R1(config)#ip prefix-list med permit192.168.3.0/24
R1(config)#ip prefix-list med1 permit192.168.1.0/24
R1(config)#ip prefix-list med1 permit192.168.2.0/24
R1(config)#route-map R1-R2 permit 10
R1(config-route-map)#match ip address prefix-list med1
R1(config-route-map)#set metric 30
R1(config)#route-map R1-R2 permit 20
R1(config-route-map)# match ip address prefix-list med
R1(config-route-map)#set metric 50
R1(config)#route-map R1-R2 permit 30
R1(config)#route-map R1-R4 permit 10
R1(config-route-map)#match ip address prefix-list med
R1(config-route-map)#set metric 30
R1(config)#route-map R1-R4 permit 20
R1(config-route-map)#match ip address prefix-list med1
R1(config-route-map)#set metric 50
R1(config)#route-map R1-R4 permit 30
R1(config)#routerbgp 10
R1(config-router)#neighbor12.1.1.2 route-map R1-R2 out
R1(config-router)#neighbor14.1.1.2 route-map R1-R4 out

配置說明:R1發往R4的路由針對192.168.1.0/24192.168.2.0/24兩個網段設置metric值爲50192.168.3.0/24metric值爲20,其它的不變;而R1發往R2的路由針對192.168.3.0/24設置metric值爲50192.168.1.0/24192.168.2.0/24兩個網段設置metric值爲20,其它的不變,如今R2R4上查看路由狀況;
xml

R2#show ip bgphtm

BGP table version is 43, local routerID is 2.2.2.2blog

Status codes: s suppressed, d damped,h history, * valid, > best, i - internal,接口

              r RIB-failure, S Stale, mmultipath, b backup-path, f RT-Filter,ip

              x best-external, aadditional-path, c RIB-compressed,

Origin codes: i - IGP, e - EGP, ? -incomplete

RPKI validation codes: V valid, Iinvalid, N Not found

    Network          Next Hop            Metric LocPrf Weight Path

 * i 1.1.1.1/32       4.4.4.4                  0    100     0 10 i

 *>                   12.1.1.1                 0             0 10 i

 *>  192.168.1.0      12.1.1.1                30             0 10 i

 *>  192.168.2.0      12.1.1.1                30             0 10 i

 *>i192.168.3.0       4.4.4.4                 30    100     0 10 i

 *                   12.1.1.1                50             0 10 i

R1收到的192.168.3.0/24metric值爲50,其值小於從R4傳遞過來的30,所以下一跳爲R4

R4#show ip bgp

BGP table version is 31, local routerID is 4.4.4.4

Status codes: s suppressed, d damped,h history, * valid, > best, i - internal,

              r RIB-failure, S Stale, m multipath, bbackup-path, f RT-Filter,

              x best-external, aadditional-path, c RIB-compressed,

Origin codes: i - IGP, e - EGP, ? -incomplete

RPKI validation codes: V valid, Iinvalid, N Not found

    Network          Next Hop            Metric LocPrf Weight Path

 *> 1.1.1.1/32       14.1.1.1                 0             0 10 i

 * i                  2.2.2.2                  0    100     0 10 i

 *   192.168.1.0      14.1.1.1                50             0 10 i

 *>i                  2.2.2.2                 30    100     0 10 i

 *   192.168.2.0      14.1.1.1                50             0 10 i

 *>i                  2.2.2.2                 30    100     0 10 i

 *>  192.168.3.0      14.1.1.1                30             0 10 i

R4R1收到的路由192.168.1.0/24192.168.2.0/24metric值爲50,大於從R2傳遞過來的30,所以其下一跳爲R2

R3#show ip bgp

BGP table version is 47, local routerID is 3.3.3.3

Status codes: s suppressed, d damped,h history, * valid, > best, i - internal,

              r RIB-failure, S Stale, mmultipath, b backup-path, f RT-Filter,

              x best-external, aadditional-path, c RIB-compressed,

Origin codes: i - IGP, e - EGP, ? -incomplete

RPKI validation codes: V valid, Iinvalid, N Not found

    Network          Next Hop            Metric LocPrf Weight Path

 * i 1.1.1.1/32       34.1.1.2                 0    100     0 10 i

 *>i                  23.1.1.1                 0    100     0 10 i

 *>i192.168.1.0      23.1.1.1                30    100      0 10 i

 *>i192.168.2.0      23.1.1.1                30    100     0 10 i

 *>i192.168.3.0      34.1.1.2                30    100     0 10 i

       R3的路由可知,R3去往192.168.1.0/24192.168.2.0/24的路由走R2,去往192.168.4.0/24的路由走R4,而且其metric值爲設置的30,而1.1.1.1/32並沒修改其MED屬性值,其metric的默認值爲0

wKioL1SJaRjxyx6QAAEzHNBnq7E172.jpg

圖2

如圖2,增長一個路由器R5,與R4之間是EBGP關係,如今R5上查看BGP路由狀況:

R5#show ip bgp

BGP table version is 27, local routerID is 5.5.5.5

Status codes: s suppressed, d damped,h history, * valid, > best, i - internal,

              r RIB-failure, S Stale, mmultipath, b backup-path, f RT-Filter,

              x best-external, aadditional-path, c RIB-compressed,

Origin codes: i - IGP, e - EGP, ? -incomplete

RPKI validation codes: V valid, Iinvalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path

 *> 1.1.1.1/32       45.1.1.1                               0 100 10 i

*> 192.168.1.0      45.1.1.1                               0 100 10 i

 *>  192.168.2.0      45.1.1.1                               0 100 10 i

 *>  192.168.3.0      45.1.1.1                               0 100 10 i

從上可知R4通告192.168.1.0/24等網段至R5時,並無將metric屬性值傳遞過來;


小結:MED值越小越優先,默認值爲0MED值可在IBGP中傳遞,不會傳遞給第三方的AS號的路由器;

 

如圖2所示,在R5上建立一個環回接口,地址網段爲192.168.3.0/24,將上述在R1上配置的MED屬性值先去掉,在R4上查看路由狀況;

R4#show ip bgp       

BGP table version is 26, local routerID is 4.4.4.4

Status codes: s suppressed, d damped,h history, * valid, > best, i - internal,

              r RIB-failure, S Stale, mmultipath, b backup-path, f RT-Filter,

              x best-external, a additional-path, cRIB-compressed,

Origin codes: i - IGP, e - EGP, ? -incomplete

RPKI validation codes: V valid, Iinvalid, N Not found

    Network          Next Hop            Metric LocPrf Weight Path

*   192.168.3.0      14.1.1.1                 0             0 10 i

 * i                  2.2.2.2                  0    100     0 10 i

 *>                   45.1.1.2                 0             0 50 i

如今R4192.168.3.0/24的路由優先走R5,如今在R5上針對192.168.3.0/24設置其med值爲50,按照BGP選路原則,med值越小路由越優先;那麼R4上查看到的192.168.3.0/24,將會選擇R1做爲下一跳,配置完成後,查看R4路由狀況;

R5(config)#ip prefix-list med permit192.168.3.0/24
R5(config)#route-map med permit 10
R5(config-route-map)#match ip addressprefix-list med
R5(config-route-map)#set metric 50
R5(config)#route-map med permit 20
R5(config)#router bgp 50
R5(config-router)#neighbor 45.1.1.1 route-map med out

R4#show ip bgp       

     Network          Next Hop            Metric LocPrf Weight Path

*   192.168.3.0      14.1.1.1                 0             0 10 i

 * i                  2.2.2.2                  0    100     0 10 i

 *>                   45.1.1.2                50             0 50 i

從上可看出,從R5傳遞過來的路由的metric值爲50,從R1傳遞過來的metric值爲0,但並無選擇R1爲下一跳,由於從R1R5傳遞過來的路由的AS號不一樣,不會比較MED值,上述的選路爲優先最老的EBGP鄰居傳遞過來的路由。

  

   小結:當從不一樣的EBGP鄰居收到相同的路由,可是AS號不同時,是不會比較MED值的。


如今R4上配置命令:

R4(config-router)#bgp always-compare-med //表示AS號不一樣也比較MED

配置上述命令後,再次觀查R4路由的狀況

R4#show ip bgp

    Network          Next Hop            Metric LocPrf Weight Path

*   192.168.3.0      45.1.1.2                50             0 50 i

 *>                   14.1.1.1                 0             0 10 i

 *i                  2.2.2.2                  0    100     0 10 i

從上述輸出可知,R4選擇去往192.168.3.0/24的下一跳爲R1,選擇MED值較小的;


   小結:經過命令能夠忽略AS號的不一樣,而且進行MED值的比較。

相關文章
相關標籤/搜索