Match first, then act
BGP gives you plenty of places to change what is accepted or advertised. All of them use the same two building blocks. A prefix list matches networks by address and mask length. A route map is a numbered list of rules, each with optional match lines and set lines.
On small screens, swipe sideways or focus the diagram and use the arrow keys.
Prefix lists: address plus a length range
An entry says permit or deny a network, optionally with ge (greater than or equal to) and le (less than or equal to) limits on the prefix length. With neither, only the exact length matches.
On small screens, swipe sideways or focus the diagram and use the arrow keys.
ip prefix-list COMPANY-ONLY seq 10 permit 198.51.100.0/24
ip prefix-list SMALL-SUBNETS seq 10 permit 198.51.100.0/24 ge 25 le 28
ip prefix-list ANY-DEFAULT seq 10 permit 0.0.0.0/0
ip prefix-list ANYTHING seq 10 permit 0.0.0.0/0 le 32Global configuration mode. The first matches only the /24. The second matches /25 to /28 inside it, not the /24 itself. The third is the default route alone. The last matches every route.
Entries are checked in sequence order and the first match wins. Anything that matches no entry meets an implicit deny. Leave gaps in the sequence numbers (10, 20, 30) so you can insert entries later.
R1#show ip prefix-list ip prefix-list COMPANY-ONLY: 1 entries seq 10 permit 198.51.100.0/24 ip prefix-list SMALL-SUBNETS: 1 entries seq 10 permit 198.51.100.0/24 ge 25 le 28
show ip prefix-list detail adds hit counts, which tells you whether a route ever matched an entry.Route maps: ordered rules
On small screens, swipe sideways or focus the diagram and use the arrow keys.
Each route is tested against the sequences in order. The first sequence whose match lines all pass decides: permit accepts it and applies the set lines, deny rejects it. A sequence with no match line matches every route. If no sequence matches, the implicit deny at the end rejects the route.
route-map ISPA-IN permit 10
match ip address prefix-list PROVIDER-ONLY
set local-preference 200
route-map ISPA-IN permit 20
set local-preference 100Sequence 10 raises the preference of the expected provider prefix. Sequence 20 has no match, so it catches everything else and keeps the default. Remove 20 and everything except the provider prefix would be dropped.
R1#show route-map ISPA-IN route-map ISPA-IN, permit, sequence 10 Match clauses: ip address prefix-lists: PROVIDER-ONLY Set clauses: local-preference 200 Policy routing matches: 0 packets, 0 bytes route-map ISPA-IN, permit, sequence 20 Match clauses: Set clauses: local-preference 100
Technical reference: Cisco IOS XE prefix list and route map configuration. Output above is illustrative.
Check your reading
ip prefix-list P seq 10 permit 198.51.100.0/24 ge 25. Does it match 198.51.100.0/24?
A route map has one sequence, permit 10, that matches a prefix list. A route does not match. What happens to it?
You need to match every route with a mask from /24 to /28 inside 198.51.100.0/24, but not the /24 itself. Which entry?