]> git.proxmox.com Git - mirror_iproute2.git/blame - man/man8/ip-rule.8
iproute: ip route get support for sport, dport and ipproto match
[mirror_iproute2.git] / man / man8 / ip-rule.8
CommitLineData
2a9721f1
SH
1.TH IP\-RULE 8 "20 Dec 2011" "iproute2" "Linux"
2.SH "NAME"
aab2702d 3ip-rule \- routing policy database management
2a9721f1
SH
4.SH "SYNOPSIS"
5.sp
6.ad l
7.in +8
8.ti -8
9.B ip
10.RI "[ " OPTIONS " ]"
11.B rule
582b0fc6 12.RI "{ " COMMAND " | "
2a9721f1
SH
13.BR help " }"
14.sp
15
16.ti -8
17.B ip rule
ca89c521
HL
18.RB "[ " list
19.RI "[ " SELECTOR " ]]"
582b0fc6
PS
20
21.ti -8
22.B ip rule
23.RB "{ " add " | " del " }"
2a9721f1
SH
24.I SELECTOR ACTION
25
2f4e171f 26.ti -8
582b0fc6
PS
27.B ip rule
28.RB "{ " flush " | " save " | " restore " }"
2f4e171f 29
2a9721f1
SH
30.ti -8
31.IR SELECTOR " := [ "
582b0fc6 32.BR not " ] ["
2a9721f1
SH
33.B from
34.IR PREFIX " ] [ "
35.B to
36.IR PREFIX " ] [ "
37.B tos
38.IR TOS " ] [ "
39.B fwmark
582b0fc6 40.IR FWMARK\fR[\fB/\fIMASK "] ] [ "
2a9721f1
SH
41.B iif
42.IR STRING " ] [ "
43.B oif
44.IR STRING " ] [ "
45.B pref
ca89c521 46.IR NUMBER " ] [ "
f686f764
RP
47.IR l3mdev " ] [ "
48.B uidrange
49.IR NUMBER "-" NUMBER " ] [ "
50.B ipproto
51.IR PROTOCOL " ] [ "
52.BR sport " [ "
53.IR NUMBER " | "
54.IR NUMBER "-" NUMBER " ] ] [ "
55.BR dport " [ "
56.IR NUMBER " | "
57.IR NUMBER "-" NUMBER " ] ]"
58.BR
59
2a9721f1
SH
60
61.ti -8
62.IR ACTION " := [ "
63.B table
64.IR TABLE_ID " ] [ "
7c083da7
DS
65.B protocol
66.IR PROTO " ] [ "
2a9721f1
SH
67.B nat
68.IR ADDRESS " ] [ "
ccaf6eb5 69.B realms
582b0fc6
PS
70.RI "[" SRCREALM "\fB/\fR]" DSTREALM " ] ["
71.B goto
72.IR NUMBER " ] " SUPPRESSOR
b1d0525f
ST
73
74.ti -8
75.IR SUPPRESSOR " := [ "
76.B suppress_prefixlength
77.IR NUMBER " ] [ "
78.B suppress_ifgroup
79.IR GROUP " ]"
2a9721f1
SH
80
81.ti -8
82.IR TABLE_ID " := [ "
83.BR local " | " main " | " default " |"
84.IR NUMBER " ]"
85
86.SH DESCRIPTION
87.I ip rule
5699275b 88manipulates rules
2a9721f1
SH
89in the routing policy database control the route selection algorithm.
90
91.P
92Classic routing algorithms used in the Internet make routing decisions
93based only on the destination address of packets (and in theory,
94but not in practice, on the TOS field).
95
96.P
97In some circumstances we want to route packets differently depending not only
98on destination addresses, but also on other packet fields: source address,
99IP protocol, transport protocol ports or even packet payload.
100This task is called 'policy routing'.
101
102.P
103To solve this task, the conventional destination based routing table, ordered
104according to the longest match rule, is replaced with a 'routing policy
105database' (or RPDB), which selects routes by executing some set of rules.
106
107.P
108Each policy routing rule consists of a
109.B selector
110and an
111.B action predicate.
843fc900
PS
112The RPDB is scanned in order of decreasing priority (note that lower number
113means higher priority, see the description of
114.I PREFERENCE
115below). The selector
2a9721f1
SH
116of each rule is applied to {source address, destination address, incoming
117interface, tos, fwmark} and, if the selector matches the packet,
a89d5329 118the action is performed. The action predicate may return with success.
2a9721f1
SH
119In this case, it will either give a route or failure indication
120and the RPDB lookup is terminated. Otherwise, the RPDB program
49572501 121continues with the next rule.
2a9721f1
SH
122
123.P
49572501 124Semantically, the natural action is to select the nexthop and the output device.
2a9721f1
SH
125
126.P
127At startup time the kernel configures the default RPDB consisting of three
128rules:
129
130.TP
1311.
132Priority: 0, Selector: match anything, Action: lookup routing
133table
134.B local
135(ID 255).
136The
137.B local
138table is a special routing table containing
139high priority control routes for local and broadcast addresses.
2a9721f1
SH
140
141.TP
1422.
143Priority: 32766, Selector: match anything, Action: lookup routing
144table
145.B main
146(ID 254).
147The
148.B main
149table is the normal routing table containing all non-policy
150routes. This rule may be deleted and/or overridden with other
151ones by the administrator.
152
153.TP
1543.
155Priority: 32767, Selector: match anything, Action: lookup routing
156table
157.B default
158(ID 253).
159The
160.B default
a89d5329 161table is empty. It is reserved for some post-processing if no previous
2a9721f1
SH
162default rules selected the packet.
163This rule may also be deleted.
164
165.P
166Each RPDB entry has additional
a89d5329
167attributes. F.e. each rule has a pointer to some routing
168table. NAT and masquerading rules have an attribute to select new IP
169address to translate/masquerade. Besides that, rules have some
2a9721f1
SH
170optional attributes, which routes have, namely
171.BR "realms" .
a89d5329 172These values do not override those contained in the routing tables. They
2a9721f1
SH
173are only used if the route did not select any attributes.
174
175.sp
176The RPDB may contain rules of the following types:
177
1284fd3a 178.RS
2a9721f1
SH
179.B unicast
180- the rule prescribes to return the route found
181in the routing table referenced by the rule.
182
183.B blackhole
184- the rule prescribes to silently drop the packet.
185
186.B unreachable
187- the rule prescribes to generate a 'Network is unreachable' error.
188
189.B prohibit
190- the rule prescribes to generate 'Communication is administratively
191prohibited' error.
192
193.B nat
194- the rule prescribes to translate the source address
195of the IP packet into some other value.
1284fd3a 196.RE
2a9721f1 197
1284fd3a 198.TP
199.B ip rule add - insert a new rule
200.TP
201.B ip rule delete - delete a rule
202.RS
2a9721f1
SH
203.TP
204.BI type " TYPE " (default)
a89d5329 205the type of this rule. The list of valid types was given in the previous
2a9721f1
SH
206subsection.
207
208.TP
209.BI from " PREFIX"
210select the source prefix to match.
211
212.TP
213.BI to " PREFIX"
214select the destination prefix to match.
215
216.TP
217.BI iif " NAME"
a89d5329
218select the incoming device to match. If the interface is loopback,
219the rule only matches packets originating from this host. This means
2a9721f1
SH
220that you may create separate routing tables for forwarded and local
221packets and, hence, completely segregate them.
222
223.TP
224.BI oif " NAME"
a89d5329 225select the outgoing device to match. The outgoing interface is only
2a9721f1
SH
226available for packets originating from local sockets that are bound to
227a device.
228
229.TP
230.BI tos " TOS"
231.TP
232.BI dsfield " TOS"
233select the TOS value to match.
234
235.TP
236.BI fwmark " MARK"
237select the
238.B fwmark
239value to match.
240
f686f764
RP
241.TP
242.BI uidrange " NUMBER-NUMBER"
243select the
244.B uid
245value to match.
246
247.TP
248.BI ipproto " PROTOCOL"
249select the ip protocol value to match.
250
251.TP
252.BI sport " NUMBER | NUMBER-NUMBER"
253select the source port value to match. supports port range.
254
255.TP
256.BI dport " NUMBER | NUMBER-NUMBER"
257select the destination port value to match. supports port range.
258
2a9721f1
SH
259.TP
260.BI priority " PREFERENCE"
31a29009
PS
261the priority of this rule.
262.I PREFERENCE
843fc900
PS
263is an unsigned integer value, higher number means lower priority, and rules get
264processed in order of increasing number. Each rule
31a29009 265should have an explicitly set
2a9721f1
SH
266.I unique
267priority value.
268The options preference and order are synonyms with priority.
269
270.TP
271.BI table " TABLEID"
272the routing table identifier to lookup if the rule selector matches.
273It is also possible to use lookup instead of table.
274
7c083da7
DS
275.TP
276.BI protocol " PROTO"
277the 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.
278
b1d0525f
ST
279.TP
280.BI suppress_prefixlength " NUMBER"
281reject routing decisions that have a prefix length of NUMBER or less.
282
283.TP
284.BI suppress_ifgroup " GROUP"
285reject routing decisions that use a device belonging to the interface
286group GROUP.
287
2a9721f1
SH
288.TP
289.BI realms " FROM/TO"
290Realms to select if the rule matched and the routing table lookup
a89d5329 291succeeded. Realm
2a9721f1
SH
292.I TO
293is only used if the route did not select any realm.
294
295.TP
296.BI nat " ADDRESS"
297The base of the IP address block to translate (for source addresses).
298The
299.I ADDRESS
300may be either the start of the block of NAT addresses (selected by NAT
301routes) or a local host address (or even zero).
302In the last case the router does not translate the packets, but
303masquerades them to this address.
304Using map-to instead of nat means the same thing.
305
306.B Warning:
307Changes to the RPDB made with these commands do not become active
a89d5329 308immediately. It is assumed that after a script finishes a batch of
2a9721f1
SH
309updates, it flushes the routing cache with
310.BR "ip route flush cache" .
1284fd3a 311.RE
312.TP
313.B ip rule flush - also dumps all the deleted rules.
7c083da7
DS
314.RS
315.TP
316.BI protocol " PROTO"
317Select the originating protocol.
318.RE
1284fd3a 319.TP
320.B ip rule show - list rules
2a9721f1
SH
321This command has no arguments.
322The options list or lst are synonyms with show.
323
2f4e171f
KT
324.TP
325.B ip rule save
7c083da7
DS
326.RS
327.TP
328.BI protocol " PROTO"
329Select the originating protocol.
330.RE
331.TP
2f4e171f
KT
332save rules table information to stdout
333.RS
334This command behaves like
335.BR "ip rule show"
336except that the output is raw data suitable for passing to
337.BR "ip rule restore" .
338.RE
339
340.TP
341.B ip rule restore
342restore rules table information from stdin
343.RS
344This command expects to read a data stream as returned from
345.BR "ip rule save" .
346It will attempt to restore the rules table information exactly as
347it was at the time of the save. Any rules already in the table are
348left unchanged, and duplicates are not ignored.
349.RE
350
2a9721f1
SH
351.SH SEE ALSO
352.br
353.BR ip (8)
354
355.SH AUTHOR
356Original Manpage by Michail Litvak <mci@owl.openwall.com>