bgp的community是一種路由标記方法,用于確定路由過濾和選擇的連續性,并且具有可傳遞性。
實驗拓撲:
實驗需求:
1.在r1上設定11.0/24 community屬性值100:11,将屬性傳遞給r3
2. 為11.11.11.0/24再添加一條屬性值no-export
3. 在r1上network 12.0/24網段,根據嚴格比對原則,在r3上将到達12.0/24網段的metric設定為1111,而11.0/24的metric不變。
4. 在r3上删除11.0/24路由的no-export屬性,12.0/24的屬性不變。
實驗步驟:
(1)完成基本配置
r1
router bgp 100
neighbor 12.0.0.2 remote-as 200
r2
router bgp 200
neighbor 12.0.0.1 remote-as 100
neighbor 23.0.0.3 remote-as 300
r3
router bgp 300
neighbor 23.0.0.2 remote-as 200
等待鄰居關系建立完畢,在r1上network11.11.11.0/24 。
network 11.11.11.0 mask 255.255.255.0
r2,r3都學習到了
在r1上為11.11.11.0/24這條路由添加community屬性值100:11 ,并使r2,r3都學習到。
ip prefix-list 11 permit 11.11.11.0/24 //字首清單比對此條路由
route-map test permit 10
match ip address prefix-list 11
set community 100:11
route-map test per 20
neighbor 12.0.0.2 send-community
neighbor 12.0.0.2 route-map test out //應用于出方向
neighbor 23.0.0.3 send-community //預設不傳遞community屬性,加上這條就可以傳遞了
r2,r3上檢視前要使用轉換格式指令
ip bgp-community new-format
!
ip bgp-community new-format
然後可以看到此條屬性值了。
r2/r3
clear ip b * s
(2)下面在r2上為11.11.11.0/24添加一條屬性no-export(此屬性意思:不向ebgp鄰居傳遞此條路由)
ip community-list 11 permit 100:11
match community 11
set community no-export additive //表示添加,不加此關鍵字則覆寫原屬性
route-map test permit 20
neighbor 23.0.0.3 route-map test out
可以在r3上檢視了
(3)在r1上network 12.0/24網段,在r3上将到達12.0/24網段的metric設定為1111.
network 12.12.12.0 mask 255.255.255.0
no ip community-list 11
ip community-list 11 permit internet //全部比對
ip community-list 11 permit no-export
match community 11 exact-match //嚴格比對no-export ,多一點少一點都不行
set metric 1111
!
neighbor 23.0.0.2 route-map test in
檢視結果
12.0/24的metric值已經變了,而11.0/24的仍然為空。
(4)首先檢視一下11.0/24和12.0/24的屬性情況
11.11.11.0/24 屬性:100:1 、 no-export
12.12.12.0/24 屬性:no-export
現在需求是删除11.11.11.0/24的no-export屬性,其他不變。
ip community-list standard del permit no-export //重新定義一條屬性清單比對no-export屬性
route-map test permit 10
no match community 11 exact-match
set comm-list del delete
r3:clear ip b * s
已删除11.11.11.0/24的no-export 屬性,其他沒變,實驗結束。