Policy-based routing

Policy-based routing overrules a routing table that is right, for a reason that is not a destination: compliance, billing, an appliance on one circuit. A route map matches traffic with ACLs or packet length and sets a next hop; traffic it does not match is routed normally. It attaches to a routed port, SVI or Layer 3 port channel, and the switch's own traffic needs local PBR.

In Daveth Pro (Network)6 min video · lab: Routing basics, deep

By , founder of Daveth · Updated

Opening frame of the video walkthrough of Policy-based routing

Watch this lesson

6 min · Video walkthrough

In Daveth Pro (Network)

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

Upcoming practical lab

Lab C3: Routing basics, deep

What the lab covers

What this page answers

How do you configure policy-based routing on a Catalyst switch?

Write a route map that matches traffic, such as match ip address 101, and sets a next hop with set ip next-hop, then apply it to the incoming interface with ip policy route-map name. Read it in “Three ways out”

Can PBR be applied to an EtherChannel member port?

No. A policy route map can go on a Layer 3 port channel, but not on a physical interface that is a member of it; the command is rejected. Read it in “Where it attaches”

Does PBR affect traffic the router generates itself?

Not an interface policy: the router's own traffic never arrives on an interface. Local PBR, ip local policy route-map, handles it, and it is disabled by default. Read it in “The switch’s own traffic”

A correct table, overruled

Every lesson so far in this domain was about getting the right answer into the routing table. Here the table on SW-1 is right: it prefers PE-PRI. Why would you overrule it?

You can use policy-based routing (PBR) to configure a defined policy for traffic flows. By using PBR, you can have more control over routing by reducing the reliance on routes derived from routing protocols.

Because the reason is not a destination. A compliance path, a billing arrangement, an appliance on one circuit: the routing table has no words for any of it.

With PBR, you classify traffic using access control lists (ACLs) and then make traffic go through a different path. PBR is applied to incoming packets. All packets received on an interface with PBR enabled are passed through route maps.

Notice the direction: incoming packets. Where does that leave traffic the switch itself sends? Hold that question for later.

You must configure policy-based routing (PBR) on the interface that receives the packet, and not on the interface from which the packet is sent.

Three ways out

Before any syntax, look at where the branches land.

Network drawing: packet arrives on an interface with a policy, route map consulted, matched a, PERMIT clause, DENY clause, matched nothing, set action applied, normal destination-based routing, two of the three outcomes end up here, A packet matching a permit statement gets the set action. A packet matching a deny statement, and a packet matching nothing, both go back to destination-based routing.

Configuration: DIVERT on Gi1/0/11, in the forms the Catalyst 9300 chapter prints; names, ports, addresses and ACLs are this course’s own.

SW-1# configure terminal
SW-1(config)# route-map DIVERT permit 10
SW-1(config-route-map)# match ip address 101
SW-1(config-route-map)# set ip next-hop 172.16.5.2
SW-1(config-route-map)# exit
SW-1(config)# interface Gi1/0/11
SW-1(config-if)# ip policy route-map DIVERT
SW-1(config-if)# end

ACL 101: FIN-1 to the payments network. Where does each of FIN-1’s flows go?

Computed from the state: FIN-1’s traffic with DIVERT attached. No command prints it.

traffic          arrives   statement  outcome        goes to
FIN-1 payments   Gi1/0/11  10         policy-routed  PE-BAK
FIN-1 audit      Gi1/0/11  10         policy-routed  PE-BAK
FIN-1 web        Gi1/0/11  -          no match       PE-PRI
You can configure only one route map on an interface. However, you can have multiple route map entries with different sequence numbers. These entries are evaluated in the order of sequence number until the first match. If there is no match, packets are routed as usual.

The audit server sits inside the payments network, and audit traffic must stay on the primary path. ACL 102: FIN-1 to the audit server, inside the payments network. A deny statement goes in front. What does deny do here?

Configuration: deny 5 in front of permit 10, in the forms the Catalyst 9300 chapter prints; names, ports, addresses and ACLs are this course’s own.

SW-1# configure terminal
SW-1(config)# route-map DIVERT deny 5
SW-1(config-route-map)# match ip address 102
SW-1(config-route-map)# end
If the statement is marked as a deny, the packets meeting the match criteria are sent back through the normal forwarding channels (destination-based routing). If the statement is marked as permit, set clauses are applied to packets meeting the match criteria. Packets that do not meet the match criteria are forwarded through the normal routing channel.

Computed from the state: the same traffic with deny 5 in front. No command prints it.

traffic          arrives   statement  outcome        goes to
FIN-1 payments   Gi1/0/11  10         policy-routed  PE-BAK
FIN-1 audit      Gi1/0/11  5          exempt         PE-PRI
FIN-1 web        Gi1/0/11  -          no match       PE-PRI
If the packet matches any match statements for a route map that is marked as deny, the packet is not subject to PBR and is forwarded normally.

Look at the audit row: statement 5, exempt, and out by the path the table chose. The word is the one access lists use; in a policy route map it sends a packet back to normal routing.

If no match is found, normal destination-based routing occurs. There is an implicit deny at the end of the list of match statements.

What one statement matches

Someone adds match length 1000 1500 to permit 10, meaning only large payments transfers. FIN-1 also sends backup transfers in large packets, and ACL 101 does not match them. Which traffic moves now?

Configuration: the length match added to permit 10, in the forms the Catalyst 9300 chapter prints; names, ports, addresses and ACLs are this course’s own.

