ip-rule
routing policy database management
- Provided by: iproute2 (Version: 4.3.0-1ubuntu3.16.04.5)
- Report a bug
routing policy database management
ip [ OPTIONS ] rule { COMMAND | help }
ip rule [ list | add | del | flush | save ] SELECTOR ACTION
ip rule restore
SELECTOR := [ from PREFIX ] [ to PREFIX ] [ tos TOS ] [ fwmark FWMARK[/MASK] ] [ iif STRING ] [ oif STRING ] [ pref NUMBER ]
ACTION := [ table TABLE_ID ] [ nat ADDRESS ] [ realms [SRCREALM/]DSTREALM ] SUPPRESSOR
SUPPRESSOR := [ suppress_prefixlength NUMBER ] [ suppress_ifgroup GROUP ]
TABLE_ID := [ local | main | default | NUMBER ]
ip rule manipulates rules in the routing policy database control the route selection algorithm.
Classic routing algorithms used in the Internet make routing decisions based only on the destination address of packets (and in theory, but not in practice, on the TOS field).
In some circumstances we want to route packets differently depending not only on destination addresses, but also on other packet fields: source address, IP protocol, transport protocol ports or even packet payload. This task is called 'policy routing'.
To solve this task, the conventional destination based routing table, ordered according to the longest match rule, is replaced with a 'routing policy database' (or RPDB), which selects routes by executing some set of rules.
Each policy routing rule consists of a selector and an action predicate. The RPDB is scanned in order of decreasing priority. The selector of each rule is applied to {source address, destination address, incoming interface, tos, fwmark} and, if the selector matches the packet, the action is performed. The action predicate may return with success. In this case, it will either give a route or failure indication and the RPDB lookup is terminated. Otherwise, the RPDB program continues with the next rule.
Semantically, the natural action is to select the nexthop and the output device.
At startup time the kernel configures the default RPDB consisting of three rules:
Rule 0 is special. It cannot be deleted or overridden.
Each RPDB entry has additional attributes. F.e. each rule has a pointer to some routing table. NAT and masquerading rules have an attribute to select new IP address to translate/masquerade. Besides that, rules have some optional attributes, which routes have, namely realms. These values do not override those contained in the routing tables. They are only used if the route did not select any attributes.
The RPDB may contain rules of the following types:
blackhole - the rule prescribes to silently drop the packet.
unreachable - the rule prescribes to generate a 'Network is unreachable' error.
prohibit - the rule prescribes to generate 'Communication is administratively prohibited' error.
nat - the rule prescribes to translate the source address of the IP packet into some other value.
Warning: Changes to the RPDB made with these commands do not become active immediately. It is assumed that after a script finishes a batch of updates, it flushes the routing cache with ip route flush cache.
Original Manpage by Michail Litvak <mci@owl.openwall.com>