Illustrated TCP/IP Illustrated TCP/IP
by Matthew G. Naugle
Wiley Computer Publishing, John Wiley & Sons, Inc.
ISBN: 0471196568   Pub Date: 11/01/98
  

Previous Table of Contents Next


Chapter 76
Longest Match Rule

As you can see, playing with the address leads to a lot of ambiguity. Using these techniques is not for the faint of heart. It can become very, very complicated. Usually, company network manages do not have to overly concern themselves with this schema.

One rule that must be understood before any of this can work is the longest match rule. This is also discussed in the OSPF section of the book. When a network ID is encountered that matches to different-length prefixes, the router will always take the path indicated by the longest mask. For example, if a router receives an IP datagram with the destination address of 200.40.1.1 and a route table lookup found 200.40.1.0/24 and 200.40.0.0/16, the router will forward the datagram out the path indicated by the longest mask: 200.40.1.0. Therefore, you must make sure there are no hosts assigned to 200.40.0.0/16.

Longest Match Rule

  Allows a router to determine the best route based on granularity of the masked address.
  Used when a network ID is found to match more than one subnet mask.
  Example:
  Received datagram of 200.40.1.1
  Route table lookup found two entries:
  200.40.1.0/24
  200.40.0.0/16
  Route would use the 200.40.1.0/24
  Must be careful when assigning addresses.

The longest match rule is implemented because the longer the mask found, the better granularity the router has in exactly defining the correct route.

Therefore, you must be wary of the fact that the router will route to the route determined by the longest mask match. If there are two entries for the same route, the longest mask wins.


Previous Table of Contents Next