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 。
R1
router bgp 100
network 11.11.11.0 mask 255.255.255.0
R2,R3都學習到了
在R1上爲11.11.11.0/24這條路由添加community屬性值100:11 ,並使R2,R3都學習到。
R1
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
router bgp 100
neighbor 12.0.0.2 send-community
neighbor 12.0.0.2 route-map test out //應用於出方向
R2
router bgp 200
neighbor 23.0.0.3 send-community //默認不傳遞community屬性,加上這條就可以傳遞了
R2,R3上查看前要使用轉換格式命令
R2
ip bgp-community new-format
!
R3
ip bgp-community new-format
!
然後可以看到此條屬性值了。
R2/R3
clear ip b * s
(2)下面在R2上爲11.11.11.0/24添加一條屬性no-export(此屬性意思:不向EBGP鄰居傳遞此條路由)
R2
ip community-list 11 permit 100:11
route-map test permit 10
match community 11
set community no-export additive //表示添加,不加此關鍵字則覆蓋原屬性
!
route-map test permit 20
router bgp 200
neighbor 23.0.0.3 route-map test out
可以在R3上查看了
R3
clear ip b * s
(3)在R1上network 12.0/24網段,在R3上將到達12.0/24網段的metric設置爲1111.
R1
router bgp 100
network 12.12.12.0 mask 255.255.255.0
R2
no ip community-list 11
ip community-list 11 permit internet //全部匹配
!
R3
ip community-list 11 permit no-export
route-map test permit 10
match community 11 exact-match //嚴格匹配no-export ,多一點少一點都不行
set metric 1111
!
route-map test permit 20
!
router bgp 300
neighbor 23.0.0.2 route-map test in
clear ip b * s
查看結果
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屬性,其他不變。
R3
no ip community-list 11
ip community-list 11 permit 100:11
ip community-list standard del permit no-export //重新定義一條屬性列表匹配no-export屬性
route-map test permit 10
no match community 11 exact-match
match community 11
set metric 1111
set comm-list del delete
查看結果
R3:clear ip b * s
已刪除11.11.11.0/24的no-export 屬性,其他沒變,實驗結束。