Skip to content
WebsiteHosting.com

concept Networks

Policy routing and source-dependent route tables

The same IPv4 destination can lead to different Linux routes. A source rule determines which table to search; the longest matching prefix and its route type determine what happens there.

Latest recorded source check · P0110

What it means

Two packets headed to the same destination can use different Linux routing tables because a policy rule can match the packet’s source address. Linux consults its routing policy database (RPDB) in rule priority order. A matching lookup rule names a table to search. Within that table, the destination determines which route prefixes match, and the longest matching prefix is the most specific.

Try it

Simulation — keep the destination at 203.0.113.8. With the starting source 192.0.2.7, the rule for sources in 192.0.2.0/24 matches. In table 100, both 203.0.113.0/24 and 203.0.0.0/16 cover the destination. The /24 matches the first 24 bits rather than just 16, so the result is the /24 unicast route in table 100. The main table is not consulted.

Policy routing and source-dependent route tables

Demonstrate why destination alone does not determine Linux routing under policy rules

Simulation
Modeled outcome: Policy

Matching policy rule selects a longest-prefix unicast route in table 100.

Policy routing and source-dependent route tables: synthetic scenario inputs
Replaces all inputs with the documented starting example and the indicated change. Reset restores the starting example.
Policy rule → table lookup

Lookup trace

  1. Step 1100: source match
  2. Step 2100: /24 unicast

Selected route

  1. Table100
  2. Prefix/24
  3. Dispositionpolicy

The trace reports only the rules reached. A table miss or throw may advance to the next rule; an unreachable match is terminal.

Evaluated inputs

Required scenario evidence
provided
Source IPv4 address
192.0.2.7
Destination IPv4 address
203.0.113.8
Table 100 /24 route
unicast
Table 100 /16 route
unicast

Not evaluated: Table 254 default

Linux RPDB teaching subset: local table assumed miss, priority 100 source rule for 192.0.2.0/24 then 32766 main default, empty final table. Only two fixed policy prefixes, no equal-cost routes, marks, VRF or actual network reachability. Text accepts canonical dotted decimal only.

About this model

The controls set only a local, bounded scenario. The computed branch is not a verdict about a live system. Inputs listed as not evaluated did not participate in this branch after validation.

Reset restores the original inputs. It does not change the open or closed state of help or FAQ answers.

Change only the Source IPv4 address to 198.51.100.7. Look at the first point where the trace differs: it now says 100: selector miss. The /24 route still exists, but its table was never searched. The later rule looks in table 254, the main table, and finds its default route, 0.0.0.0/0. Neither the destination nor any route entry had to change.

Use Reset to restore both addresses, all three route choices to unicast, and scenario evidence to provided. Now change only Table 100 /24 route to absent. This time the source rule still matches and the lookup stays in table 100: the /16 is the longest matching entry left.

What happens after a route matches

Rule priority and prefix length answer different questions. Here, rule priority 100 comes before 32766 because the smaller number is considered first. Those rules specify table 100 and table 254, respectively. The table number identifies where to look; it does not rank a route against entries in another table.

Once a table is searched, the type of its most specific matching entry matters. Keep the starting addresses, the /16 unicast route, and the main default fixed. Compare the four settings for 203.0.113.0/24:

Table 100 /24 routeResultWhy
unicastTable 100, /24The more specific entry supplies the route.
absentTable 100, /16There is no /24 entry to select, so the broader entry wins.
throwTable 254, /0The /24 wins, but its type ends this table lookup as if no route were found. The next rule leads to main.
unreachableTable 100, terminal rejectionThe /24 wins and explicitly rejects the destination. Neither the /16 nor the main default is used as a fallback.

A present default route matches every destination in its table. If the example reaches main and no route exists there, the default is absent; the packet did not somehow fail to match a present /0. This is a different observation from a source selector miss.

In particular, throw does not mean “ignore this row and try the /16.” It means leave this table. A trace that reaches main after 100: /24 throw therefore tells a different story from one that reaches main after 100: selector miss, even though both end at the same default route.

In practice

When a route looks surprising, start with the source and destination of the lookup you want to explain. Read the rules in priority order, identify which selector matched, then inspect the destination prefix and route type in the named table. A listing of the main table alone cannot tell you whether the lookup ever reached it.

Distinguish an exhausted lookup from an unknown one. For example, with source 192.0.2.7 and destination 198.51.100.8, the source rule matches but neither policy prefix covers the destination. If the main default is also absent, the simulation can conclude that no route remains. If required scenario evidence is missing, it cannot conclude that: there is no routing result. With evidence provided, a malformed address such as 192.0.2.256 is an input error, not a routing failure.

This example assumes the local table has no match and the final table is empty. It uses two fixed policy prefixes and leaves out equal-cost routes, marks, and virtual routing and forwarding (VRF). It neither inspects nor changes your system. Use the rule path and the selected entry together to explain a routing decision; whether a packet actually arrived is a separate question.

Frequently asked questions

Editorial questions based on the listed sources and explicitly labeled local examples.

Can a throw route fall back to a broader prefix in the same table?

Not in this Linux lookup example. The selected throw route terminates that table lookup as though no route were found, so a later policy rule may be tried. An absent specific route is different: the broader matching route in the same table may then be selected.

What does a lower rule priority number mean?

A smaller numerical rule priority is considered earlier in the RPDB scan. Within a selected routing table the route lookup is a separate operation.

Can a policy match more than source?

Yes. Linux policy rules can also match attributes such as destination, incoming interface or marks. This model only exercises its listed selectors.

Does a route prove a packet arrives?

No. This lab ends at route selection. It does not observe forwarding, firewall processing or delivery. A selected entry is evidence of this stipulated lookup, not proof of arrival.

Sources & model boundaries

Primary references used for this explanation. The interactive example is an educational model, not a live check.

  1. ip-rule(8)

    DESCRIPTION. Rules scanned in increasing numerical priority; lookup failure can permit another rule, successful terminal action ends lookup.

    Checked .

  2. ip-route(8)

    route types. Route types include throw, which terminates lookup in a table as if no route found; unreachable is distinct. Prefix lengths and default route described. Equal-metric selection is outside toy model.

    Checked .

  3. RFC 1812: Requirements for IP Version 4 Routers

    Appendix E.1 and E.3.1. Longest matching route prefix precedes tie-breaking policy in the described classic IPv4 routing algorithm. Linux rule/table behavior separately documented.

    Checked .

Report an issue. Include the article URL and ID, not passwords or access keys.