Longest Prefix Match Routing

Hello Robert

No, it works exactly the same way.

However, let me clarify. In my previous post, I mentioned that AD and metric are used to determine if a route will enter the routing table or not. This is indeed the case, however, this is only valid when the destinations are identical. For example, a router learns of the following networks via the routing protocols indicated:

  • 192.168.2.0/24 using EIGRP gives next hop IP of 10.10.10.1
  • 192.168.2.0/24 using OSPF gives next hop IP of 10.10.20.1
  • 192.168.2.0/24 using Static with a metric of 5 gives next hop IP of 10.10.30.1
  • 192.168.2.0/24 using Static with a metric of 10 gives next hop IP of 10.10.40.1

Out of all of these, the static routes have the lowest AD, and between those two static routes, it is the route with the smallest metric that will be installed in the routing table. So there will be only one entry in the routing table like so:

S 192.168.2.0/24 [1/5] via 10.10.30.1

However, if you have the following networks advertised:

  • 192.168.2.0/24 using EIGRP gives next hop IP of 10.10.10.1
  • 192.168.2.0/25 using OSPF gives next hop IP of 10.10.20.1
  • 192.168.2.0/26 using Static with a metric of 5 gives next hop IP of 10.10.30.1
  • 192.168.2.0/27 using Static with a metric of 10 gives next hop IP of 10.10.40.1

All four of them will be in the routing table! This is because they are considered different routes because they have different prefix sizes. So any packet that is destined for 192.168.2.1 must choose between those four installed routes. How does it choose which is the best route for a particular destination?

For routes installed in the routing table, the prefix length is always used first to match, regardless of AD or metric.

In the routing table you shared, you see two static routes to 192.168.2.0/24 and 192.168.2.0/29. These are considered two different routes because they specify a different range of addresses. For this reason, they are both put into the routing table. Now I notice that they have different metrics and that’s fine too. If they were the same route (same network address and prefix), then only the one with the lowest metric would be installed. But here they’re two different routes.

So, when a packet destined for 192.168.2.1 arrives on this router, how is it routed? It will match the longest prefix, which is 192.168.2.0/29 so it will be forwarded to 192.168.0.2.

More detailed information on this process can be found at the following Cisco documentation:

I hope this has been helpful!

Laz

2 Likes