BGP的Community屬性大揭祕

1. 什麼是Community屬性app

首先community是一個任選可透明傳送屬性,它能夠用於簡化策略的執行。其次Community屬性可讓一組目的網段享用某些相同的路由特性,但這些目的網段沒必要要求處於同一AS。它能夠用來控制BGP信息所通過的路由器怎麼對待這條BGP信息。ide

community屬性能夠用一組48位組的數值表示。格式爲:AANN,前兩個8位組表示自治系統,後28位組表示出地管理目的而定義的標識符。如下是定義的一些團體屬性,即公共的community屬性:oop

1internet :全部路由在默認狀況下都屬於該團體學習

2No_export: 表示攜帶該值的路由不能公佈給EBGP鄰居,若是配置了BGP聯盟,則不能將該路由宣告到聯盟以外,攜帶該值的路由能夠公佈給聯盟內的其它子自治系統但不能在構成聯盟的AS之外進行公佈this

3no_advertise:若是接收到的路由攜帶該數值,那就誰也不宣告,包括EBGPIBGP對等體。spa

4local-as :帶有該團體屬性的路由條目只在本as內傳播,不能宣告給ebgp對等體。 code

 

你們要注意NO_exportlocal-as的區別,若是沒有配置聯盟,二者實現的效果都是同樣的,即都不能夠傳輸本AS,但若是配置了聯盟,NO_EXPOR屬性還能夠傳給聯盟內的其餘子AS,而local-as則不能夠 orm

2、案例研究 router

 

如上圖在r1上宣告10.1.1.0-10.1.4.04條路由,要求以下blog

r2上能夠看到10.1.1.0-10.1.4.04條路由

R3上能夠看到10.1.2.0-10.1.4.03條路由

R4上能夠看到10.1.3.0-10.1.4.02條路由

R5上能夠看到10.1.4.01條路由

固然實現這種效果的方法有不少,可是請你想想若是咱們使用Community屬性應該怎麼實現?

建議以下:

R1上使用前綴列表匹配路由,分別對不一樣的路由設置不一樣的community屬性

針對10.1.1.0設置no_advertise屬性

針對10.1.2.0設置local-AS屬性

針對10.1.3.0設置No_export屬性

針對10.1.3.0設置none屬性

具體配置以下:

R1的配置

**************************************

1)首先設置前綴列表匹配路由

ip prefix-list 1 seq 5 permit 10.1.1.0/24   

ip prefix-list 2 seq 5 permit 10.1.2.0/24            

ip prefix-list 3 seq 5 permit 10.1.3.0/24     

ip prefix-list 4 seq 5 permit 10.1.4.0/24

備註:使用前綴列表能夠作到精確匹配路由

2)使用route-map作路由策略

route-map comm-test permit 10

 match ip address prefix-list 1

 set community no-advertise

route-map comm-test permit 20

 match ip address prefix-list 2

 set community local-AS

route-map comm-test permit 30

 match ip address prefix-list 3

 set community no-export

route-map comm-test permit 40

 match ip address prefix-list 4

 set community none

3BGP的配置

router bgp 100

 no synchronization

 bgp router-id 1.1.1.1

 network 10.1.1.0 mask 255.255.255.0

 network 10.1.2.0 mask 255.255.255.0

 network 10.1.3.0 mask 255.255.255.0

 network 10.1.4.0 mask 255.255.255.0

 neighbor 192.1.12.2 remote-as 234

 neighbor 192.1.12.2 send-community

 neighbor 192.1.12.2 route-map comm-test out //調用route-map

 no auto-summary

備註:切記不要忘記向鄰居發送community屬性,使用如下命令

neighbor 192.1.12.2 send-community

R2的配置

**************************************

1BGP的配置

router bgp 64512

 no synchronization

 bgp router-id 2.2.2.2

 bgp confederation identifier 234

 neighbor 3.3.3.3 remote-as 64512

 neighbor 3.3.3.3 update-source Loopback0

 neighbor 3.3.3.3 next-hop-self

 neighbor 3.3.3.3 send-community

 neighbor 192.1.12.1 remote-as 100

 no auto-summary

 

2)在R2上查看bgp

r2#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

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

 

   Network          Next Hop            Metric LocPrf Weight Path

