BGP Communities for Traffic Engineering: Prepend, Blackhole
BGP communities are tags attached to a route that tell your upstreams, and sometimes their upstreams, what to do with it. Used for traffic engineering, they let you shift inbound traffic with prepends, limit how far a prefix propagates with NO_EXPORT, announce only to certain regions, and drop attack traffic with a blackhole community, all without calling anyone.
This guide covers what each mechanism does, what it cannot do, and how to configure it on a Linux router or BGP VDS with BIRD 2 or FRRouting. Examples use documentation resources: AS64496 is your ASN, AS64511 is an upstream, and 192.0.2.0/24 is your prefix.
What a BGP community actually is
A community is a 32-bit value, usually written ASN:value (for example 64511:100), attached to a route as an optional attribute. It has no meaning by itself. Meaning comes from the network that reads it. There are three flavors:
| Type | Format | Notes |
|---|---|---|
| Standard (RFC 1997) | 64511:100 |
16-bit ASN, 16-bit value |
| Well-known | 65535:65281 etc. |
Same meaning everywhere |
| Large (RFC 8092) | 64496:1:100 |
Needed for 32-bit ASNs |
Well-known communities you can rely on:
NO_EXPORT(65535:65281): do not advertise outside the local AS (or confederation).NO_ADVERTISE(65535:65282): do not advertise to any BGP peer.BLACKHOLE(65535:666, RFC 7999): drop traffic to this prefix. Support is up to the receiving network.
Everything else, such as "prepend twice to Europe" or "set local-pref 80", is defined by each provider in its own documentation. Never guess those values. Read your upstream's community list first.
Know the limits before you start
Traffic engineering with BGP only influences inbound traffic, and only as far as other networks agree to listen. Keep these rules in mind:
- Best-path selection runs local-pref first, then AS-path length. A remote network that sets a higher local-pref for a customer or peer route will ignore your prepends.
- A more-specific prefix always beats a less-specific one in forwarding. Announcing a /24 beats any prepend on a /23.
- Communities are optional and non-transitive in practice: many networks strip or ignore communities they do not define.
- Your outbound path is controlled by your own local-pref, not by communities you send.
1. AS-path prepending
Prepending repeats your ASN in the AS-path to make a route look longer and therefore less attractive. It is the bluntest tool, and it is often worth trying first because it needs no provider support.
BIRD 2, applied on export to the backup upstream:
filter export_backup {
if net ~ [192.0.2.0/24] then {
bgp_path.prepend(64496);
bgp_path.prepend(64496);
accept;
}
reject;
}
FRRouting:
route-map TO-BACKUP permit 10
match ip address prefix-list MY-PREFIXES
set as-path prepend 64496 64496
!
router bgp 64496
address-family ipv4 unicast
neighbor 198.51.100.1 route-map TO-BACKUP out
Two or three prepends are usually enough. More than that rarely changes anything and just clutters the table. If your upstream offers a "prepend toward peer X" community, it is often better than prepending to everyone, because it targets the specific path you want to de-prefer.
2. NO_EXPORT and scoped announcements
Attach NO_EXPORT to a route and the neighbor that receives it will keep it for its own use but will not pass it to its peers or upstreams. This is useful when you announce a more-specific prefix only so a single upstream can use it as a backup or for local delivery.
BIRD 2:
filter export_noexport {
if net = 192.0.2.128/25 then {
bgp_community.add((65535, 65281));
accept;
}
reject;
}
FRRouting:
route-map TO-UPSTREAM-B permit 10
match ip address prefix-list MORE-SPECIFIC
set community no-export
!
neighbor 198.51.100.1 send-community
The send-community statement matters. In FRR, communities are not sent to a neighbor unless you enable it (send-community both for standard and large). BIRD sends them by default.
Note that NO_EXPORT only works if the neighbor honors it, and it affects only the next AS. If you need to keep a prefix out of a specific region or peer group, use the provider's own scoping communities.
3. Regional and selective announcement
Larger transit providers publish communities that control where they announce your route: only to customers, not to a given region, not to specific peers, or only to certain exchange points. A typical pattern looks like this (illustrative only, not any real provider's scheme):
64511:1000 do not announce to peers
64511:1001 announce to European peers only
64511:1002 announce to North American peers only
64511:2002 prepend once toward all peers
64511:9999 do not announce to AS-specific peer (value = ASN)
Use cases:
- Keep traffic for a regional audience (a game server cluster, say) on regional paths by limiting the announcement scope.
- Steer a noisy peer's traffic to a different upstream by suppressing your route toward that peer.
- Reduce long intercontinental detours caused by a distant peer winning on local-pref.
BIRD 2 example tagging a prefix with a provider's scope community and a large community:
filter export_upstream_a {
if net = 192.0.2.0/24 then {
bgp_community.add((64511, 1001));
bgp_large_community.add((64511, 0, 64500));
accept;
}
reject;
}
Change one thing at a time, wait for convergence, and check the result before the next change.
4. Blackhole (RTBH) communities
Remotely triggered blackholing lets you ask an upstream to discard all traffic destined to one IP under attack, so the rest of your network stays reachable and the link does not saturate. The cost is that the targeted IP is unreachable for legitimate users, too. It is a last resort, not a mitigation.
Typical rules, which vary by provider:
- Usually only a /32 (IPv4) or /128 (IPv6) is accepted, and it must sit inside a prefix you are authorized to announce (verified by ROA and IRR objects).
- The route carries the provider's blackhole community, or the standard
65535:666. - Your route filters on the provider side must allow the longer prefix. Some providers accept more-specifics only when tagged.
- Many also want
NO_EXPORTadded so the /32 does not spread.
BIRD 2:
protocol static blackhole4 {
ipv4;
route 192.0.2.55/32 blackhole;
}
filter export_rtbh {
if net = 192.0.2.55/32 then {
bgp_community.add((65535, 666));
bgp_community.add((65535, 65281));
accept;
}
reject;
}
Remove the static route as soon as the attack ends, then withdraw the announcement. Automating this from flow-based detection is common. A monitoring system such as NixMon can detect volumetric attacks from flow data, and a script can then add or remove the blackhole route. Keep a human approval step or tight thresholds, so a false positive does not take a healthy IP offline.
If you want to keep the service up during an attack rather than sacrifice the target IP, filtering or scrubbing upstream is the better answer than blackholing. See DDoS protection and firewall.
Verifying the result
Do not trust the config. Look at what the rest of the internet sees.
- On your router, confirm what you send:
birdc show route export upstream_a 192.0.2.0/24 allor, in FRR,show ip bgp neighbors 198.51.100.1 advertised-routes. - Check that communities are present:
birdc show route for 192.0.2.0/24 alland look atBGP.community. - Query a public looking glass for your prefix to see AS-path and communities from another vantage point. The Nixcon looking glass offers BGP route, ping, and traceroute queries from Izmir, Frankfurt, and the US.
- Run traceroutes before and after the change to confirm that the path actually moved.
Common mistakes and fixes
- No effect from prepending. The remote network uses local-pref that overrides AS-path length. Use the provider's action communities, or announce more-specifics.
- Communities never arrive. In FRR,
send-communityis missing. Also check that your upstream does not strip communities from customers. - Blackhole route rejected. The prefix is longer than the provider accepts, the ROA does not cover it (check max-length), or your IRR object is missing. Fix the objects first.
- Whole /24 withdrawn instead of one IP. You blackholed the covering prefix rather than the /32. Always target the single address.
- Leaked communities. Do not forward customer or upstream communities blindly to other neighbors. Clean the community set on export and add only the ones you mean to send.
- Flapping after many changes. Make one change at a time and let route dampening and convergence settle.
Running this on a BGP VDS
All of the above works on a VM with a BGP session, as long as the provider documents its community support. On a BGP-enabled VDS at Nixcon (AS40368), you announce your own ASN and IP block, with or without DDoS protection, and see how your routes look from the looking glass. Check the community documentation for the specific session type you use before depending on any particular action community.
Frequently asked questions
Do BGP communities work with every upstream?
No. Only the well-known communities have a standard meaning, and even those depend on the receiving network honoring them. Action communities such as regional scoping or local-pref changes are defined by each provider, so read their documentation.
Why doesn't AS-path prepending move my traffic?
Remote networks usually evaluate local-pref before AS-path length. If they prefer a given neighbor by policy, your prepends are ignored. Use provider action communities or more-specific prefixes instead.
What is the BGP blackhole community?
65535:666 is the well-known BLACKHOLE community from RFC 7999. It asks the receiving network to discard traffic to the tagged prefix, normally a single /32 or /128. Support and accepted prefix lengths vary by provider.
Does NO_EXPORT stop a route from spreading globally?
It tells the receiving AS not to advertise the route to external neighbors. It only works if that neighbor honors it, and it is mainly a tool for keeping backup or more-specific routes local.