Blame man/man8/ip-rule.8

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