Repository navigation
Communities
BGP Communities are optional transitive attributes used to tag BGP routes for policy-based routing, traffic engineering, and route filtering. ExaBGP provides comprehensive support for Standard Communities (RFC 1997), Extended Communities (RFC 4360), and Large Communities (RFC 8092), enabling flexible route tagging and sophisticated BGP policy implementations.
- What are BGP Communities?
- Community Types
- Standard Communities (RFC 1997)
- Extended Communities (RFC 4360)
- Large Communities (RFC 8092)
- Well-Known Communities
- Configuration Examples
- API Usage
- Use Cases and Patterns
- Community Matching and Filtering
- Common Errors and Solutions
- See Also
- References
BGP Communities are tags attached to BGP routes that enable policy-based routing without relying solely on prefix or AS-path matching. Communities allow network operators to:
- Group routes with similar characteristics
- Apply policies based on route tags
- Signal intent to upstream/downstream neighbors
- Implement traffic engineering through selective route preference
- Control route propagation across AS boundaries
- Optional Transitive Attribute (Type Code: 8)
- Routes can carry multiple communities
- Preserved across AS boundaries (unless stripped)
- No inherent meaning - semantics defined by network operators
- Policy tool - used in route-maps, import/export filters
ExaBGP supports three types of BGP communities:
| Type | RFC | Size | Format | Use Case |
|---|---|---|---|---|
| Standard | RFC 1997 | 32-bit | AS:Value (16:16) | General route tagging |
| Extended | RFC 4360 | 64-bit | Type:AS:Value | VPN, Traffic Eng, QoS |
| Large | RFC 8092 | 96-bit | ASN:Val1:Val2 (32:32:32) | Large ASN support |
Compatibility:
- ✅ Standard Communities: Universal support (all BGP implementations)
- ✅ Extended Communities: Wide support (MPLS VPN, FlowSpec, EVPN)
⚠️ Large Communities: Modern implementations only (2017+)
32-bit value typically represented as:
-
Decimal:
AS:Value(16-bit:16-bit) -
Hexadecimal:
0xAAAAVVVV
Example:
-
65001:100→ ASN 65001, Value 100 -
0xFDE90064→ Hexadecimal representation
┌─────────────────┬─────────────────┐
│ ASN (16 bits) │ Value (16 bits)│
├─────────────────┼─────────────────┤
│ 0-65535 │ 0-65535 │
└─────────────────┴─────────────────┘
Example: 65001:100
├────┘ └──┘
AS Value
Conventions:
- High 16 bits: Typically AS number (administrative domain)
- Low 16 bits: Locally significant value (policy identifier)
| Community | Hex | Meaning | Use Case |
|---|---|---|---|
NO_EXPORT |
0xFFFFFF01 |
Do not advertise outside confederation | Local routes |
NO_ADVERTISE |
0xFFFFFF02 |
Do not advertise to any peer | Blackhole local |
NO_EXPORT_SUBCONFED |
0xFFFFFF03 |
Do not advertise outside sub-confederation | Confederation internal |
NOPEER |
0xFFFFFF04 |
Do not advertise to peers | Upstream only |
BLACKHOLE |
0xFFFF029A |
Blackhole/discard traffic | DDoS mitigation |
# Static route with standard communities
neighbor 192.168.1.1 {
router-id 192.168.1.2;
local-address 192.168.1.2;
local-as 65001;
peer-as 65000;
family {
ipv4 unicast;
}
static {
route 10.0.0.0/8 {
next-hop 192.168.1.2;
community [ 65001:100 65001:200 ]; # Multiple communities
}
}
}#!/usr/bin/env python3
import sys
def send(command):
"""Write one command, then read lines until ExaBGP answers it."""
sys.stdout.write(command + "\n")
sys.stdout.flush()
while True:
line = sys.stdin.readline()
if not line: # ExaBGP closed the pipe: it is stopping
sys.exit(0)
answer = line.strip()
if answer == "done":
return True
if answer == "error":
sys.stderr.write(f"ExaBGP refused: {command}\n")
return False
# Announce route with standard communities
route = (
"announce route 10.0.0.0/8 "
"next-hop 192.168.1.2 "
"community [ 65001:100 65001:200 ]"
)
send(route)
# Well-known community: NO_EXPORT
route_no_export = (
"announce route 172.16.0.0/12 "
"next-hop 192.168.1.2 "
"community [ no-export ]" # or 65535:65281 or 0xFFFFFF01
)
send(route_no_export)
# BLACKHOLE community for DDoS mitigation
blackhole = (
"announce route 1.2.3.4/32 "
"next-hop 192.0.2.1 "
"community [ blackhole ]" # or 65535:666 or 0xFFFF029A
)
send(blackhole)The programs on this page read ExaBGP's answer after each command with this send() function, as Reading the answers explains. ExaBGP 6.0 writes these commands with a peer * selector, see How a program talks to ExaBGP.
Traffic Engineering:
65001:100 # Prefer path via ISP-1
65001:200 # Prefer path via ISP-2
65001:300 # Backup path
Geographic Tagging:
65001:1000 # Routes from US-East
65001:2000 # Routes from EU-West
65001:3000 # Routes from APAC
Route Origin:
65001:10 # Customer routes
65001:20 # Peer routes
65001:30 # Upstream routes
64-bit value with structured format:
┌────────────┬────────────┬──────────────────────┐
│ Type (8) │ Sub (8) │ Value (48 bits) │
├────────────┼────────────┼──────────────────────┤
│ 0x00-0xFF │ 0x00-0xFF │ Format depends on type│
└────────────┴────────────┴──────────────────────┘
Total: 64 bits (8 bytes)
ExaBGP supports these extended community types:
Purpose: VPN membership (L3VPN, EVPN, L2VPN)
Formats:
# Type 0x0002: AS:Value (2-byte AS)
target:65001:100
# Type 0x0102: IP:Value
target:192.0.2.1:100
# Type 0x0202: AS:Value (4-byte AS), chosen by ExaBGP 6.0 when the AS is above 65535
target:4200000000:100
ExaBGP 5.x encodes target:4200000000:100 with the IPv4 type 0x0102 instead, so with 5.x a 4-byte AS route target has to be written in hexadecimal: 0x0202fa56ea000064. target4: is the IPv4 type, with the first field read as a 32 bit number: target4:4200000000:100 is target:250.86.234.0:100.
Example:
# VPNv4 route with Route Target
route = (
"announce route 10.0.0.0/8 "
"next-hop 192.168.1.2 "
"rd 65001:1 "
"extended-community [ target:65001:100 ]"
)Purpose: Route source identification
Formats:
origin:65001:100 # 2-byte AS
origin:192.0.2.1:100 # IPv4
origin:4200000000:100 # 4-byte AS (ExaBGP 6.0)
The FlowSpec actions (traffic-rate, traffic-marking, redirect) are extended communities on the wire. ExaBGP writes them as actions in the then block of a flow route:
then {
rate-limit 1000000; # traffic-rate, bytes per second (0 drops the traffic)
mark 10; # traffic-marking: the DSCP to set
redirect 65001:100; # redirect to the VRF of this route target
discard; # a traffic-rate of 0
}
redirect:65001:100 is also accepted as an extended-community, as are redirect:<ipv4>:<n> (type 0x8108) and redirect:<asn>:<n> with an AS above 65535 (type 0x8208). See FlowSpec Actions.
Purpose: Specify tunnel encapsulation type (RFC 9012)
ExaBGP has no name for this extended community in the configuration or the API, so it is written in hexadecimal, and printed as encap: in what ExaBGP sends to a program:
0x030c000000000008 # encap:VXLAN
0x030c000000000002 # encap:GRE
Purpose: MAC address mobility in EVPN
ExaBGP prints it as mac-mobility:<sequence> in the EVPN routes it receives, followed by :sticky when the low-order bit of its flags octet, the sticky/static flag of RFC 7432 section 7.7, is set. Only that bit is read, so another flag bit set beside it no longer hides it. It has no name for it in the configuration or the API, and ExaBGP cannot announce EVPN routes (see EVPN Overview).
neighbor 192.168.1.1 {
router-id 192.168.1.2;
local-address 192.168.1.2;
local-as 65001;
peer-as 65000;
family {
ipv4 mpls-vpn; # VPNv4 uses extended communities
}
static {
route 10.0.0.0/8 {
next-hop 192.168.1.2;
rd 65001:1;
label 100;
extended-community [ target:65001:100 origin:65001:1 ];
}
}
}#!/usr/bin/env python3
import sys
def send(command):
"""Write one command, then read lines until ExaBGP answers it."""
sys.stdout.write(command + "\n")
sys.stdout.flush()
while True:
line = sys.stdin.readline()
if not line: # ExaBGP closed the pipe: it is stopping
sys.exit(0)
answer = line.strip()
if answer == "done":
return True
if answer == "error":
sys.stderr.write(f"ExaBGP refused: {command}\n")
return False
# VPNv4 route with Route Target
vpn_route = (
"announce route 10.0.0.0/8 "
"next-hop 192.168.1.2 "
"rd 65001:1 "
"label 100 "
"extended-community [ target:65001:100 target:65001:200 ]"
)
send(vpn_route)
# FlowSpec with traffic action
flowspec = (
"announce flow route "
"{ match { source 1.2.3.4/32; destination-port =80; } "
"then { rate-limit 0; } }" # Drop traffic
)
send(flowspec)96-bit (12-byte) value supporting 4-byte ASNs:
┌──────────────┬──────────────┬──────────────┐
│ ASN (32-bit) │ Val1 (32-bit)│ Val2 (32-bit)│
├──────────────┼──────────────┼──────────────┤
│ 0-4294967295 │ 0-4294967295 │ 0-4294967295 │
└──────────────┴──────────────┴──────────────┘
Example: 4200000000:100:200
├────────┘ └─┘ └─┘
4-byte ASN V1 V2
Problem with Standard Communities:
- Limited to 16-bit AS numbers (0-65535)
- 4-byte ASNs (4200000000+) cannot fit in standard communities
Solution:
- Large Communities support full 32-bit ASNs
- Two 32-bit values for flexible encoding
- Total 96 bits (12 bytes)
neighbor 192.168.1.1 {
router-id 192.168.1.2;
local-address 192.168.1.2;
local-as 4200000000; # 4-byte ASN
peer-as 65000;
family {
ipv4 unicast;
}
static {
route 10.0.0.0/8 {
next-hop 192.168.1.2;
large-community [ 4200000000:100:200 4200000000:100:300 ];
}
}
}#!/usr/bin/env python3
import sys
def send(command):
"""Write one command, then read lines until ExaBGP answers it."""
sys.stdout.write(command + "\n")
sys.stdout.flush()
while True:
line = sys.stdin.readline()
if not line: # ExaBGP closed the pipe: it is stopping
sys.exit(0)
answer = line.strip()
if answer == "done":
return True
if answer == "error":
sys.stderr.write(f"ExaBGP refused: {command}\n")
return False
# Route with large communities (4-byte ASN)
route = (
"announce route 10.0.0.0/8 "
"next-hop 192.168.1.2 "
"large-community [ 4200000000:100:200 4200000000:100:300 ]"
)
send(route)
# Mix standard and large communities
mixed = (
"announce route 172.16.0.0/12 "
"next-hop 192.168.1.2 "
"community [ 65001:100 ] "
"large-community [ 4200000000:1:1 ]"
)
send(mixed)Geographic + Function Encoding:
4200000000:1000:1 # Region: North America, Function: Customer
4200000000:2000:1 # Region: Europe, Function: Customer
4200000000:3000:2 # Region: Asia, Function: Peer
Hierarchical Tagging:
ASN:Category:Subcategory
4200000000:100:1 # Category: Customer, Subcategory: Tier-1
4200000000:100:2 # Category: Customer, Subcategory: Tier-2
4200000000:200:1 # Category: Peer, Subcategory: IX
Meaning: Do not advertise outside the local AS (or confederation)
Use Case: Keep routes local to your network
Example:
# Route visible only within AS 65001
route = (
"announce route 10.0.0.0/8 "
"next-hop 192.168.1.2 "
"community [ no-export ]" # or 65535:65281
)Behavior:
- eBGP neighbors: Route NOT advertised
- iBGP neighbors: Route IS advertised
- Confederation: Route advertised within confederation
Meaning: Do not advertise to ANY peer (iBGP or eBGP)
Use Case: Route is local to this router only
Example:
# Route not propagated to any neighbor
route = (
"announce route 172.16.0.0/12 "
"next-hop 192.168.1.2 "
"community [ no-advertise ]" # or 65535:65282
)Behavior:
- eBGP neighbors: Route NOT advertised
- iBGP neighbors: Route NOT advertised
- Local use only
Meaning: Traffic to this prefix should be discarded (blackholed)
Use Case: DDoS mitigation, null routing
Example:
# Blackhole attacker IP
blackhole = (
"announce route 1.2.3.4/32 "
"next-hop 192.0.2.1 " # Discard next-hop
"community [ blackhole ]" # or 65535:666
)Typical Workflow:
- Detect DDoS attack from 1.2.3.4
- Announce 1.2.3.4/32 with BLACKHOLE community
- Upstream provider discards traffic to 1.2.3.4
- DDoS mitigated
Meaning: Do not advertise to lateral peers (only upstream/downstream)
Use Case: Control route propagation in transit networks
Example:
route = (
"announce route 192.168.0.0/16 "
"next-hop 192.168.1.2 "
"community [ nopeer ]" # or 65535:65284
)ExaBGP has names for the five communities above (no-export, no-advertise, no-export-subconfed, nopeer, blackhole). The other well-known communities registered with IANA are written as numbers, for example:
65535:1 # ACCEPT_OWN (RFC 7611)
65535:6 # LLGR_STALE (RFC 9494)
65535:7 # NO_LLGR (RFC 9494)
neighbor 192.168.1.1 {
router-id 192.168.1.2;
local-address 192.168.1.2;
local-as 65001;
peer-as 65000;
family {
ipv4 unicast;
}
static {
# Route with multiple community types
route 10.0.0.0/8 {
next-hop 192.168.1.2;
community [ 65001:100 65001:200 no-export ];
large-community [ 4200000000:1:1 ];
}
# Blackhole route
route 1.2.3.4/32 {
next-hop 192.0.2.1;
community [ blackhole ];
}
}
}neighbor 192.168.1.1 {
router-id 192.168.1.2;
local-address 192.168.1.2;
local-as 65001;
peer-as 65000;
family {
ipv4 flow;
}
flow {
route {
match {
source 1.2.3.0/24;
destination-port =80;
protocol tcp;
}
then {
discard;
}
}
}
}neighbor 192.168.1.1 {
router-id 192.168.1.2;
local-address 192.168.1.2;
local-as 65001;
peer-as 65000;
family {
ipv4 mpls-vpn;
}
static {
route 10.0.0.0/8 {
next-hop 192.168.1.2;
rd 65001:100;
label 1000;
extended-community [ target:65001:100 origin:65001:1 ];
}
}
}#!/usr/bin/env python3
"""Standard communities via text API"""
import sys
def send(command):
"""Write one command, then read lines until ExaBGP answers it."""
sys.stdout.write(command + "\n")
sys.stdout.flush()
while True:
line = sys.stdin.readline()
if not line: # ExaBGP closed the pipe: it is stopping
sys.exit(0)
answer = line.strip()
if answer == "done":
return True
if answer == "error":
sys.stderr.write(f"ExaBGP refused: {command}\n")
return False
# Single community
send("announce route 10.0.0.0/8 next-hop 192.168.1.2 community 65001:100")
# Multiple communities
send("announce route 10.0.1.0/24 next-hop 192.168.1.2 community [ 65001:100 65001:200 ]")
# Well-known communities
send("announce route 10.0.2.0/24 next-hop 192.168.1.2 community no-export")
# BLACKHOLE community
send("announce route 1.2.3.4/32 next-hop 192.0.2.1 community blackhole")#!/usr/bin/env python3
"""Extended communities via text API"""
import sys
def send(command):
"""Write one command, then read lines until ExaBGP answers it."""
sys.stdout.write(command + "\n")
sys.stdout.flush()
while True:
line = sys.stdin.readline()
if not line: # ExaBGP closed the pipe: it is stopping
sys.exit(0)
answer = line.strip()
if answer == "done":
return True
if answer == "error":
sys.stderr.write(f"ExaBGP refused: {command}\n")
return False
# Route Target
send(
"announce route 10.0.0.0/8 next-hop 192.168.1.2 rd 65001:1 label 100 "
"extended-community [ target:65001:100 ]"
)
# Multiple extended communities
send(
"announce route 10.0.1.0/24 next-hop 192.168.1.2 rd 65001:1 label 101 "
"extended-community [ target:65001:100 target:65001:200 origin:65001:1 ]"
)
# IPv4-based Route Target
send(
"announce route 10.0.2.0/24 next-hop 192.168.1.2 rd 65001:1 label 102 "
"extended-community [ target:192.0.2.1:100 ]"
)
# 4-byte ASN Route Target (ExaBGP 6.0, see above for 5.x)
send(
"announce route 10.0.3.0/24 next-hop 192.168.1.2 rd 65001:1 label 103 "
"extended-community [ target:4200000000:100 ]"
)#!/usr/bin/env python3
"""Large communities via text API"""
import sys
def send(command):
"""Write one command, then read lines until ExaBGP answers it."""
sys.stdout.write(command + "\n")
sys.stdout.flush()
while True:
line = sys.stdin.readline()
if not line: # ExaBGP closed the pipe: it is stopping
sys.exit(0)
answer = line.strip()
if answer == "done":
return True
if answer == "error":
sys.stderr.write(f"ExaBGP refused: {command}\n")
return False
# Single large community
send(
"announce route 10.0.0.0/8 next-hop 192.168.1.2 "
"large-community 4200000000:100:200"
)
# Multiple large communities
send(
"announce route 10.0.1.0/24 next-hop 192.168.1.2 "
"large-community [ 4200000000:100:200 4200000000:100:300 ]"
)
# Mix standard and large communities
send(
"announce route 10.0.2.0/24 next-hop 192.168.1.2 "
"community [ 65001:100 no-export ] "
"large-community [ 4200000000:1:1 ]"
)Commands are always written as text, as above. JSON is the format of what ExaBGP sends to a program: a route received with communities arrives like this (the update part of the message), with the attributes shared by every route of the UPDATE, and each community as a list of numbers:
{
"update": {
"attribute": {
"origin": "igp",
"local-preference": 100,
"community": [ [ 65001, 100 ], [ 65001, 200 ] ],
"large-community": [ [ 4200000000, 1, 1 ] ]
},
"announce": {
"ipv4 unicast": {
"192.168.1.2": [ { "nlri": "10.0.0.0/8" } ]
}
}
}
}The message is under neighbor.message in the JSON object; Community Matching and Filtering shows a program reading it.
Scenario: Control route preference through community-based MED adjustment.
Example:
#!/usr/bin/env python3
"""Traffic engineering with community-based path selection"""
import sys
def send(command):
"""Write one command, then read lines until ExaBGP answers it."""
sys.stdout.write(command + "\n")
sys.stdout.flush()
while True:
line = sys.stdin.readline()
if not line: # ExaBGP closed the pipe: it is stopping
sys.exit(0)
answer = line.strip()
if answer == "done":
return True
if answer == "error":
sys.stderr.write(f"ExaBGP refused: {command}\n")
return False
# Two paths for the same prefix need ADD-PATH and a path-information each:
# without them, the second announcement replaces the first
# Prefer path via ISP-1
route_isp1 = (
"announce route 10.0.0.0/8 "
"next-hop 192.168.1.10 "
"path-information 1 "
"community [ 65001:100 ]" # Tag: ISP-1
)
# Backup path via ISP-2
route_isp2 = (
"announce route 10.0.0.0/8 "
"next-hop 192.168.1.20 "
"path-information 2 "
"community [ 65001:200 ]" # Tag: ISP-2 (backup)
)
send(route_isp1)
send(route_isp2)
# Upstream applies policy:
# - Match community 65001:100 → Set LOCAL_PREF 150
# - Match community 65001:200 → Set LOCAL_PREF 100Upstream router configuration (Cisco example):
route-map SET_PREF permit 10
match community 100 ! Community-list matching 65001:100
set local-preference 150
route-map SET_PREF permit 20
match community 200 ! Community-list matching 65001:200
set local-preference 100
Scenario: Null-route attacker IP via BGP blackhole community.
Example:
#!/usr/bin/env python3
"""DDoS mitigation with blackhole community"""
import sys
import time
def send(command):
"""Write one command, then read lines until ExaBGP answers it."""
sys.stdout.write(command + "\n")
sys.stdout.flush()
while True:
line = sys.stdin.readline()
if not line: # ExaBGP closed the pipe: it is stopping
sys.exit(0)
answer = line.strip()
if answer == "done":
return True
if answer == "error":
sys.stderr.write(f"ExaBGP refused: {command}\n")
return False
def blackhole_ip(attacker_ip):
"""Blackhole attacker IP via BGP"""
route = (
f"announce route {attacker_ip}/32 "
f"next-hop 192.0.2.1 " # next hop the routers send to their discard interface
f"community [ blackhole ]"
)
send(route)
print(f"Blackholed {attacker_ip}", file=sys.stderr)
def unblackhole_ip(attacker_ip):
"""Remove blackhole"""
withdraw = f"withdraw route {attacker_ip}/32"
send(withdraw)
print(f"Removed blackhole for {attacker_ip}", file=sys.stderr)
# Detect attack and blackhole
attacker = "1.2.3.4"
blackhole_ip(attacker)
# Wait for attack to subside
time.sleep(300) # 5 minutes
# Remove blackhole
unblackhole_ip(attacker)Upstream provider action:
- Receives route with BLACKHOLE community
- Installs route with next-hop pointing to null0
- Traffic to 1.2.3.4/32 is dropped at edge
Scenario: L3VPN route distribution using Route Target communities.
Example:
#!/usr/bin/env python3
"""L3VPN with Route Target communities"""
import sys
def send(command):
"""Write one command, then read lines until ExaBGP answers it."""
sys.stdout.write(command + "\n")
sys.stdout.flush()
while True:
line = sys.stdin.readline()
if not line: # ExaBGP closed the pipe: it is stopping
sys.exit(0)
answer = line.strip()
if answer == "done":
return True
if answer == "error":
sys.stderr.write(f"ExaBGP refused: {command}\n")
return False
# Customer A VPN routes (RT: 65001:100)
def announce_customer_a_routes():
"""Announce routes for Customer A VPN"""
routes = [
"10.0.0.0/8",
"172.16.0.0/12",
]
for prefix in routes:
route = (
f"announce route {prefix} "
f"next-hop 192.168.1.2 "
f"rd 65001:1 "
f"label 1000 "
f"extended-community [ target:65001:100 ]"
)
send(route)
print("Customer A routes announced (RT: 65001:100)", file=sys.stderr)
# Customer B VPN routes (RT: 65001:200)
def announce_customer_b_routes():
"""Announce routes for Customer B VPN"""
routes = [
"192.168.0.0/16",
]
for prefix in routes:
route = (
f"announce route {prefix} "
f"next-hop 192.168.1.2 "
f"rd 65001:2 "
f"label 2000 "
f"extended-community [ target:65001:200 ]"
)
send(route)
print("Customer B routes announced (RT: 65001:200)", file=sys.stderr)
announce_customer_a_routes()
announce_customer_b_routes()
# PE routers import routes matching configured Route Targets
# Customer A PE: Import RT 65001:100
# Customer B PE: Import RT 65001:200Scenario: Tag routes by geographic origin for policy-based routing.
Example:
#!/usr/bin/env python3
"""Geographic tagging with large communities"""
import sys
def send(command):
"""Write one command, then read lines until ExaBGP answers it."""
sys.stdout.write(command + "\n")
sys.stdout.flush()
while True:
line = sys.stdin.readline()
if not line: # ExaBGP closed the pipe: it is stopping
sys.exit(0)
answer = line.strip()
if answer == "done":
return True
if answer == "error":
sys.stderr.write(f"ExaBGP refused: {command}\n")
return False
# Define geographic regions
REGIONS = {
"us-east": "4200000000:1000:1",
"us-west": "4200000000:1000:2",
"eu-central": "4200000000:2000:1",
"apac": "4200000000:3000:1",
}
def announce_regional_route(prefix, region, nexthop):
"""Announce route with geographic tag"""
if region not in REGIONS:
print(f"Unknown region: {region}", file=sys.stderr)
return
route = (
f"announce route {prefix} "
f"next-hop {nexthop} "
f"large-community [ {REGIONS[region]} ]"
)
send(route)
print(f"Announced {prefix} from {region}", file=sys.stderr)
# Announce routes from different regions
announce_regional_route("10.1.0.0/16", "us-east", "10.0.1.1")
announce_regional_route("10.2.0.0/16", "eu-central", "10.0.2.1")
announce_regional_route("10.3.0.0/16", "apac", "10.0.3.1")Scenario: Advertise routes within AS but not to external peers.
Example:
#!/usr/bin/env python3
"""Internal-only routes with NO_EXPORT"""
import sys
def send(command):
"""Write one command, then read lines until ExaBGP answers it."""
sys.stdout.write(command + "\n")
sys.stdout.flush()
while True:
line = sys.stdin.readline()
if not line: # ExaBGP closed the pipe: it is stopping
sys.exit(0)
answer = line.strip()
if answer == "done":
return True
if answer == "error":
sys.stderr.write(f"ExaBGP refused: {command}\n")
return False
# Infrastructure routes - iBGP only
internal_routes = [
"10.0.0.0/8", # Internal network
"172.16.0.0/12", # Private network
"192.168.0.0/16", # Management network
]
for prefix in internal_routes:
route = (
f"announce route {prefix} "
f"next-hop 192.168.1.2 "
f"community [ no-export ]"
)
send(route)
print("Internal routes announced with NO_EXPORT", file=sys.stderr)
# Routes visible to iBGP neighbors only
# NOT advertised to eBGP peers#!/usr/bin/env python3
"""Filter routes based on communities"""
import sys
import json
def process_route_with_communities():
"""Process routes and filter by community"""
for line in sys.stdin:
line = line.strip()
if line in ('done', 'error') or line.startswith('error:'):
continue # the answer to a command
try:
msg = json.loads(line)
if msg.get('type') == 'update':
update = msg['neighbor']['message']['update']
# the attributes are shared by every route of the UPDATE
communities = update.get('attribute', {}).get('community', [])
for afi_safi, announcements in update.get('announce', {}).items():
for nexthop, prefixes in announcements.items():
for prefix_data in prefixes:
prefix = prefix_data.get('nlri')
# Check for specific community
if [65001, 100] in communities:
print(f"Route {prefix} has community 65001:100 - accept", file=sys.stderr)
# Install route
# Check for NO_EXPORT
if [0xFFFF, 0xFF01] in communities:
print(f"Route {prefix} has NO_EXPORT - local only", file=sys.stderr)
# Do not re-advertise
# Check for BLACKHOLE
if [0xFFFF, 0x029A] in communities:
print(f"Route {prefix} has BLACKHOLE - null route", file=sys.stderr)
# Install blackhole route
except json.JSONDecodeError:
pass
process_route_with_communities()#!/usr/bin/env python3
"""Select best path based on community"""
import sys
import json
def select_path_by_community(routes):
"""Select path with preferred community
routes: the "update" objects (neighbor.message.update) of the received paths
"""
PREFER_COMMUNITIES = [
[65001, 100], # Highest preference
[65001, 200], # Medium preference
[65001, 300], # Lowest preference
]
best_route = None
best_priority = 999
for route in routes:
communities = route.get('attribute', {}).get('community', [])
for priority, preferred in enumerate(PREFER_COMMUNITIES):
if preferred in communities:
if priority < best_priority:
best_priority = priority
best_route = route
break
return best_route
# Use in route selection logicSymptom: Community sent but not received by peer.
Causes:
- Peer strips communities on import
- Community filtered by peer's route-map
- Community type not supported by peer
Solutions:
# Verify peer configuration
# Cisco - ensure communities not removed:
router bgp 65000
neighbor 192.168.1.2 send-community
neighbor 192.168.1.2 send-community extended
neighbor 192.168.1.2 send-community large
# Juniper:
protocols {
bgp {
group peers {
neighbor 192.168.1.2 {
import allow-communities;
}
}
}
}
# Check ExaBGP logs
grep -i community /var/log/exabgp.logSymptom: Community parsing error.
Answer and log (ExaBGP 6.0):
error: Could not parse route: route 10.0.0.0/8 next-hop 192.168.1.2 community 65001-100
configuration.parse.error message=line 1:49: invalid community name 65001-100
Correct Formats:
# Standard community: AS:Value (colon separator)
"community 65001:100" # Correct
"community 65001-100" # Wrong (hyphen)
# Extended community: type:AS:Value
"extended-community target:65001:100" # Correct
"extended-community 65001:100" # Also accepted: read as target:65001:100
# Large community: ASN:Val1:Val2
"large-community 4200000000:100:200" # Correct
"large-community 4200000000:100" # Wrong (missing Val2)Symptom: Well-known community syntax error.
Correct Syntax:
# Correct (hyphen, in any case: NO-EXPORT works too):
"community no-export"
"community no-advertise"
"community blackhole"
"community nopeer"
# Also correct (numeric):
"community 65535:65281" # NO_EXPORT
"community 65535:65282" # NO_ADVERTISE
"community 65535:666" # BLACKHOLE
# Also accepted: the underscore forms no_export and no_advertise
# Wrong:
"community noexport" # Wrong formatSymptom: Large communities not recognized by peer.
Causes:
- Peer does not support RFC 8092
- Peer running old software version
Large communities are an optional transitive attribute: there is no capability to negotiate, so a peer which does not support them accepts them and passes them on without acting on them (RFC 4271 section 5).
Solutions:
# Verify peer supports large communities (2017+ software)
# Cisco IOS XR 6.0.0+, IOS XE 16.6+, NX-OS 7.0(3)I5+
# Juniper Junos 14.2+
# Fallback to standard communities for legacy peers
# Use standard communities for 2-byte ASNs
# Use large communities only with supporting peers- Extended Communities - Legacy extended communities documentation
- FlowSpec Actions - FlowSpec extended communities
- L3VPN Overview - Route Target communities
- EVPN Overview - EVPN extended communities
- DDoS Mitigation - BLACKHOLE community usage
- Configuration Syntax - Community configuration
- RFC 1997: BGP Communities Attribute
- RFC 3765: NOPEER Community for BGP Route Scope Control
- RFC 4360: BGP Extended Communities Attribute
- RFC 5668: 4-Octet AS Specific BGP Extended Community
- RFC 5701: IPv6 Address Specific BGP Extended Community Attribute
- RFC 7153: IANA Registries for BGP Extended Communities
- RFC 7999: BLACKHOLE Community
- RFC 8092: BGP Large Communities Attribute
- RFC 8642: Policy Behavior for Well-Known BGP Communities
- RFC Support - All implemented RFCs
- RFC Information - Detailed RFC implementation
-
Source Code:
src/exabgp/bgp/message/update/attribute/community/ -
Attribute Type Code:
- Standard: 8
- Extended: 16
- Large: 32
- ExaBGP Version: 3.x, 4.x, 5.x/main
Getting Started
Configuration
- Configuration Syntax
- Neighbor Configuration
- Directives A-Z
- Syntax Reference
- Templates
- Environment Variables
- Process Configuration
API
- API Overview
- Text API Reference
- JSON API Reference
- API Commands
- Writing API Programs
- Error Handling
- Production Best Practices
Address Families
- Overview
- IPv4 Unicast
- IPv6 Unicast
- FlowSpec
- EVPN
- L3VPN
- BGP-LS
- VPLS
- SRv6 / MUP
- Multicast
- RT Constraint
Features
Use Cases
Tools
Operations
Reference
- Architecture
- Design
- Attribute Reference
- Command Reference
- BGP State Machine
- Capabilities
- Communities
- Examples Index
- Glossary
- RFC Support
Integration
Migration
Community
External