Border Gateway Protocol (BGP) is the routing protocol used to exchange network reachability information between autonomous systems. It is widely deployed by Internet service providers, enterprise networks, cloud providers, and large data centers.
However, exchanging routes without carefully controlling which prefixes are accepted and advertised can introduce routing problems and security risks.
For example:
BGP route filtering solves these problems by controlling which routes a router accepts from its neighbors and which routes it advertises to them.
This guide explains how to configure BGP route filtering using prefix lists, route maps, AS-path filters, and BGP communities. It includes practical Cisco IOS and FRRouting (FRR) examples, verification commands, and troubleshooting techniques.
BGP route filtering is the process of applying routing policies to BGP updates exchanged between neighboring routers.
A BGP router can apply filtering in two main directions:
Consider this simplified topology:
ISP 1
AS 65010
|
|
192.0.2.1
|
+---------+
| Router A|
| AS 65001|
+---------+
|
198.51.100.1
|
+---------+
| Router B|
| AS 65002|
+---------+
|
|
Customer LAN
203.0.113.0/24 Router A receives routes from ISP 1 and exchanges routing information with Router B.
Without appropriate policies, the routers may accept or advertise prefixes that are not intended for that relationship.
A route-filtering policy can ensure that:
BGP filtering is not the same as firewall filtering. A firewall controls packets, while BGP policies control routing information before it influences forwarding decisions.
Understanding the direction of a policy is essential before applying any configuration.
Inbound filtering is applied to routes received from a neighbor.
For example, an enterprise may receive routes from an ISP but only want to accept a default route.
ISP
|
| Advertises:
| 0.0.0.0/0
| 8.8.8.0/24
| 203.0.113.0/24
|
v
Enterprise Router
|
| Inbound Policy:
| Permit 0.0.0.0/0
| Reject other prefixes
|
v
Routing Table An inbound policy helps prevent unwanted routes from entering the local BGP decision process.
Outbound filtering controls which routes are advertised to a neighbor.
For example, a company owns the following networks:
10.10.10.0/24
10.10.20.0/24
10.10.30.0/24 The company wants to advertise only:
10.10.10.0/24
10.10.20.0/24 An outbound policy can permit those two prefixes and reject everything else.
| Feature | Inbound Filtering | Outbound Filtering |
|---|---|---|
| Direction | From neighbor to local router | From local router to neighbor |
| Main purpose | Control received routes | Control advertised routes |
| Common use | Reject unauthorized prefixes | Prevent unintended advertisements |
| Typical policy | neighbor ... in | neighbor ... out |
Both directions should be considered when designing an eBGP routing policy.
The IETF document RFC 8212 specifies that eBGP routes must not be imported or exported without explicit policies for implementations following the standard.
Prefix lists are among the most common tools for BGP route filtering.
They allow administrators to match network prefixes and their prefix lengths.
A prefix list can permit or deny specific networks, including more-specific routes.
On Cisco IOS:
ip prefix-list CUSTOMER-IN permit 203.0.113.0/24 This entry matches exactly:
203.0.113.0/24 It does not automatically permit more-specific prefixes such as:
203.0.113.0/25
203.0.113.128/25 The ge and le parameters allow matching a range of prefix lengths.
Example:
ip prefix-list CUSTOMER-IN permit 203.0.113.0/24 ge 24 le 28 This permits matching prefixes within 203.0.113.0/24 with lengths from /24 through /28.
For example:
203.0.113.0/24
203.0.113.0/25
203.0.113.128/25
203.0.113.0/26 However, it does not permit a /29 or a prefix outside the specified network range.
If you only want to permit a particular prefix length, use an exact prefix-list entry:
ip prefix-list CUSTOMER-ONLY permit 203.0.113.0/24 This is often preferable when a customer is authorized to originate one specific network.
Cisco prefix lists have an implicit deny at the end.
For example:
ip prefix-list CUSTOMER-IN permit 203.0.113.0/24 Only the specified prefix is permitted. Any unmatched prefix is denied.
This behavior is important because a restrictive prefix list can unintentionally block all routes if the permitted prefixes are incomplete.
For more information, see Cisco’s BGP configuration documentation.
Suppose Router A receives routes from a customer using this BGP relationship:
Local AS: 65001
Customer AS: 65020
Customer Peer: 192.0.2.2
Authorized Prefix: 203.0.113.0/24 The objective is to accept only the customer’s authorized prefix.
ip prefix-list CUSTOMER-IN permit 203.0.113.0/24 Because the prefix list has an implicit deny, other prefixes will not match a permitted entry.
router bgp 65001
neighbor 192.0.2.2 remote-as 65020
neighbor 192.0.2.2 prefix-list CUSTOMER-IN in show ip prefix-list CUSTOMER-IN Check the neighbor configuration:
show running-config | section router bgp Inspect received routes where supported:
show ip bgp neighbors 192.0.2.2 routes The exact availability of received-route information depends on the platform and whether inbound soft-reconfiguration or an equivalent route-refresh mechanism is configured.
Important: Before applying a restrictive inbound policy to a production peer, identify all prefixes that the neighbor is expected to advertise. An incomplete allowlist can remove valid routes from the routing process.
Outbound filtering prevents a router from advertising unauthorized networks to a neighbor.
Consider this example:
Local AS: 65001
ISP AS: 65010
ISP Peer: 192.0.2.1
Networks:
10.10.10.0/24
10.10.20.0/24
10.10.30.0/24 Assume only the first two networks are approved for advertisement.
ip prefix-list ISP-OUT permit 10.10.10.0/24
ip prefix-list ISP-OUT permit 10.10.20.0/24 router bgp 65001
neighbor 192.0.2.1 remote-as 65010
neighbor 192.0.2.1 prefix-list ISP-OUT out show ip bgp neighbors 192.0.2.1 advertised-routes The intended advertisements are:
10.10.10.0/24
10.10.20.0/24 The third network should not be advertised through this neighbor.
Remember that a route must also be eligible for BGP advertisement. A prefix list does not originate routes by itself; it filters routes that BGP could otherwise advertise.
Route maps provide more flexible routing policies than prefix lists alone.
They can match routes based on several attributes and apply actions to those routes.
Common matching conditions include:
Common actions include:
Route maps are evaluated in sequence order.
A route-map entry can contain matching conditions and actions. If a route matches a deny entry, it is rejected. If it matches a permit entry, it is accepted and any configured actions are applied.
If no route-map entry permits a route, the route is denied by the route map.
Suppose the router should accept only:
203.0.113.0/24 Create a prefix list:
ip prefix-list CUSTOMER-PREFIX permit 203.0.113.0/24 Create a route map:
route-map CUSTOMER-IN permit 10
match ip address prefix-list CUSTOMER-PREFIX Apply it inbound:
router bgp 65001
neighbor 192.0.2.2 route-map CUSTOMER-IN in The route map permits routes matching the prefix list. Other routes do not match a permitting entry and are rejected.
A route map can also modify BGP attributes.
For example, set local preference to 200 for routes matching a specific prefix:
ip prefix-list PREFERRED-ROUTE permit 203.0.113.0/24
route-map ISP-IN permit 10
match ip address prefix-list PREFERRED-ROUTE
set local-preference 200
route-map ISP-IN permit 20 Apply the route map:
router bgp 65001
neighbor 192.0.2.1 route-map ISP-IN in The first entry assigns local preference 200 to the matching route. The second entry permits other routes without changing their local preference.
Local preference is an attribute used within an AS to influence the preferred outbound path. It is not a substitute for an inbound prefix authorization policy.
The AS_PATH attribute records the sequence of autonomous systems through which a BGP route has passed.
Administrators can use AS-path filters to match routes based on that sequence.
This is useful when:
Assume AS 65020 must not appear in the AS_PATH of routes accepted from a particular peer.
On Cisco IOS:
ip as-path access-list 20 deny _65020_
ip as-path access-list 20 permit .* Create a route map:
route-map ISP-IN permit 10
match as-path 20 Apply it:
router bgp 65001
neighbor 192.0.2.1 route-map ISP-IN in The AS-path access list rejects paths containing AS 65020 and permits other paths.
The underscore in Cisco’s AS-path regular expressions represents an AS-path boundary. This helps avoid matching an AS number as part of an unrelated larger number.
A commonly used AS-path expression is:
ip as-path access-list 10 permit ^$ This matches an empty AS_PATH, which is commonly associated with locally originated BGP routes.
Use AS-path filters carefully. Their behavior depends on the path being evaluated, and they should not replace prefix authorization.
BGP communities are optional transitive path attributes that allow networks to tag routes with additional policy information.
A community can identify how a route should be treated by other routers.
For example:
65001:100
65001:200
65001:300 An organization may define an internal policy such as:
| Community | Example Policy |
|---|---|
| 65001:100 | Customer routes |
| 65001:200 | Preferred routes |
| 65001:300 | Routes requiring special handling |
These values are examples of locally defined policy conventions, not universal meanings.
On Cisco IOS, a standard community list can be used with a route map:
ip community-list standard CUSTOMER-ROUTES permit 65001:100 Create a route map:
route-map CUSTOMER-POLICY permit 10
match community CUSTOMER-ROUTES
set local-preference 200 Apply it to the appropriate neighbor:
router bgp 65001
neighbor 192.0.2.2 route-map CUSTOMER-POLICY in This policy matches routes carrying the specified community and assigns local preference 200.
A router must be configured to send communities when the platform and neighbor configuration require it.
On Cisco IOS platforms supporting this syntax:
router bgp 65001
neighbor 192.0.2.2 send-community For standard, extended, or large communities, check the platform-specific syntax and ensure the appropriate community types are sent.
On FRRouting, an example is:
router bgp 65001
address-family ipv4 unicast
neighbor 192.0.2.2 send-community both
exit-address-family Some communities have standardized meanings.
For example:
no-export: Prevents a route from being advertised outside the local AS or confederation boundary as defined by the community’s behavior.no-advertise: Prevents further advertisement of the route to any BGP peer.local-AS: Restricts propagation beyond the local AS or confederation context according to the applicable BGP behavior.Do not confuse these well-known communities with locally defined values such as 65001:100.
For more details, consult the FRRouting BGP documentation.
Using multiple filtering techniques provides more precise control than relying on one condition.
For example, an ISP may want to:
A Cisco IOS example:
ip prefix-list CUSTOMER-PREFIXES permit 203.0.113.0/24
ip as-path access-list 20 deny _65030_
ip as-path access-list 20 permit .*
route-map CUSTOMER-IN permit 10
match ip address prefix-list CUSTOMER-PREFIXES
match as-path 20
set local-preference 200
router bgp 65001
neighbor 192.0.2.2 remote-as 65020
neighbor 192.0.2.2 route-map CUSTOMER-IN in In this example, the route must satisfy both matching conditions in the route-map entry.
The policy permits the specified prefix only when the AS_PATH does not contain AS 65030.
If you need to permit additional authorized prefixes, add them to the prefix list after validating the authorization.
Incorrect BGP advertisements can expose internal routes or cause traffic to follow unintended paths.
A robust routing policy should account for more than just the prefixes expected from a neighbor.
Important checks include:
Maintain an accurate list of prefixes that each customer or peer is authorized to originate.
Do not assume that a route is legitimate simply because it arrived through an established BGP session.
Prefixes that are not globally routable should not normally be accepted as public Internet routes.
Examples include:
10.0.0.0/8
172.16.0.0/12
192.168.0.0/16 These are private IPv4 address ranges defined by RFC 1918.
Also consider other special-purpose address ranges, documentation prefixes, and reserved networks as appropriate.
Use the IANA IPv4 Special-Purpose Address Registry as a reference rather than relying on an incomplete hand-written list.
A neighbor authorized to advertise a /24 should not automatically be allowed to advertise every more-specific prefix inside that range.
For example:
203.0.113.0/24
203.0.113.0/25
203.0.113.128/25 These are different route advertisements.
Use exact prefix matching or an explicitly approved prefix-length range.
A default route can redirect a large amount of traffic.
If a neighbor should not receive a default route, explicitly exclude it from the outbound policy.
The IETF BGP Operations and Security document (RFC 7454) provides operational recommendations for inbound and outbound filtering, including protection against inappropriate prefix announcements.
Prefix filtering controls which routes are accepted, but another important safeguard is limiting the number of prefixes received from a neighbor.
The BGP maximum-prefix feature can help protect a router if a peer unexpectedly sends a very large routing table.
On Cisco IOS, an example is:
router bgp 65001
neighbor 192.0.2.2 maximum-prefix 100 80 This configures a maximum of 100 prefixes, with an 80 percent warning threshold.
The exact behavior and supported options vary by platform and software release. Some platforms also support actions such as restarting the session after a configured interval or treating the threshold as warning-only.
Before choosing a limit:
Maximum-prefix protection is not a replacement for prefix filtering. It limits route volume but does not determine whether individual prefixes are authorized.
FRRouting (FRR) provides BGP functionality for Linux-based routers and network appliances.
Its configuration supports prefix lists, route maps, AS-path access lists, and BGP communities.
The following example shows how to accept one authorized customer prefix and apply an inbound policy.
router bgp 65001
neighbor 192.0.2.2 remote-as 65020 ip prefix-list CUSTOMER-IN seq 10 permit 203.0.113.0/24 router bgp 65001
address-family ipv4 unicast
neighbor 192.0.2.2 prefix-list CUSTOMER-IN in
exit-address-family show ip prefix-list
show bgp ipv4 unicast summary
show bgp ipv4 unicast neighbors 192.0.2.2 Create a prefix list:
ip prefix-list PREFERRED seq 10 permit 203.0.113.0/24 Create a route map:
route-map CUSTOMER-IN permit 10
match ip address prefix-list PREFERRED
set local-preference 200 Apply it:
router bgp 65001
address-family ipv4 unicast
neighbor 192.0.2.2 route-map CUSTOMER-IN in
exit-address-family FRR supports additional matching and setting options. Check the documentation for the installed release before deploying configuration changes.
Official references:
After configuring a policy, verify that it behaves as expected.
Do not assume that a successful configuration command means the intended routes are being accepted or advertised.
On Cisco IOS:
show ip bgp summary On FRRouting:
show bgp ipv4 unicast summary Check that the neighbor session is Established and inspect the received-prefix count.
On Cisco:
show ip prefix-list This displays configured prefix-list entries and their match counters where supported.
show route-map Review the sequence entries, match conditions, and route-map counters.
On Cisco platforms where the command is supported:
show ip bgp neighbors 192.0.2.2 routes This helps identify routes accepted from the neighbor.
show ip bgp neighbors 192.0.2.2 advertised-routes Compare the displayed advertisements with the intended outbound policy.
show ip bgp On FRRouting:
show bgp ipv4 unicast Verify that expected routes are present and that unwanted routes are not being selected.
Some verification commands depend on platform capabilities and whether inbound route storage or soft-reconfiguration is enabled.
A BGP session can remain Established even when routing policies prevent the exchange of expected prefixes.
Use the following checks to identify the problem.
Possible causes:
Useful commands:
show ip bgp summary
show ip prefix-list
show route-map
show ip bgp neighbors 192.0.2.2 Check both sides of the BGP relationship before changing the policy.
A common cause is an incomplete prefix list or route map.
For example:
ip prefix-list CUSTOMER-IN permit 203.0.113.0/24 If the neighbor advertises 203.0.113.128/25, the entry above will not match it.
Review the actual advertised prefixes and decide whether more-specific routes should be permitted.
Do not broaden the policy automatically. Confirm that each additional prefix is authorized.
Check the outbound policy attached to the affected peer:
show running-config | section router bgp Verify:
out direction.Inspect the route map:
show route-map Check whether:
Remember that multiple match conditions in one route-map entry are generally evaluated together. A route may fail to match if one of the conditions is not satisfied.
Check the neighbor’s received-prefix count and the configured maximum-prefix limit.
Review the source of the additional routes before increasing the limit.
An unexpected increase can indicate:
BGP policy changes may require a route refresh or soft reset to re-evaluate existing routes.
On Cisco platforms that support it:
clear ip bgp 192.0.2.2 soft in For outbound policy re-evaluation:
clear ip bgp 192.0.2.2 soft out Check platform support and the operational impact before executing these commands.
Avoid a hard BGP reset unless it is necessary. A hard reset can interrupt the session and temporarily remove routes.
A secure BGP policy should be designed around the relationship between each router and its neighbors.
Follow these recommendations:
For broader routing security guidance, review RFC 7454: BGP Operations and Security.
BGP route filtering is the process of controlling which routing prefixes a BGP router accepts from neighbors and which prefixes it advertises to them. It helps prevent unauthorized advertisements, route leaks, and unwanted routing changes.
Inbound filtering controls routes received from a neighbor, while outbound filtering controls routes advertised to that neighbor. Both are important for maintaining a predictable routing policy.
A BGP prefix list is a policy tool that matches network prefixes and prefix lengths. It can permit or deny specific routes and more-specific networks using parameters such as ge and le.
A prefix list primarily matches network prefixes. A route map supports more complex policies by matching multiple route attributes and modifying attributes such as local preference, MED, and communities.
BGP communities are route tags used to communicate policy information between routers. They can identify customer routes, influence routing preferences, and control route propagation.
On Cisco IOS, configure an AS-path access list and reference it in a route map or neighbor filter-list. This allows policies to match routes based on the autonomous systems present in the AS_PATH attribute.
Maximum-prefix limits the number of prefixes accepted from a BGP neighbor. It helps protect routers from unexpectedly large route advertisements but does not replace prefix authorization policies.
A normal route-filtering policy does not usually cause the BGP session to become Idle. The session can remain Established while the policy rejects all received or advertised routes. Session failures should be investigated separately.
Possible causes include an inactive address family, missing advertisements from the peer, an inbound prefix list rejecting every route, or a route map without a matching permit entry.
Explicit inbound and outbound policies are essential for secure eBGP operation. RFC 8212 specifies default-reject behavior for eBGP routes when import or export policies are absent in implementations following the standard.
BGP route filtering is a fundamental part of reliable and secure routing design.
Prefix lists provide precise control over network prefixes, route maps support more advanced routing policies, AS-path filters identify routes based on their autonomous-system paths, and communities allow routers to exchange policy information.
For production networks, combine these mechanisms with explicit inbound and outbound policies, maximum-prefix protection, and regular route verification.
A carefully designed BGP filtering policy helps prevent route leaks, unauthorized advertisements, and unexpected routing behavior while keeping the routing infrastructure predictable and manageable.
Related reading: BGP Neighbor Troubleshooting: Fix Idle, Active, Connect & OpenSent States
For another routing-policy perspective, see OSPF Route Filtering Explained: Prefix Lists, Distribute Lists and Route Control.
Introduction A Linux server can experience connection failures even when its network interface is working…
Introduction TCP retransmissions are an important indicator of network reliability and performance. When a Linux…
Open Shortest Path First (OSPF) is a link-state routing protocol widely used in enterprise networks…
Group Policy is one of the most important management features in Windows Server Active Directory…
Windows DNS servers play an essential role in Active Directory environments, allowing computers, servers, applications,…
Linux services are responsible for running many of the critical components that keep a server…