Route maps

A prefix list only says yes or no; a route map can keep a route and change it on the way through. Its sequences are read in order: an omitted action is permit, an omitted sequence number counts in tens, a sequence with no match takes every prefix, and an implicit deny ends the map. Several values on one match line are OR; different match kinds are AND.

In Daveth Pro (Network)11 min video · lab: Redistribution

By , founder of Daveth · Updated

Opening frame of the video walkthrough of Route maps

Watch this lesson

11 min · Video walkthrough

In Daveth Pro (Network)

The full 11 min walkthrough is in Daveth Pro (Network). See what the plan opens

Upcoming practical lab

Lab R8: Redistribution

What the lab covers

What this page answers

What is a route map?

An ordered list of sequences that each match routes, with ACLs, prefix lists or other attributes, and permit or deny them, optionally setting attributes on the way. It is how routing protocols filter and change routes in one place. Read it in “Keep the route, and change it”

How are route map sequences processed?

In sequence order until one matches; an omitted action is permit, an omitted sequence number increments by 10, a sequence with no match statement matches all prefixes, and a route that matches nothing is denied. Read it in “The walk, and the line nobody wrote”

Is a route map match AND or OR?

Several variables on one match line, such as two ACLs, are OR: one has to match. Different kinds of match in one sequence, such as an ACL and a tag, are AND: all must match. Read it in “One line is OR, two kinds is AND”

Keep the route, and change it

The last lesson ended on a question. A prefix list only ever answers yes or no. What if the job is to keep a route and change it on the way through?

That's what a route map is for. Route maps provide many different features to a variety of routing protocols. At the simplest level they filter networks much the way an ACL does, but they can also add or change a route's attributes. Route maps are used with BGP and with the IGPs, to filter or modify routes using conditional matching.

One thing first, because it catches people. A route map on its own does nothing. To influence a routing protocol, the map has to be referenced from the routing protocol. Where it's referenced decides what its permit, deny and set clauses end up doing, and the callers come later in the course: redistribution, policy-based routing, and BGP, where route maps are the main tool for a different routing policy on each neighbor. This lesson is the map itself.

A route map has four parts:

  • Sequence number: sets the order the map is processed in.
  • Conditional matching criterion: what this sequence looks for in a route, such as the network, a BGP path attribute or the next hop.
  • Processing action: permits or denies the route.
  • Optional action: changes to the route, which depend on how the map is referenced; they can modify, add or remove route characteristics.

Before you read on. Here's a map with one sequence, and three routes coming in:

ip prefix-list SRV31 seq 5 permit 10.1.31.0/24 le 32
route-map TAG31 permit 10
 match ip address prefix-list SRV31
 set tag 31

10.1.31.0/25, 10.1.30.0/24, 10.1.32.0/24. Which ones get through, and which carry tag 31? Write it down.

The walk, and the line nobody wrote

The statement is route-map route-map-name [permit | deny] [sequence-number]. Five rules govern it, and the whole lesson leans on them:

  1. Leave out the action and you get permit.
  2. Leave out the sequence number and it increments by 10 automatically.
  3. A sequence with no match statement matches all prefixes.
  4. Once a route matches, processing stops after the sequence's optional actions are done. (One exception, continue, comes later.)
  5. A route that isn't associated with a permit action meets an implicit deny, and it's dropped.

We'll say a sequence claims a route when all its match lines pass for it.

Back to your three routes. 10.1.31.0/25 is inside SRV31, so sequence 10 claims it: permitted, tag 31. 10.1.30.0/24 and 10.1.32.0/24 aren't in SRV31. Sequence 10 doesn't claim them, there's no other sequence, and rule 5 takes them.

So: why did my route map drop routes I never mentioned? Because you never mentioned them. You've met this already: the invisible entry at the end belongs to ACLs, prefix lists and route maps alike, and it stops whatever matched nothing earlier. It turns up again in redistribution, where a map written to tag one route drops every other route if you forget the sequence that lets them through. Same rule.

Now a sample map. Its conditional matching uses network ranges in ACLs:

route-map EXAMPLE permit 10
 match ip address ACL-ONE
route-map EXAMPLE deny 20
 match ip address ACL-TWO
route-map EXAMPLE permit 30
 match ip address ACL-THREE
 set metric 20
route-map EXAMPLE permit 40

Read it as a route would:

  • Sequence 10: a route that matches ACL-ONE is permitted, and the map stops for it there.
  • Sequence 20: a route that matches ACL-TWO is denied, and the map stops.
  • Sequence 30: a route that matches ACL-THREE is permitted with its metric changed to 20.
  • Sequence 40 has no match, so every other route is permitted. Without it, every other route would be dropped by the implicit deny that every route map has.

Now turn sequence 40 around: make it deny 40, still with no match line. Any remaining routes are discarded, and the routes earlier sequences processed stay as they were. A deny with no match line is "drop everything that's left".

One practical note. To delete one statement, give its sequence number; leave it off and you delete the entire route map. no route-map EXAMPLE 20 takes out sequence 20. no route-map EXAMPLE takes out all four.

What a sequence can look at

These are the match commands you'll use:

  • match ip address {acl-number | acl-name} picks routes by the network selection in an ACL. A standard ACL looks at the route's address and nothing else, as the last lesson showed.
  • match {ip | ipv6} address prefix-list prefix-list-name picks routes by a prefix list. This is the dual-stack line: IPv6 routes are matched with match ipv6 address prefix-list.
  • match tag tag-value picks routes by a numeric tag, 0 to 4294967295, that another router set.
  • match metric {1-4294967295 | external 1-4294967295} [+- deviation] picks routes by metric: an exact value, a range, or within a deviation.
  • match source-protocol {bgp asn | connected | eigrp asn | ospf process-id | static} picks routes by the protocol and process they came from.
  • match interface interface-id matches the network or traffic by the association or inbound interface named. In redistribution, the same command is described as matching the outbound interface used to pick routes.

