· 7 min read

BGP Maximum Prefix Limit: Cisco, Juniper, MikroTik, BIRD, FRR

A BGP maximum-prefix limit tells your router to warn, and then tear down the session, when a neighbor sends more routes than you expect. Paired with strict inbound prefix filtering, it is the cheapest protection an edge router has against route leaks and full-table floods. This guide gives working configs for Cisco, Juniper, MikroTik, BIRD and FRR, plus sane limits per peer type.

Why you need both limits and filters

They solve different problems:

Typical failures that a limit catches:

Without a limit, the router accepts the routes, burns CPU on best-path selection, and may exhaust FIB memory. The result is an outage, not a graceful degradation.

Per-peer-type limits

Pick limits from real data, not guesses. Use PeeringDB info_prefixes4/6 for IX and private peers, and the IRR object count (for example from bgpq4) for customers.

Peer type IPv4 limit IPv6 limit Warning Restart
Customer (single /24) 2-5 2-5 80% 10-15 min auto
Customer (with AS-SET) registered count + ~25% same 80% 10-15 min auto
IX route server / bilateral PeeringDB value + ~50% same 80% 15-30 min auto
Private peer agreed count + ~50% same 80% 30 min or manual
Transit, default only 2 2 n/a manual
Transit, full table current table + 20-30% current table + 20-30% 90% long timer or manual

For full-table transit, check the current global table size and your router's FIB capacity first. IPv4 is above 1 million routes and IPv6 is above 200 thousand at the time of writing, and both keep growing. Review these numbers every quarter. A limit that is too tight is its own outage.

Restart timers: Auto-restart helps customers recover on their own after fixing a leak. For full-table sessions, a restart means a full re-learn and high CPU, so use a long timer or require manual clearing and alert a human.

Cisco IOS-XE

ip prefix-list CUST-64496-IN seq 10 permit 198.51.100.0/24
!
route-map CUST-64496-IN permit 10
 match ip address prefix-list CUST-64496-IN
 set local-preference 200
!
router bgp 64500
 neighbor 192.0.2.2 remote-as 64496
 address-family ipv4 unicast
  neighbor 192.0.2.2 activate
  neighbor 192.0.2.2 maximum-prefix 5 80 restart 10
  neighbor 192.0.2.2 route-map CUST-64496-IN in

maximum-prefix 5 80 restart 10 means: limit of 5, warning log at 80%, and when the limit is exceeded the session goes down and comes back after 10 minutes. Without restart, the session stays down until you run clear ip bgp. warning-only logs without tearing down, which is useful during a baselining period. On IOS-XR the command is the same under the address family.

Juniper Junos

set policy-options policy-statement CUST-64496-IN term OK from route-filter 198.51.100.0/24 upto /24
set policy-options policy-statement CUST-64496-IN term OK then local-preference 200
set policy-options policy-statement CUST-64496-IN term OK then accept
set policy-options policy-statement CUST-64496-IN term DENY then reject

set protocols bgp group CUSTOMERS type external
set protocols bgp group CUSTOMERS import CUST-64496-IN
set protocols bgp group CUSTOMERS neighbor 192.0.2.2 peer-as 64496
set protocols bgp group CUSTOMERS neighbor 192.0.2.2 family inet unicast prefix-limit maximum 5
set protocols bgp group CUSTOMERS neighbor 192.0.2.2 family inet unicast prefix-limit teardown 80 idle-timeout 10

Junos has two counters. prefix-limit counts routes received from the peer, while accepted-prefix-limit counts routes that survive your import policy. Use prefix-limit when you want to catch floods even if the filter rejects them. teardown 80 logs a warning at 80% and tears down at 100%. idle-timeout 10 holds the session idle for 10 minutes. idle-timeout forever requires a manual clear bgp neighbor.

MikroTik RouterOS

RouterOS v7 filters use the /routing/filter/rule syntax:

/routing/filter/rule
add chain=CUST-64496-IN rule="if (dst in 198.51.100.0/24 && dst-len <= 24) { set bgp-local-pref 200; accept }"
add chain=CUST-64496-IN rule="reject"

/routing/bgp/connection
add name=cust64496 remote.address=192.0.2.2 remote.as=64496 \
    local.role=ebgp input.filter=CUST-64496-IN \
    input.limit-process-routes-ipv4=5