*> 10.1.1.0/24      192.1.12.1               0             0 100 i

*> 10.1.2.0/24      192.1.12.1               0             0 100 i

*> 10.1.3.0/24      192.1.12.1               0             0 100 i

*> 10.1.4.0/24      192.1.12.1               0             0 100 i

以上能夠看到4條路由都學習到了,再查看某一條具體的路由條目,查看其詳細屬性

r2#sh ip bgp 10.1.1.0

BGP routing table entry for 10.1.1.0/24, version 5

Paths: (1 available, best #1, table Default-IP-Routing-Table, not advertised to any peer)

  Not advertised to any peer

  100

    192.1.12.1 from 192.1.12.1 (1.1.1.1)

      Origin IGP, metric 0, localpref 100, valid, external, best

      Community: no-advertise   //屬性已傳遞

r2#sh ip bgp 10.1.2.0

BGP routing table entry for 10.1.2.0/24, version 8

Paths: (1 available, best #1, table Default-IP-Routing-Table, not advertised outside local AS)

  Advertised to non peer-group peers:

  3.3.3.3

  100

    192.1.12.1 from 192.1.12.1 (1.1.1.1)

      Origin IGP, metric 0, localpref 100, valid, external, best

      Community: local-AS    //屬性已傳遞

…………

R3的配置

**************************************

1BGP的配置

router bgp 64512

 no synchronization

 bgp router-id 3.3.3.3

 bgp confederation identifier 234

 bgp confederation peers 64514

 neighbor 2.2.2.2 remote-as 64512

 neighbor 2.2.2.2 next-hop-self

 neighbor 4.4.4.4 remote-as 64514

 neighbor 4.4.4.4 ebgp-multihop 255

 neighbor 4.4.4.4 update-source Loopback0

 neighbor 4.4.4.4 send-community

 no auto-summary

2)在R3上查看bgp表,能夠看到沒有學習到     10.1.1.0/24的路由 

r3#sh ip bgp

BGP table version is 7, local router ID is 3.3.3.3

   Network          Next Hop            Metric LocPrf Weight Path

*>i10.1.2.0/24      2.2.2.2                  0    100      0 100 i

*>i10.1.3.0/24      2.2.2.2                  0    100      0 100 i

*>i10.1.4.0/24      2.2.2.2                  0    100      0 100 i

 

R4的配置

**************************************

1BGP的配置

router bgp 64514

 no synchronization

 bgp router-id 4.4.4.4

 bgp confederation identifier 234

 bgp confederation peers 64512

 neighbor 3.3.3.3 remote-as 64512

 neighbor 3.3.3.3 ebgp-multihop 255

 neighbor 3.3.3.3 update-source Loopback0

 neighbor 192.1.45.5 remote-as 500

 no auto-summary

2)在R4上查看BGP表,能夠看到10.1.2.0這條路由沒有過來

r4#sh ip bgp

   Network          Next Hop            Metric LocPrf Weight Path

*> 10.1.3.0/24      2.2.2.2                  0    100      0 (64512) 100 i

*> 10.1.4.0/24      2.2.2.2                  0    100      0 (64512) 100 i

查看10.1.3.0/24的詳細信息

r4#sh ip bgp 10.1.3.0/24

BGP routing table entry for 10.1.3.0/24, version 2

Paths: (1 available, best #1, table Default-IP-Routing-Table, not advertised to EBGP peer)

  Not advertised to any peer

  (64512) 100

    2.2.2.2 (metric 2) from 3.3.3.3 (3.3.3.3)

      Origin IGP, metric 0, localpref 100, valid, confed-external, best

      Community: no-export  //攜帶該值的路由不能公佈給EBGP鄰居

 

R5的配置

**************************************

1BGP的配置

router bgp 500

 no synchronization

 bgp router-id 5.5.5.5

 bgp cluster-id 2886734593

 bgp log-neighbor-changes

 neighbor 192.1.45.4 remote-as 234

 no auto-summary

 

r5#sh ip bgp

BGP table version is 4, local router ID is 5.5.5.5

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

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

 

   Network          Next Hop            Metric LocPrf Weight Path

*> 10.1.4.0/24      192.1.45.4                             0 234 100 i

實驗完成。

相關文章
相關標籤/搜索