Three more are BGP's, named here and taught with BGP: match as-path, a regex query on the AS_Path; match community, the BGP community attribute; and match local-preference.

Five of these carry the note "allows for multiple match variables": as-path, ip address, the prefix list, local-preference and tag. That note is the next section.

One line is OR, two kinds is AND

Several variables on one sequence, such as two ACLs, two prefix lists or two tags: only one of them has to match for the route to qualify. The Boolean logic is or.

route-map EXAMPLE permit 10
 match ip address ACL-ONE ACL-TWO
!
route-map EXAMPLE deny 20

Sequence 10 wants a route that passes ACL-ONE or ACL-TWO. Sequence 20 has no match statement, so every route sequence 10 didn't pass qualifies there, and it's denied. Sequence 20 is redundant, because the implicit deny already drops whatever sequence 10 didn't match. Writing it anyway does no harm, and it makes the end of the map visible to whoever reads it next.

Now put two different match commands in one sequence. Both have to be met. The logic is and:

route-map EXAMPLE permit 10
 match ip address ACL-ONE
 match metric 550 +- 50

Sequence 10 wants a route ACL-ONE matches and a metric between 500 and 600.

A route that doesn't meet both doesn't qualify for sequence 10, and since no other sequence permits anything, it's denied. Several conditional matches of the same type: only one must be met. Several different match types: all of them must match.

Where that rule stops. What if you type the same kind twice, on two lines: match ip address prefix-list A, then match ip address prefix-list B? Variables are OR and options are AND, but two lines of one kind sit between the two, and we haven't confirmed whether IOS keeps them as two AND conditions or folds them into one OR line. Our advice: put alternatives on one line, where the rule is plain and nobody has to guess.

The dual-stack trap is the same question with a sharper edge. Put match ip address prefix-list V4 and match ipv6 address prefix-list V6 in one sequence and read the AND rule literally: no route could ever match, because an IPv4 route is never in an IPv6 prefix list. Whether the router applies only the line for the route's own family, we haven't confirmed. Until that's settled, give each family its own sequence or its own map.

A deny inside the list

Some engineers find route maps too complex when the list a match calls has a deny in it, whether that's an ACL, an AS_Path ACL or a prefix list. Here's one built that way: its ACL denies the 172.16.1.0/24 range.

  1. Network drawing: Each sequence asks two questions in turn: does the list it calls say this route is mine, and if so, what does the sequence do with it? A deny inside a list only answers the first.

    Step 1 of 4 172.16.1.0/24 meets the route map, metric 100. ACL-ONE denies 172.16.1.0/24 and permits the rest of 172.16.0.0/16; two sequences call it, and the third has no match line.

  2. Network drawing: Each sequence asks two questions in turn: does the list it calls say this route is mine, and if so, what does the sequence do with it? A deny inside a list only answers the first.

    Step 2 of 4 Sequence 10, permit: ACL-ONE's first line denies the route, so the list says not this sequence, and the route moves on.

  3. Network drawing: Each sequence asks two questions in turn: does the list it calls say this route is mine, and if so, what does the sequence do with it? A deny inside a list only answers the first.

    Step 3 of 4 Sequence 20, deny: the same list, the same answer. A deny inside a list only says the sequence doesn't apply; it doesn't drop the route.

  4. Network drawing: Each sequence asks two questions in turn: does the list it calls say this route is mine, and if so, what does the sequence do with it? A deny inside a list only answers the first.

    Step 4 of 4 Sequence 30 has no match line, so it matches everything: the route leaves with metric 20, permitted by sequence 30.

The reading order: follow the sequence order first and the conditional match second; only after a match do you use the processing action and the optional action. And when a route hits a deny inside the match list, that deny excludes it from that sequence of the route map. That's all it does.

So walk 172.16.1.0/24. ACL-ONE denies it, so there's no match in sequence 10 or in sequence 20, and their permit or deny never comes into it. Sequence 30 has no match clause, so any route that's left is permitted: 172.16.1.0/24 passes on sequence 30 with its metric set to 20. And 172.16.2.0/24 matches ACL-ONE and passes in sequence 10, with its metric untouched, because sequence 10 sets nothing.

The ACL said deny. The route left with a metric of 20.

There are two denies here, at two layers, and they do different jobs:

  • A deny inside the list answers the match question: "not this sequence, try the next one."
  • A deny on the sequence answers the action question: "this one's mine, and it's dropped."

Put another way: route maps process in this order, the sequence, the conditional match criteria, the processing action, the optional action; any deny statements in the match component are isolated from the sequence's action.

Test it from the other side. route-map QUESTION deny 10 matches prefix list PrefixRFC1918; route-map QUESTION permit 20 sets metric 200. A route that doesn't match the prefix list skips sequence 10, moves on to 20, and is allowed with metric 200. It proceeds because sequence 20 is a permit sequence with no match line, and that matches everything.

Now go back to the walk's map, EXAMPLE, and its deny 20. It's a deny sequence calling ACL-ONE. Which routes could it ever drop? Only ones ACL-ONE permits, and every one of those has already left at sequence 10. Sequence 20 never decides anything. A map can carry a line that does nothing, and reading only that line, you might think it drops 172.16.x routes.