Route Preference

Suppose a router receives a packet destined for the IP address 192.0.2.73. The router has in its routing table the following three routes:

ProtocolADMetricPrefixNext Hop
OSPF110240192.0.2.0/25172.16.1.1
EIGRP9033789192.0.2.0/24172.16.2.1
RIP1206192.0.2.64/26172.16.3.1

To which next hop address will the packet be routed?

If you picked 172.16.3.1, you're correct. Why? A router evaluates routes in the following order.

  1. Prefix Length - The longest-matching route is preferred first. Prefix length trumps all other route attributes.
  2. Administrative Distance - In the event there are multiple routes to a destination with the same prefix length, the route learned by the protocol with the lowest administrative distance is preferred.
  3. Metric - In the event there are multiple routes learned by the same protocol with same prefix length, the route with the lowest metric is preferred. (If two or more of these routes have equal metrics, load balancing across them may occur.)

Following these rules, we can see that our RIP-learned route is preferred because it is the most specific route: it has the longest matching prefix (26 bits in length compared to 25 and 24). These rules hold true even when evaluating directly connected routes, which have an AD of zero:

Router# show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route

Gateway of last resort is not set

172.16.0.0/24 is subnetted, 3 subnets
C       172.16.1.0 is directly connected, Loopback1
C       172.16.2.0 is directly connected, Loopback2
C       172.16.3.0 is directly connected, Loopback3
     192.0.2.0/24 is variably subnetted, 3 subnets, 3 masks
S       192.0.2.64/26 [120/0] via 172.16.3.2
C       192.0.2.0/24 is directly connected, Loopback99
Router# show ip route 192.0.2.73
Routing entry for 192.0.2.64/26
  Known via "static", distance 120, metric 0
  Routing Descriptor Blocks:
  * 172.16.3.2
      Route metric is 0, traffic share count is 1

I'm afraid that this core concept is too often glossed over in CCNA and other introductory networking classes. Remember: it doesn't matter if we have a less-specific route with a direct 100 Gbps connection to the destination, and a more-specific route which takes 15 hops over 56 Kbps serial links through a bad neighborhood. The most-specific route will always be preferred.

About the Author

Jeremy Stretch is a freelance networking engineer, instructor, and the maintainer of PacketLife.net. He currently lives in Fairfax, Virginia, on the edge of the Washington, DC metro area. Although primarily an R&S guy, he likes to get into everything, and runs a free network training lab out of his basement for fun. You can contact him by email or follow him on Twitter.

Comments

Nice post Jeremy. This was one of the things that puzzled me when doing CCNA at a net academy back in 2003. There is probably still a lot of people that don't know of this even at a higher level of understanding.

Wow I'm a week off doing the ICND2 exam and I wasn't actually aware that a more direct route trumps a protocol, I love this site.

Now back to Packet tracer

Awesome!!!!! :) You made my day.... Throw more stuffs like this...

Jeremy, perhaps this is just semantics, but when you write "If two or more of these routes have equal metrics, load balancing across them may occur", why did you use the word "may"? Is there a possibility that load-balancing would not occur? If so, what would be the cause(s)?

@Guest: There are intricacies to CEF load sharing that can prevent the expected load balancing behavior in some cases. I might have written "will occur," but didn't want to commit, just in case. :)

Depends on the protocol that has the tie as well, not all support load balancing.

The router evaluates all this routes in opposite order (but result is the same):
0) consider routes ONLY if next hop is valid (that generally means "reachable"). That's very important.
1) prefer routes with the best metric (independently for each protocol)
-then-
2) prefer route sources with the lowest AD
-now we have ONLY the best routes for each prefix in routing table
-and then
If router receive a packet, it looks through the whole routing table (or in CEF case, part of FIB) for longest match.
So result is the same, but the order is completely different. Very important, if you want to understand various "tables", like RIB, FIB, LSDB, bgp table and more.

Funny things about unicast and multicast routing differences, is that in your multicast routing table, the preference matters MORE than the length of the route.

If you have a static mroute to 0.0.0.0/0 and a MBGP route to 1.1.1.1/32, the RPF for 1.1.1.1 will be the static mroute...

Confusing no... ?

Fred

Nice Article...This should be part of all CCNA Books now.

I did some similar testing too couple of months back.

http://deepakarora1984.blogspot.com/2009/02/how-router-makes-routing-decision.html

HTH...

Deepak Arora

http://deepakarora1984.blogspot.com

In the CCNA Exploration - Routing Protocols and Concepts (both NetAcad online curriculum and printed Companion Guida) this topic is adressed.

The longest prefix match always wins among the routes actually installed in the routing table, while the routing protocol with the lowest administrative distance always wins when installing routes into the routing table.

see http://www.cisco.com/en/US/tech/tk365/technologies_tech_note09186a0080094823.shtml

an oldie but goldi

Just now i am prepare ccnp (ROUTE) and i had wrong answer on this Q. Oooo my Good. I don't can believe :)

Jeremy I read this article 3 times to believe that is this for real ... you know I recently cleared by BSCI exam and never had an Idea about that. you rocks man.

anon beat me to it.

I was confused at first following the method posted here when I was going through my CCNA. There are two things going on, route installation and route selection.

Route Installation

  • Lowest AD
  • Lowest Metric

Route Selection

  • Longest mask
  • Lowest metric

The link anon posted explains it nicely

pls guys .. i dont know how to start this network ing studies

@zerozerofourteen (or anyone else for that matter)

What is the difference between 'route installation' and 'route selection' ?

** Ignore that I know understand it after reading through the cisco article above... A route is added for each protocol based upon firstly the AD... the traffic is then forwarded via the route installed depending on firstly on the longest prefix match... I take it that's correct?

For those who want to go further, I recommend "CCNA Exploration: Routing Protocols and Concepts", Chapter 8 - "The Routing Table: A Closer Look".

Hi,

I think this order is just for Cisco box. is it?

why Maximum prefix length match is first Priority routing table?

Leave a Comment


Register to comment as a member. You'll look cooler.

Optional; will not be displayed publicly or given out.

No commercial links. Only personal (e.g. blog, Twitter, or LinkedIn) and/or on-topic links, please.
The 'V' in VLAN stands for _____.