0

I understand the concept and how the longest prefix match rule works.

Let's say a router receives a packet destined for 192.168.100.5 and the router has the following matching routes in its routing table. enter image description here

It will pick and use the static 192.168.100.0/26 route, because it's the most specific route/has the longest prefix length.

However, why does it work like this? What is the reasoning behind it? Would any problems occur it it chose one of the less-specific routes?

Thank you all in advance.

3
  • Interesting bit of screenshot/output, there. Ist that an actual thing? "S" usually stands for "static" and a combination of static routes as shown is possible. But further down each line it says "directly connected" (which in turn should've made it a "C" at the beginning) and all subnets seem connected to the same interface Gig0/0/0. You can't usually configure overlapping subnets on a router's interfaces. Can I bother you to show us the config section that lead to such a routing table? Mar 29, 2023 at 21:15
  • The reason why it says "Directly Connected" is because this is a Directly Connected Static Route. In such routes, we only specify the output interface. cisco.com/c/en/us/td/docs/switches/datacenter/nexus3000/sw/…
    – Mitrixsen
    Mar 30, 2023 at 12:01
  • Directly connected routes usually have "C" at the beginning of the line. "S", as in your output - denotes "static", but that contradicts with "is directly connected". Mar 31, 2023 at 14:59

2 Answers 2

4

Would any problems occur it it chose one of the less-specific routes?

Yes. Your PC is a good example. You (usually) have two routes in your PC's routing table. It will look something like this:

    Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0       172.19.2.3      172.19.2.20     25
       172.19.2.0    255.255.254.0         On-link       172.19.2.20    281

Let's say you have a printer on your desk with an IP address of 172.19.2.21. If you send data to it, which route will your PC use? If you use the most specific route (172.19.2.0/23), the data will be sent to the printer on the local subnet. But if you use the least-specific route, the data will be sent to the default gateway instead of your printer.

Since most devices have a default route (0.0.0.0/0), all data will always use the default route, since it is the least specific match. The PC or router would never choose any other route than the default.

2

The longest-prefix-preferred rule saves you the hassle to finely split up all routing into distinct routes (if no overlap would be allowed) and use a coarser, "catch-all" route instead.

A good use case to show why that scheme is a good idea is a corporation network using 10.0.0.0/8 overall and where a branch location may have multiple VPN/MPLS links and sends 10.10.0.0/16 to one site, 10.11.0.0/16 to another, and 10.0.0.0/8 to HQ where it may or may not be forwarded elsewhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.