The Longest Match Rule
One of the the concepts that comes up occasionally is that of precedence. For example, one might consider the following routing table entries.
ip route 0.0.0.0 0.0.0.0 1.1.1.1 //default route ip route 192.168.0.0 255.255.0.0 1.1.1.2 //supernet/cidr route ip route 192.168.1.0 255.255.255.0 1.1.1.3 //network route ip route 192.168.1.0 255.255.255.128 1.1.1.4 //subnet route ip route 192.168.1.20 255.255.255.255 1.1.1.5 //host route
Questions often arise around which path a packet would take when it matches more than one entry. For example, a packet may have a destination address of 192.168.1.20. In this case it matches every single route entry.
The logic is actually simple, even straightforward. A packet will follow the most specific route entry that it matches. So a packet destined to 192.168.1.20 would be routed to a router at 1.1.1.5. If the destination happened to be 192.168.1.21, it would be routed over to 1.1.1.4.
