BGP的Community屬性大揭祕

1. 什麼是Community屬性

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

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

1internet :所有路由在默認情況下都屬於該團體

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

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

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

 

大家要注意NO_exportlocal-as的區別,如果沒有配置聯盟,兩者實現的效果都是一樣的,即都不可以傳輸本AS,但如果配置了聯盟,NO_EXPOR屬性還可以傳給聯盟內的其他子AS,而local-as則不可以

2、案例研究

 

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

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

實驗完成。

 

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