Blame man/man8/ip-rule.8

Packit Service 3880ab
.TH IP\-RULE 8 "20 Dec 2011" "iproute2" "Linux"
Packit Service 3880ab
.SH "NAME"
Packit Service 3880ab
ip-rule \- routing policy database management
Packit Service 3880ab
.SH "SYNOPSIS"
Packit Service 3880ab
.sp
Packit Service 3880ab
.ad l
Packit Service 3880ab
.in +8
Packit Service 3880ab
.ti -8
Packit Service 3880ab
.B ip
Packit Service 3880ab
.RI "[ " OPTIONS " ]"
Packit Service 3880ab
.B rule
Packit Service 3880ab
.RI "{ " COMMAND " | "
Packit Service 3880ab
.BR help " }"
Packit Service 3880ab
.sp
Packit Service 3880ab
Packit Service 3880ab
.ti -8
Packit Service 3880ab
.B  ip rule
Packit Service 3880ab
.RB "[ " list
Packit Service 3880ab
.RI "[ " SELECTOR " ]]"
Packit Service 3880ab
Packit Service 3880ab
.ti -8
Packit Service 3880ab
.B  ip rule
Packit Service 3880ab
.RB "{ " add " | " del " }"
Packit Service 3880ab
.I  SELECTOR ACTION
Packit Service 3880ab
Packit Service 3880ab
.ti -8
Packit Service 3880ab
.B ip rule
Packit Service 3880ab
.RB "{ " flush " | " save " | " restore " }"
Packit Service 3880ab
Packit Service 3880ab
.ti -8
Packit Service 3880ab
.IR SELECTOR " := [ "
Packit Service 3880ab
.BR not " ] ["
Packit Service 3880ab
.B  from
Packit Service 3880ab
.IR PREFIX " ] [ "
Packit Service 3880ab
.B  to
Packit Service 3880ab
.IR PREFIX " ] [ "
Packit Service 3880ab
.B  tos
Packit Service 3880ab
.IR TOS " ] [ "
Packit Service 3880ab
.B  fwmark
Packit Service 3880ab
.IR FWMARK\fR[\fB/\fIMASK "] ] [ "
Packit Service 3880ab
.B  iif
Packit Service 3880ab
.IR STRING " ] [ "
Packit Service 3880ab
.B  oif
Packit Service 3880ab
.IR STRING " ] [ "
Packit Service 3880ab
.B  pref
Packit Service 3880ab
.IR NUMBER " ] [ "
Packit Service 3880ab
.IR l3mdev " ] [ "
Packit Service 3880ab
.B uidrange
Packit Service 3880ab
.IR NUMBER "-" NUMBER " ] [ "
Packit Service 3880ab
.B ipproto
Packit Service 3880ab
.IR PROTOCOL " ] [ "
Packit Service 3880ab
.BR sport " [ "
Packit Service 3880ab
.IR NUMBER " | "
Packit Service 3880ab
.IR NUMBER "-" NUMBER " ] ] [ "
Packit Service 3880ab
.BR dport " [ "
Packit Service 3880ab
.IR NUMBER " | "
Packit Service 3880ab
.IR NUMBER "-" NUMBER " ] ] [ "
Packit Service 3880ab
.B  tun_id
Packit Service 3880ab
.IR TUN_ID " ]"
Packit Service 3880ab
.BR
Packit Service 3880ab
Packit Service 3880ab
Packit Service 3880ab
.ti -8
Packit Service 3880ab
.IR ACTION " := [ "
Packit Service 3880ab
.B  table
Packit Service 3880ab
.IR TABLE_ID " ] [ "
Packit Service 3880ab
.B  protocol
Packit Service 3880ab
.IR PROTO " ] [ "
Packit Service 3880ab
.B  nat
Packit Service 3880ab
.IR ADDRESS " ] [ "
Packit Service 3880ab
.B realms
Packit Service 3880ab
.RI "[" SRCREALM "\fB/\fR]" DSTREALM " ] ["
Packit Service 3880ab
.B goto
Packit Service 3880ab
.IR NUMBER " ] " SUPPRESSOR
Packit Service 3880ab
Packit Service 3880ab
.ti -8
Packit Service 3880ab
.IR SUPPRESSOR " := [ "
Packit Service 3880ab
.B  suppress_prefixlength
Packit Service 3880ab
.IR NUMBER " ] [ "
Packit Service 3880ab
.B  suppress_ifgroup
Packit Service 3880ab
.IR GROUP " ]"
Packit Service 3880ab
Packit Service 3880ab
.ti -8
Packit Service 3880ab
.IR TABLE_ID " := [ "
Packit Service 3880ab
.BR local " | " main " | " default " |"
Packit Service 3880ab
.IR NUMBER " ]"
Packit Service 3880ab
Packit Service 3880ab
.SH DESCRIPTION
Packit Service 3880ab
.I ip rule
Packit Service 3880ab
manipulates rules
Packit Service 3880ab
in the routing policy database control the route selection algorithm.
Packit Service 3880ab
Packit Service 3880ab
.P
Packit Service 3880ab
Classic routing algorithms used in the Internet make routing decisions
Packit Service 3880ab
based only on the destination address of packets (and in theory,
Packit Service 3880ab
but not in practice, on the TOS field).
Packit Service 3880ab
Packit Service 3880ab
.P
Packit Service 3880ab
In some circumstances we want to route packets differently depending not only
Packit Service 3880ab
on destination addresses, but also on other packet fields: source address,
Packit Service 3880ab
IP protocol, transport protocol ports or even packet payload.
Packit Service 3880ab
This task is called 'policy routing'.
Packit Service 3880ab
Packit Service 3880ab
.P
Packit Service 3880ab
To solve this task, the conventional destination based routing table, ordered
Packit Service 3880ab
according to the longest match rule, is replaced with a 'routing policy
Packit Service 3880ab
database' (or RPDB), which selects routes by executing some set of rules.
Packit Service 3880ab
Packit Service 3880ab
.P
Packit Service 3880ab
Each policy routing rule consists of a
Packit Service 3880ab
.B selector
Packit Service 3880ab
and an
Packit Service 3880ab
.B action predicate.
Packit Service 3880ab
The RPDB is scanned in order of decreasing priority (note that lower number
Packit Service 3880ab
means higher priority, see the description of
Packit Service 3880ab
.I PREFERENCE
Packit Service 3880ab
below). The selector
Packit Service 3880ab
of each rule is applied to {source address, destination address, incoming
Packit Service 3880ab
interface, tos, fwmark} and, if the selector matches the packet,
Packit Service 3880ab
the action is performed. The action predicate may return with success.
Packit Service 3880ab
In this case, it will either give a route or failure indication
Packit Service 3880ab
and the RPDB lookup is terminated. Otherwise, the RPDB program
Packit Service 3880ab
continues with the next rule.
Packit Service 3880ab
Packit Service 3880ab
.P
Packit Service 3880ab
Semantically, the natural action is to select the nexthop and the output device.
Packit Service 3880ab
Packit Service 3880ab
.P
Packit Service 3880ab
At startup time the kernel configures the default RPDB consisting of three
Packit Service 3880ab
rules:
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
1.
Packit Service 3880ab
Priority: 0, Selector: match anything, Action: lookup routing
Packit Service 3880ab
table
Packit Service 3880ab
.B local
Packit Service 3880ab
(ID 255).
Packit Service 3880ab
The
Packit Service 3880ab
.B local
Packit Service 3880ab
table is a special routing table containing
Packit Service 3880ab
high priority control routes for local and broadcast addresses.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
2.
Packit Service 3880ab
Priority: 32766, Selector: match anything, Action: lookup routing
Packit Service 3880ab
table
Packit Service 3880ab
.B main
Packit Service 3880ab
(ID 254).
Packit Service 3880ab
The
Packit Service 3880ab
.B main
Packit Service 3880ab
table is the normal routing table containing all non-policy
Packit Service 3880ab
routes. This rule may be deleted and/or overridden with other
Packit Service 3880ab
ones by the administrator.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
3.
Packit Service 3880ab
Priority: 32767, Selector: match anything, Action: lookup routing
Packit Service 3880ab
table
Packit Service 3880ab
.B default
Packit Service 3880ab
(ID 253).
Packit Service 3880ab
The
Packit Service 3880ab
.B default
Packit Service 3880ab
table is empty. It is reserved for some post-processing if no previous
Packit Service 3880ab
default rules selected the packet.
Packit Service 3880ab
This rule may also be deleted.
Packit Service 3880ab
Packit Service 3880ab
.P
Packit Service 3880ab
Each RPDB entry has additional
Packit Service 3880ab
attributes. F.e. each rule has a pointer to some routing
Packit Service 3880ab
table. NAT and masquerading rules have an attribute to select new IP
Packit Service 3880ab
address to translate/masquerade. Besides that, rules have some
Packit Service 3880ab
optional attributes, which routes have, namely
Packit Service 3880ab
.BR "realms" .
Packit Service 3880ab
These values do not override those contained in the routing tables. They
Packit Service 3880ab
are only used if the route did not select any attributes.
Packit Service 3880ab
Packit Service 3880ab
.sp
Packit Service 3880ab
The RPDB may contain rules of the following types:
Packit Service 3880ab
Packit Service 3880ab
.RS
Packit Service 3880ab
.B unicast
Packit Service 3880ab
- the rule prescribes to return the route found
Packit Service 3880ab
in the routing table referenced by the rule.
Packit Service 3880ab
Packit Service 3880ab
.B blackhole
Packit Service 3880ab
- the rule prescribes to silently drop the packet.
Packit Service 3880ab
Packit Service 3880ab
.B unreachable
Packit Service 3880ab
- the rule prescribes to generate a 'Network is unreachable' error.
Packit Service 3880ab
Packit Service 3880ab
.B prohibit
Packit Service 3880ab
- the rule prescribes to generate 'Communication is administratively
Packit Service 3880ab
prohibited' error.
Packit Service 3880ab
Packit Service 3880ab
.B nat
Packit Service 3880ab
- the rule prescribes to translate the source address
Packit Service 3880ab
of the IP packet into some other value.
Packit Service 3880ab
.RE
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
.B ip rule add - insert a new rule
Packit Service 3880ab
.TP
Packit Service 3880ab
.B ip rule delete - delete a rule
Packit Service 3880ab
.RS
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI type " TYPE " (default)
Packit Service 3880ab
the type of this rule. The list of valid types was given in the previous
Packit Service 3880ab
subsection.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI from " PREFIX"
Packit Service 3880ab
select the source prefix to match.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI to " PREFIX"
Packit Service 3880ab
select the destination prefix to match.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI iif " NAME"
Packit Service 3880ab
select the incoming device to match. If the interface is loopback,
Packit Service 3880ab
the rule only matches packets originating from this host. This means
Packit Service 3880ab
that you may create separate routing tables for forwarded and local
Packit Service 3880ab
packets and, hence, completely segregate them.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI oif " NAME"
Packit Service 3880ab
select the outgoing device to match. The outgoing interface is only
Packit Service 3880ab
available for packets originating from local sockets that are bound to
Packit Service 3880ab
a device.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI tos " TOS"
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI dsfield " TOS"
Packit Service 3880ab
select the TOS value to match.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI fwmark " MARK"
Packit Service 3880ab
select the
Packit Service 3880ab
.B fwmark
Packit Service 3880ab
value to match.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI uidrange " NUMBER-NUMBER"
Packit Service 3880ab
select the
Packit Service 3880ab
.B uid
Packit Service 3880ab
value to match.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI ipproto " PROTOCOL"
Packit Service 3880ab
select the ip protocol value to match.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI sport " NUMBER | NUMBER-NUMBER"
Packit Service 3880ab
select the source port value to match. supports port range.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI dport " NUMBER | NUMBER-NUMBER"
Packit Service 3880ab
select the destination port value to match. supports port range.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI priority " PREFERENCE"
Packit Service 3880ab
the priority of this rule.
Packit Service 3880ab
.I PREFERENCE
Packit Service 3880ab
is an unsigned integer value, higher number means lower priority, and rules get
Packit Service 3880ab
processed in order of increasing number. Each rule
Packit Service 3880ab
should have an explicitly set
Packit Service 3880ab
.I unique
Packit Service 3880ab
priority value.
Packit Service 3880ab
The options preference and order are synonyms with priority.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI table " TABLEID"
Packit Service 3880ab
the routing table identifier to lookup if the rule selector matches.
Packit Service 3880ab
It is also possible to use lookup instead of table.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI protocol " PROTO"
Packit Service 3880ab
the routing protocol who installed the rule in question.  As an example when zebra installs a rule it would get RTPROT_ZEBRA as the installing protocol.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI suppress_prefixlength " NUMBER"
Packit Service 3880ab
reject routing decisions that have a prefix length of NUMBER or less.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI suppress_ifgroup " GROUP"
Packit Service 3880ab
reject routing decisions that use a device belonging to the interface
Packit Service 3880ab
group GROUP.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI realms " FROM/TO"
Packit Service 3880ab
Realms to select if the rule matched and the routing table lookup
Packit Service 3880ab
succeeded. Realm
Packit Service 3880ab
.I TO
Packit Service 3880ab
is only used if the route did not select any realm.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI nat " ADDRESS"
Packit Service 3880ab
The base of the IP address block to translate (for source addresses).
Packit Service 3880ab
The
Packit Service 3880ab
.I ADDRESS
Packit Service 3880ab
may be either the start of the block of NAT addresses (selected by NAT
Packit Service 3880ab
routes) or a local host address (or even zero).
Packit Service 3880ab
In the last case the router does not translate the packets, but
Packit Service 3880ab
masquerades them to this address.
Packit Service 3880ab
Using map-to instead of nat means the same thing.
Packit Service 3880ab
Packit Service 3880ab
.B Warning:
Packit Service 3880ab
Changes to the RPDB made with these commands do not become active
Packit Service 3880ab
immediately. It is assumed that after a script finishes a batch of
Packit Service 3880ab
updates, it flushes the routing cache with
Packit Service 3880ab
.BR "ip route flush cache" .
Packit Service 3880ab
.RE
Packit Service 3880ab
.TP
Packit Service 3880ab
.B ip rule flush - also dumps all the deleted rules.
Packit Service 3880ab
.RS
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI protocol " PROTO"
Packit Service 3880ab
Select the originating protocol.
Packit Service 3880ab
.RE
Packit Service 3880ab
.TP
Packit Service 3880ab
.B ip rule show - list rules
Packit Service 3880ab
This command has no arguments.
Packit Service 3880ab
The options list or lst are synonyms with show.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
.B ip rule save
Packit Service 3880ab
.RS
Packit Service 3880ab
.TP
Packit Service 3880ab
.BI protocol " PROTO"
Packit Service 3880ab
Select the originating protocol.
Packit Service 3880ab
.RE
Packit Service 3880ab
.TP
Packit Service 3880ab
save rules table information to stdout
Packit Service 3880ab
.RS
Packit Service 3880ab
This command behaves like
Packit Service 3880ab
.BR "ip rule show"
Packit Service 3880ab
except that the output is raw data suitable for passing to
Packit Service 3880ab
.BR "ip rule restore" .
Packit Service 3880ab
.RE
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
.B ip rule restore
Packit Service 3880ab
restore rules table information from stdin
Packit Service 3880ab
.RS
Packit Service 3880ab
This command expects to read a data stream as returned from
Packit Service 3880ab
.BR "ip rule save" .
Packit Service 3880ab
It will attempt to restore the rules table information exactly as
Packit Service 3880ab
it was at the time of the save. Any rules already in the table are
Packit Service 3880ab
left unchanged, and duplicates are not ignored.
Packit Service 3880ab
.RE
Packit Service 3880ab
Packit Service 3880ab
.SH SEE ALSO
Packit Service 3880ab
.br
Packit Service 3880ab
.BR ip (8)
Packit Service 3880ab
Packit Service 3880ab
.SH AUTHOR
Packit Service 3880ab
Original Manpage by Michail Litvak <mci@owl.openwall.com>