Understanding BGP communities
What are BGP communities?
The BGP community attribute is a numerical value that can be assigned to a specific prefix and advertised to other neighbors. When the neighbor receives the prefix it will examine the community value and take proper action whether it is filtering or modifying other attributes.
By default the community attribute is removed from the update before being sent to the neighbor. To allow community values to be sent to a specific neighbor the command neighbor x.x.x.x send-community must be applied.
BGP has default 4 well known communities that can be used to mark prefixes; listed as follows:
- Internet: advertise these routes to all neighbors.
- Local-as: prevent sending routes outside the local As within the confederation.
- No-Advertise: do not advertise this route to any peer, internal or external.
- No-Export: do not advertise this route to external BGP peers.
Why using BGP communities?
Communities can be used to mark a set of prefixes that share a common property. Upstream providers can use these marks to apply a common routing policy such as filtering or assigning a specific local preference.
As a service provider you can make an agreement with your customers on a specific policy to be applied to their prefixes using communities; this gives your customers the freedom to change the policy of a prefix just by changing the community attribute value with no support from your side.
Consult this link for an example of Using BGP community values to control routing policy.
How to set community attribute values?
- Network command: the optional route-map at the end of the network command can be used to set the community of the advertised prefix.
- Aggregate address: the Attribute-map option can be used to set the attributes of the aggregate route including the community value.
- Neighbor command: a route-map can be used to set the community of specific prefixes received from or sent to the neighbor.
- Redistribution: you can set the community attribute of the redistributed prefixes using the route-map option of the redistribute command.
How to match community attribute values?
- A standard or expanded IP community list must be configured specifying the values to be matched.
- Use the match statement in a route map to match the values specified in the IP community list.
- The route-map can be used to apply routing policies by setting other attributes or filtering the prefix based on the matched community value.
Here is a simple example:
R1 is directly connected to R2 with an IBGP session between them; the example will show you how to use communities to manipulate BGP attributes:
Configuration of R1:
R1(config)#ip bgp-community new-format R1(config)#route-map SETCOM R1(config-route-map)#set community 1:10 R1(config)#router bgp 12 R1(config-router)#neighbor 192.168.12.2 remote-as 12 R1(config-router)#neighbor 192.168.12.2 send-community !-- The network 22.214.171.124 is advertised with community 1:10 R1(config-router)#network 126.96.36.199 mask 255.255.255.0 route-map SETCOM !-- R1's BGP table R1(config)#do sh ip bgp 188.8.131.52 BGP routing table entry for 184.108.40.206/24, version 2 Paths: (1 available, best #1, table Default-IP-Routing-Table) Not advertised to any peer Local 0.0.0.0 from 0.0.0.0 (192.168.127.1) Origin IGP, metric 0, localpref 100, weight 32768, valid, sourced, local, best Community: 1:10
Configuration of R2:
R2(config)#router bgp 12 R2(config-router)#nei 192.168.12.1 remot 12 !-- Before applying any policies R2#sh ip bgp 220.127.116.11 BGP routing table entry for 18.104.22.168/24, version 2 Paths: (1 available, best #1, table Default-IP-Routing-Table) Flag: 0x820 Not advertised to any peer Local 192.168.12.1 from 192.168.12.1 (192.168.127.1) Origin IGP, metric 0, localpref 100, valid, internal, best Community: 1:10 !-- Match the community using a standard community-list R2(config)#ip community-list 1 permit 1:10 R2(config)#route-map COM R2(config-route-map)#match community 1 R2(config-route-map)#set metric 100 R2(config)#router bgp 12 R2(config-router)#nei 192.168.12.1 route-map COM in !-- After applying the policy the metric changed to 100 R2#sh ip bgp 22.214.171.124/24 BGP routing table entry for 126.96.36.199/24, version 3 Paths: (1 available, best #1, table Default-IP-Routing-Table) Flag: 0x800 Not advertised to any peer Local 192.168.12.1 from 192.168.12.1 (192.168.127.1) Origin IGP, metric 100, localpref 100, valid, internal, best Community: 1:10
Hope I have been informative; more practical examples on using BGP communities is coming in later posts.
As you can see in the comments below, Ivan has spotted an myth about the internet community in his post mysteries of the internet community; please check out for details.