Be careful here. In RouterOS v6 the BGP peer had max-prefix-limit and max-prefix-restart-time, which behaved like the other platforms. In v7 the input.limit-process-routes-ipv4/ipv6 settings are the closest equivalent, but behavior has changed between releases. Test on your exact version in a lab: confirm whether the session is dropped, and whether it recovers on its own. Always end the chain with an explicit reject, because the default for a filter chain with no matching rule can differ from what you expect.

BIRD 2

filter cust_64496_in {
  if net ~ [ 198.51.100.0/24{24,24} ] then {
    bgp_local_pref = 200;
    accept;
  }
  reject;
}

protocol bgp cust64496 {
  local as 64500;
  neighbor 192.0.2.2 as 64496;
  ipv4 {
    import filter cust_64496_in;
    import limit 5 action restart;
    export none;
  };
}

BIRD's import limit supports the actions warn, block, restart and disable. Two differences from Cisco and Junos: there is a single threshold rather than a percentage warning plus a limit, and there is no restart timer attached to the limit. disable keeps the session down until birdc enable cust64496. restart brings it back automatically, but a persistent leak will flap the session, so pair it with monitoring and alerts. Check the docs for your BIRD version for the receive limit option if you need to count routes before filtering.

FRR

ip prefix-list CUST-64496-IN seq 10 permit 198.51.100.0/24
!
route-map CUST-64496-IN permit 10
 match ip address prefix-list CUST-64496-IN
 set local-preference 200
!
router bgp 64500
 neighbor 192.0.2.2 remote-as 64496
 address-family ipv4 unicast
  neighbor 192.0.2.2 maximum-prefix 5 80 restart 10
  neighbor 192.0.2.2 route-map CUST-64496-IN in
 exit-address-family

The syntax mirrors Cisco: limit, warning percentage, optional restart in minutes, or warning-only. Recent FRR versions also enable bgp ebgp-requires-policy by default, so an eBGP session with no inbound or outbound policy exchanges no routes. Leave that on.

IPv6 and per-address-family limits

Set limits for every address family on every session. A common mistake is to configure IPv4 carefully and leave family inet6 unicast unlimited. For IPv6 use equivalent filters, such as a registered 2001:db8::/32 with a maximum length of /48 for customers.

Filters to apply alongside limits

Common mistakes

  1. Limit equals the current count. One new prefix will take the session down. Leave headroom.
  2. No restart timer on customer sessions. The customer fixes the leak at 3 a.m. and stays offline until someone clears the session.
  3. Short restart timer on full tables. The session flaps and the CPU never settles.
  4. Warning thresholds nobody sees. Send syslog or SNMP traps to something that alerts a person.
  5. Forgetting automation sessions. RTBH and FlowSpec sessions from a detection system are BGP too. Accept only your own prefixes, only /32 and /128 with the blackhole community on the RTBH session, and set a low prefix limit.
  6. Not testing. Lab the teardown and recovery behavior on your exact software version.

Where NixMon fits

Prefix limits protect the control plane, but you also need to see what is happening in the data plane. NixMon analyzes NetFlow, IPFIX and sFlow and can announce BGP blackhole and FlowSpec routes to your routers. The limits and filters above are how you keep that automation session safe. If you use NixGuard Edge, the BGP session inside the GRE tunnel is a normal BGP session, so apply the same discipline there: filter what you accept and set a limit. You can try detection and mitigation workflows with the 15-day free trial, no credit card required.

Frequently asked questions

What should I set as the BGP maximum-prefix warning threshold?

80% is a common value for customers, IX and private peers. For full-table transit, use about 90% against a limit that already has 20-30% headroom, so you do not get constant warnings. Make sure the warning goes to a system that alerts a person.

Should maximum-prefix automatically restart the session?

For customers, IX and private peers, a restart timer of 10-30 minutes lets sessions self-heal after the other side fixes the leak. For full-table transit, a restart triggers a full re-learn, so use a long timer or manual clearing and alert an engineer.

Does a maximum-prefix limit replace prefix filtering?

No. Filters control which routes you accept, and limits control how many. A filter stops a hijack or leak of the wrong prefixes. A limit is a safety net when a filter is missing, outdated or wrong. Use both.

Do Cisco and Juniper count prefixes before or after import policy?

It depends on the platform and command. On Junos, prefix-limit counts received routes and accepted-prefix-limit counts routes that pass your import policy. Check your platform's documentation and test, because it affects whether a filtered flood trips the limit.

Test DDoS detection and BGP mitigation free for 15 days, no credit card.Learn more