SW-1# configure terminal
SW-1(config)# route-map DIVERT permit 10
SW-1(config-route-map)# match length 1000 1500
SW-1(config-route-map)# end
A match command can match on length or multiple ACLs. A route map statement can contain multiple match commands. Logical or algorithm function is performed across all the match commands to reach a permit or deny decision. A packet is permitted if it is permitted by match length A B or acl1 or acl2 or acl3

Computed from the state: FIN-1’s traffic after the length match. No command prints it.

traffic          arrives   statement  outcome        goes to
FIN-1 payments   Gi1/0/11  10         policy-routed  PE-BAK
FIN-1 audit      Gi1/0/11  5          exempt         PE-PRI
FIN-1 backup     Gi1/0/11  10         policy-routed  PE-BAK
FIN-1 web        Gi1/0/11  -          no match       PE-PRI

Look at the backup row. On this switch either match is enough, so being large was enough. Small payments still move.

If the decision reached is deny, then the PBR action (specified in the set command) is not applied. Instead the processing logic moves forward to look at the next route-map statement in the sequence (the statement with the next higher sequence number). If no next statement exists, PBR processing terminates, and the packet is routed using the default IP routing table.
Match statements are evaluated first by the criteria specified in the match ipv6 address command and then by the criteria specified in the match length command. Therefore, if both an ACL and a length statement are used, a packet will first be subject to an ACL match. Only packets that pass the ACL match will be subject to the length match. Finally, only packets that pass both the ACL and the length statement will be policy routed.

The two pages describe the same pair of match commands differently: the Catalyst 9300 chapter ORs them for its IPv4 policy, the 17.x module requires both for IPv6. This course models each as its page states and does not reconcile them.

If you do not specify a match command, the route map is applicable to all packets.
Do not match ACLs that permit packets destined for a local address.

Where it attaches

ENG-1 arrives on Po1. Does the policy go on the channel or on its members?

You can enable PBR on a routed port or an SVI.
You can apply a policy route map to an EtherChannel port channel in Layer 3 mode, but you cannot apply a policy route map to a physical interface that is a member of the EtherChannel. If you try to do so, the command is rejected. When a policy route map is applied to a physical interface, that interface cannot become a member of an EtherChannel.

Computed from the state: DIVERT typed on Gi1/0/12. No command prints it.

rejected: Gi1/0/12 is a member of Po1; apply the policy route map to Po1

Computed from the state: attachments, and ENG-1’s traffic once it is on the channel. No command prints it.

where       family  route map
Gi1/0/11    IPv4    DIVERT
Po1         IPv4    DIVERT
local       IPv4    none

traffic          arrives   statement  outcome        goes to
ENG-1 web        Po1       -          no match       PE-PRI

The switch’s own traffic

SW-1 sends syslog, NTP, SNMP traps and pings to the monitoring network. None of it arrives on an interface. Which policy reads it?

Work it from where the policy sits rather than from what the traffic is. An interface policy reads what arrives on that interface, and nothing the switch generates itself ever arrives anywhere: it starts inside. So a policy written on every interface in the building will not see one packet of it.

Computed from the state: SW-1’s own traffic with only interface policies. No command prints it.

traffic          arrives   statement  outcome        goes to
SW-1 syslog      local     -          no policy      PE-PRI
SW-1 ntp         local     -          no policy      PE-PRI
SW-1 snmp        local     -          no policy      PE-PRI
SW-1 ping        local     -          no policy      PE-PRI
Packets that are generated by the switch (CPU), or local packets, are not normally policy-routed. When you globally enable local PBR on the switch, all unicast packets that originate on the switch are subject to local PBR. The protocols that are supported for local PBR are NTP, DNS, MSDP, SYSLOG and TFTP. Local PBR is disabled by default.

Configuration: local PBR with LOCAL, in the forms the Catalyst 9300 chapter prints; names, ports, addresses and ACLs are this course’s own.

SW-1# configure terminal
SW-1(config)# route-map LOCAL permit 10
SW-1(config-route-map)# match ip address MGMT
SW-1(config-route-map)# set ip next-hop 172.16.5.2
SW-1(config-route-map)# exit
SW-1(config)# ip local policy route-map LOCAL
SW-1(config)# end
Enables local PBR to perform policy-based routing on packets originating at the switch. This applies to packets generated by the switch, and not to incoming packets.

So which of the four now leave by PE-BAK?

Computed from the state: SW-1’s own traffic with local PBR. No command prints it.

traffic          arrives   statement  outcome        goes to
SW-1 syslog      local     10         policy-routed  PE-BAK
SW-1 ntp         local     10         policy-routed  PE-BAK
SW-1 snmp        local     -          not listed     not stated
SW-1 ping        local     -          not listed     not stated

Notice the two rows that say not listed. SNMP and ping are not in the chapter’s list, so this course does not claim where local PBR sends them. Test with a protocol the list names.

Packets that are generated by the device are not normally policy routed.

From elsewhere: local PBR for IPv6. The values in it come from elsewhere, not from this scenario.

ipv6 access-list src-90
  permit ipv6 host 2001:DB8:2003::90 2001:DB8:2001:1000::/64
route-map pbr-src-90 permit 10
  match ipv6 address src-90
  set ipv6 next-hop 2001:DB8:2003:1::95
ipv6 local policy route-map pbr-src-90