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