Cisco routers use the longest prefix match rule when determining which of the routes placed into the routing table should be used to forward traffic to a destination network or node. Longer, or more specific routing table entries are preferred over less specific entries, such as summary addresses, when determining which entry to use to route traffic to the intended destination network or node.
The longest prefix or most specific route will be used to route traffic to the destination network or node regardless of the administrative distance of the route source, or even the routing protocol metric assigned to the prefix is multiple overlapping prefixes are learned via the same routing protocol. Table 1-3 illustrates the order of route selection on a router sending packets to the address 1.1.1.1. This order is based on the longest prefix match lookup.
Routing Table Entry | Order Used |
1.1.1.1/32 | 1st |
1.1.1.0/24 | 2nd |
1.1.0.0/16 | 3rd |
1.0.0.0/8 | 4th |
0.0.0.0/0 | 5th |
Tab.1-3. Matching the Longest Prefix
NOTE: Although the default route is listed last in the route selection order in Table 1-3, keep in mind that a default route is not always present in the routing table. If that is the case and no other entries to the address 1.1.1.1 exist, packets to that destination are simply discarded by the router. In most cases, the router will send the source host an ICMP message indicting that the destination is unreachable.