Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

longest-match (Static Routes)

Syntax

Hierarchy Level

Description

Specify the static route on the device to resolve and determine the packet’s next-hop interface using the Longest Match Routing Rule (most specific entry), sometimes referred to as the longest prefix match or maximum prefix length match. The Longest Match Routing Rule is an algorithm used by IP routers to select an entry from a routing table. The router uses the longest (prefix) match to determine the egress (outbound) interface and the address of the next device to which to send a packet. Typically, the static route prefers the directly connected subnet route for resolving the next hop rather than performing a longest prefix match with any other available routes.

Note:

(Required) You must include the resolve next-hop option to specify the longest-match statement. Next-hop options define additional information about static routes that are included with the route when it is installed in the routing table. You alter the default next-hop resolution behavior using the resolve next-hop option.

The router implements the Longest Match Routing Rule as follows:

  1. The router receives a packet.

  2. While processing the header, the router compares the destination IP address, bit-by-bit, with the entries in the routing table.

The entry that has the longest number of network bits that match the IP destination address is always the best match (or best path) as shown in the following example:

Longest Match Example

  • The router receives a packet with a destination IP address of 192.168.1.33.

  • The routing table contains the following possible matches:

    • 192.168.1.32/28

    • 192.168.1.0/24

    • 192.168.0.0/16

To determine the longest match, it’s easiest to convert the IP addresses in Table 1 to binary and compare them.

Table 1: Converted IP Addresses

Address

Converted Binary Address

192.168.1.33 (destination IP address)

11000000.10101000.00000001.00100001

192.168.1.32/28

11000000.10101000.00000001.00100000 (<–Best match)

192.168.1.0/24

11000000.10101000.00000001.00000000

192.168.0.0/16

11000000.10101000.00000000.00000000

Note:

When determining the next-hop interface for customer deployments, setting the longest-match statement results in traffic loss.

Required Privilege Level

routing—To view this statement in the configuration.

routing-control—To add this statement to the configuration.

Release Information

Statement introduced in Junos OS Release 15.1.