配置:
l 为路由条目添加community 属性值
1、 使用ACL或者前缀列表匹配需要添加community 属性值的路由条目,尽量使用前缀列表匹配。
(config)#ip prefix-list 1 permit 1.1.1.1/32
2、 定义一个route-map ,匹配到相应的路由条目,并且追加或者覆盖community 属性值。
(config)#route-map 1 permit 10
(config-route-map)# match ip address prefix-list 1 ##匹配需要添加community 属性的路由条目
(config-route-map)# set community 126:1 ##为匹配到的路由条目打上一个私有的community 属性值
(config-route-map)# set community no-advertise ##为匹配到的路由前缀打上一个众所周知的community属性值
(config-route-map)# set community 126:1 no-advertise ##为匹配到的路由前缀打上一个私有的和一个众所周知的community值。
3、在BGP中定义在发送或者接收路由时添加communti 属性值。
(config-router)#neighbor 192.168.12.2 route-map 1 out ##为BGP邻居配置策略,在发送BGP路由时应用route-map 1 的策略,也就是为相应的路由前缀打上community 值。
(config-router)# neighbor 192.168.12.2 send-community ##为邻居发送BGP路由时,携带community 属性值
4、查看带有community 属性值得BGP 路由
R2#show ip bgp community ##查看带有community 属性值的BGP条目
BGP table version is 8, local router ID is 192.168.23.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*>i1.1.1.1/32 192.168.12.1 0 100 0 i ##说明当前的路由前缀携带了community 值
5、查看BGP路由条目中的communtiy 值
R2#show ip bgp 1.1.1.1
BGP routing table entry for 1.1.1.1/32, version 8
Paths: (1 available, best #1, table Default-IP-Routing-Table)
Advertised to update-groups:
2
Local
192.168.12.1 from 192.168.12.1 (192.168.26.2)
Origin IGP, metric 0, localpref 100, valid, internal, best
Community: 126:1 ##路由条目中携带的community 值。
R2#show ip bgp 1.1.1.1
BGP routing table entry for 1.1.1.1/32, version 8
Paths: (1 available, best #1, table Default-IP-Routing-Table, not advertised to any peer)
Flag: 0x880
Not advertised to any peer
100
192.168.12.1 from 192.168.12.1 (1.1.1.3)
Origin IGP, metric 0, localpref 100, valid, external, best
Community: 100:1 1000:1 no-advertise ##当前路由前缀中携带了3个community 属性值
案例一
1.1.1.1/32 community:100:1
1.1.1.2/32 community:100:1 100:2
IP community-list 1 permit 100:1
Route-map 1
Match community 1
(config-router)#neighbor 192.168.1.1 route-map 1 in
通过以上配置后,1.1.1.1/32和1.1.1.2/32 都能进入BGP表,原因是在匹配的时候没有严格匹配。
案例二
1.1.1.1/32 community:100:1
1.1.1.2/32 community:100:1 100:2
IP community-list 1 permit 100:1
Route-map 1
Match community 1 exact-match
(config-router)#neighbor 192.168.1.1 route-map 1 in
通过以上配置,只有1.1.1.1/32的路由可以进去BGP表,因为进行了严格匹配。
案例三
1.1.1.1/32 community:100:1
1.1.1.2/32 community:100:1 100:2
IP community-list 1 permit 100:1 100:2
Route-map 1
Match community 1
(config-router)#neighbor 192.168.1.1 route-map 1 in
通过以上配置,只会有1.1.1.2/32的路由可以进入BGP表,因为同一条community-list 中的多个值是and关系,需要同时匹配,才算匹配。
案例四
1.1.1.1/32 community:100:1
1.1.1.2/32 community:100:1 100:2
ip community-list 1 permit 100:1
ip community-list 1 permit 100:2
Route-map 1
Match community 1
(config-router)#neighbor 192.168.1.1 route-map 1 in
通过以上配置,1.1.1.1/32和1.1.1.2/32的路由都可以进入BGP表
案例五
1.1.1.1/32 community:100:1
1.1.1.2/32 community:100:1 100:2
ip community-list standard comm permit 100:1
ip community-list standard comm permit 100:2
Route-map 1
Match community comm exact-match
(config-router)#neighbor 192.168.1.1 route-map 1 in
通过以上配置,1.1.1.1/32可以进入BGP表,因为1.1.1.2/32的路由不能严格匹配。
案例六
1.1.1.1/32 community:100:1
1.1.1.2/32 community:100:1 100:2
ip community-list 1 permit 100:1
ip community-list 2 permit 100:2
route-map 1 permit 10
match community 1 2
(config-router)#neighbor 192.168.1.1 route-map 1 in
通过以上配置,1.1.1.1/32和1.1.1.2/32的路由都可以进入BGP表
案例七
1.1.1.1/32 community:100:1
1.1.1.2/32 community:100:1 100:2
ip community-list standard comm permit 100:1
ip community-list standard comm2 permit 100:2
route-map 1 permit 10
match community comm comm2 exact-match
(config-router)#neighbor 192.168.1.1 route-map 1 in
通过那个配置,只有1.1.1.1/32的路由可以进入BGP表