iptables: refer to dmesg when we hit error
[jleu-iptables.git] / iptables.8.in
blob9947da4c46aab94961b49b197012065dfe9b57a4
1 .TH IPTABLES 8 "Jul 03, 2008" "" ""
2 .\"
3 .\" Man page written by Herve Eychenne <rv@wallfire.org> (May 1999)
4 .\" It is based on ipchains page.
5 .\" TODO: add a word for protocol helpers (FTP, IRC, SNMP-ALG)
6 .\"
7 .\" ipchains page by Paul ``Rusty'' Russell March 1997
8 .\" Based on the original ipfwadm man page by Jos Vos <jos@xos.nl>
9 .\"
10 .\"     This program is free software; you can redistribute it and/or modify
11 .\"     it under the terms of the GNU General Public License as published by
12 .\"     the Free Software Foundation; either version 2 of the License, or
13 .\"     (at your option) any later version.
14 .\"
15 .\"     This program is distributed in the hope that it will be useful,
16 .\"     but WITHOUT ANY WARRANTY; without even the implied warranty of
17 .\"     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 .\"     GNU General Public License for more details.
19 .\"
20 .\"     You should have received a copy of the GNU General Public License
21 .\"     along with this program; if not, write to the Free Software
22 .\"     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 .\"
24 .\"
25 .SH NAME
26 iptables \- administration tool for IPv4 packet filtering and NAT
27 .SH SYNOPSIS
28 \fBiptables\fP [\fB-t\fP \fItable\fP] {\fB-A\fP|\fB-D\fP} \fIchain\fP \fIrule-specification\fP
29 .PP
30 \fBiptables\fP [\fB-t\fP \fItable\fP] \fB-I\fP [\fIrulenum\fP] \fIrule-specification\fP
31 .PP
32 \fBiptables\fP [\fB-t\fP \fItable\fP] \fB-R\fP \fIrulenum rule-specification\fP
33 .PP
34 \fBiptables\fP [\fB-t\fP \fItable\fP] \fB-D\fP \fIchain rulenum\fP
35 .PP
36 \fBiptables\fP [\fB-t\fP \fItable\fP] \fB-S\fP [\fIchain\fP]
37 .PP
38 \fBiptables\fP [\fB-t\fP \fItable\fP] {\fB-F\fP|\fB-L\fP|\fB-Z\fP} [\fIchain\fP] [\fIoptions...\fP]
39 .PP
40 \fBiptables\fP [\fB-t\fP \fItable\fP] \fB-N\fP \fIchain\fP
41 .PP
42 \fBiptables\fP [\fB-t\fP \fItable\fP] \fB-X\fP [\fIchain\fP]
43 .PP
44 \fBiptables\fP [\fB-t\fP \fItable\fP] \fB-P\fP \fIchain target\fP
45 .PP
46 \fBiptables\fP [\fB-t\fP \fItable\fP] \fB-E\fP \fIold-chain-name new-chain-name\fP
47 .PP
48 rule-specification = [\fImatches...\fP] [\fItarget\fP]
49 .PP
50 match = \fB-m\fP \fImatchname\fP [\fIper-match-options\fP]
51 .PP
52 target = \fB-j\fP \fItargetname\fP [\fIper-target-options\fP]
53 .SH DESCRIPTION
54 \fBIptables\fP is used to set up, maintain, and inspect the
55 tables of IPv4 packet
56 filter rules in the Linux kernel.  Several different tables
57 may be defined.  Each table contains a number of built-in
58 chains and may also contain user-defined chains.
60 Each chain is a list of rules which can match a set of packets.  Each
61 rule specifies what to do with a packet that matches.  This is called
62 a `target', which may be a jump to a user-defined chain in the same
63 table.
65 .SH TARGETS
66 A firewall rule specifies criteria for a packet and a target.  If the
67 packet does not match, the next rule in the chain is the examined; if
68 it does match, then the next rule is specified by the value of the
69 target, which can be the name of a user-defined chain or one of the
70 special values \fBACCEPT\fP, \fBDROP\fP, \fBQUEUE\fP or \fBRETURN\fP.
71 .PP
72 \fBACCEPT\fP means to let the packet through.
73 \fBDROP\fP means to drop the packet on the floor.
74 \fBQUEUE\fP means to pass the packet to userspace.
75 (How the packet can be received
76 by a userspace process differs by the particular queue handler.  2.4.x
77 and 2.6.x kernels up to 2.6.13 include the \fBip_queue\fP
78 queue handler.  Kernels 2.6.14 and later additionally include the
79 \fBnfnetlink_queue\fP queue handler.  Packets with a target of QUEUE will be
80 sent to queue number '0' in this case. Please also see the \fBNFQUEUE\fP
81 target as described later in this man page.)
82 \fBRETURN\fP means stop traversing this chain and resume at the next
83 rule in the
84 previous (calling) chain.  If the end of a built-in chain is reached
85 or a rule in a built-in chain with target \fBRETURN\fP
86 is matched, the target specified by the chain policy determines the
87 fate of the packet.
88 .SH TABLES
89 There are currently three independent tables (which tables are present
90 at any time depends on the kernel configuration options and which
91 modules are present).
92 .TP
93 \fB-t\fP, \fB--table\fP \fItable\fP
94 This option specifies the packet matching table which the command
95 should operate on.  If the kernel is configured with automatic module
96 loading, an attempt will be made to load the appropriate module for
97 that table if it is not already there.
99 The tables are as follows:
101 .TP .4i
102 \fBfilter\fP:
103 This is the default table (if no -t option is passed).  It contains
104 the built-in chains \fBINPUT\fP (for packets destined to local sockets),
105 \fBFORWARD\fP (for packets being routed through the box), and
106 \fBOUTPUT\fP (for locally-generated packets).
108 \fBnat\fP:
109 This table is consulted when a packet that creates a new
110 connection is encountered.  It consists of three built-ins: \fBPREROUTING\fP
111 (for altering packets as soon as they come in), \fBOUTPUT\fP
112 (for altering locally-generated packets before routing), and \fBPOSTROUTING\fP
113 (for altering packets as they are about to go out).
115 \fBmangle\fP:
116 This table is used for specialized packet alteration.  Until kernel
117 2.4.17 it had two built-in chains: \fBPREROUTING\fP
118 (for altering incoming packets before routing) and \fBOUTPUT\fP
119 (for altering locally-generated packets before routing).
120 Since kernel 2.4.18, three other built-in chains are also supported:
121 \fBINPUT\fP (for packets coming into the box itself), \fBFORWARD\fP
122 (for altering packets being routed through the box), and \fBPOSTROUTING\fP
123 (for altering packets as they are about to go out).
125 \fBraw\fP:
126 This table is used mainly for configuring exemptions from connection
127 tracking in combination with the NOTRACK target.  It registers at the netfilter
128 hooks with higher priority and is thus called before ip_conntrack, or any other
129 IP tables.  It provides the following built-in chains: \fBPREROUTING\fP
130 (for packets arriving via any network interface) \fBOUTPUT\fP
131 (for packets generated by local processes)
133 .SH OPTIONS
134 The options that are recognized by
135 \fBiptables\fP can be divided into several different groups.
136 .SS COMMANDS
137 These options specify the desired action to perform. Only one of them
138 can be specified on the command line unless otherwise stated
139 below. For long versions of the command and option names, you
140 need to use only enough letters to ensure that
141 \fBiptables\fP can differentiate it from all other options.
143 \fB-A\fP, \fB--append\fP \fIchain rule-specification\fP
144 Append one or more rules to the end of the selected chain.
145 When the source and/or destination names resolve to more than one
146 address, a rule will be added for each possible address combination.
148 \fB-D\fP, \fB--delete\fP \fIchain rule-specification\fP
151 \fB-D\fP, \fB--delete\fP \fIchain rulenum\fP
152 Delete one or more rules from the selected chain.  There are two
153 versions of this command: the rule can be specified as a number in the
154 chain (starting at 1 for the first rule) or a rule to match.
156 \fB-I\fP, \fB--insert\fP \fIchain\fP [\fIrulenum\fP] \fIrule-specification\fP
157 Insert one or more rules in the selected chain as the given rule
158 number.  So, if the rule number is 1, the rule or rules are inserted
159 at the head of the chain.  This is also the default if no rule number
160 is specified.
162 \fB-R\fP, \fB--replace\fP \fIchain rulenum rule-specification\fP
163 Replace a rule in the selected chain.  If the source and/or
164 destination names resolve to multiple addresses, the command will
165 fail.  Rules are numbered starting at 1.
167 \fB-L\fP, \fB--list\fP [\fIchain\fP]
168 List all rules in the selected chain.  If no chain is selected, all
169 chains are listed. Like every other iptables command, it applies to the
170 specified table (filter is the default), so NAT rules get listed by
172  iptables -t nat -n -L
174 Please note that it is often used with the \fB-n\fP
175 option, in order to avoid long reverse DNS lookups.
176 It is legal to specify the \fB-Z\fP
177 (zero) option as well, in which case the chain(s) will be atomically
178 listed and zeroed.  The exact output is affected by the other
179 arguments given. The exact rules are suppressed until you use
181  iptables -L -v
184 \fB-S\fP, \fB--list-rules\fP [\fIchain\fP]
185 Print all rules in the selected chain.  If no chain is selected, all
186 chains are printed like iptables-save. Like every other iptables command,
187 it applies to the specified table (filter is the default).
189 \fB-F\fP, \fB--flush\fP [\fIchain\fP]
190 Flush the selected chain (all the chains in the table if none is given).
191 This is equivalent to deleting all the rules one by one.
193 \fB-Z\fP, \fB--zero\fP [\fIchain\fP]
194 Zero the packet and byte counters in all chains.  It is legal to
195 specify the
196 \fB-L\fP, \fB--list\fP
197 (list) option as well, to see the counters immediately before they are
198 cleared. (See above.)
200 \fB-N\fP, \fB--new-chain\fP \fIchain\fP
201 Create a new user-defined chain by the given name.  There must be no
202 target of that name already.
204 \fB-X\fP, \fB--delete-chain\fP [\fIchain\fP]
205 Delete the optional user-defined chain specified.  There must be no references
206 to the chain.  If there are, you must delete or replace the referring rules
207 before the chain can be deleted.  The chain must be empty, i.e. not contain
208 any rules.  If no argument is given, it will attempt to delete every
209 non-builtin chain in the table.
211 \fB-P\fP, \fB--policy\fP \fIchain target\fP
212 Set the policy for the chain to the given target.  See the section \fBTARGETS\fP
213 for the legal targets.  Only built-in (non-user-defined) chains can have
214 policies, and neither built-in nor user-defined chains can be policy
215 targets.
217 \fB-E\fP, \fB--rename-chain\fP \fIold-chain new-chain\fP
218 Rename the user specified chain to the user supplied name.  This is
219 cosmetic, and has no effect on the structure of the table.
221 .B -h
222 Help.
223 Give a (currently very brief) description of the command syntax.
224 .SS PARAMETERS
225 The following parameters make up a rule specification (as used in the
226 add, delete, insert, replace and append commands).
228 [\fB!\fP] \fB-p\fP, \fB--protocol\fP \fIprotocol\fP
229 The protocol of the rule or of the packet to check.
230 The specified protocol can be one of \fBtcp\fP, \fBudp\fP, \fBudplite\fP,
231 \fBicmp\fP, \fBesp\fP, \fBah\fP, \fBsctp\fP or \fBall\fP,
232 or it can be a numeric value, representing one of these protocols or a
233 different one.  A protocol name from /etc/protocols is also allowed.
234 A "!" argument before the protocol inverts the
235 test.  The number zero is equivalent to \fBall\fP.
236 Protocol \fBall\fP
237 will match with all protocols and is taken as default when this
238 option is omitted.
240 [\fB!\fP] \fB-s\fP, \fB--source\fP \fIaddress\fP[\fB/\fP\fImask\fP]
241 Source specification. \fIAddress\fP
242 can be either a network name, a hostname (please note that specifying
243 any name to be resolved with a remote query such as DNS is a really bad idea),
244 a network IP address (with \fB/\fP\fImask\fP), or a plain IP address.
245 The \fImask\fP
246 can be either a network mask or a plain number,
247 specifying the number of 1's at the left side of the network mask.
248 Thus, a mask of \fI24\fP is equivalent to \fI255.255.255.0\fP.
249 A "!" argument before the address specification inverts the sense of
250 the address. The flag \fB--src\fP is an alias for this option.
252 [\fB!\fP] \fB-d\fP, \fB--destination\fP \fIaddress\fP[\fB/\fP\fImask\fP]
253 Destination specification. 
254 See the description of the \fB-s\fP
255 (source) flag for a detailed description of the syntax.  The flag
256 \fB--dst\fP is an alias for this option.
258 \fB-j\fP, \fB--jump\fP \fItarget\fP
259 This specifies the target of the rule; i.e., what to do if the packet
260 matches it.  The target can be a user-defined chain (other than the
261 one this rule is in), one of the special builtin targets which decide
262 the fate of the packet immediately, or an extension (see \fBEXTENSIONS\fP
263 below).  If this
264 option is omitted in a rule (and \fB-g\fP
265 is not used), then matching the rule will have no
266 effect on the packet's fate, but the counters on the rule will be
267 incremented.
269 \fB-g\fP, \fB--goto\fP \fIchain\fP
270 This specifies that the processing should continue in a user
271 specified chain. Unlike the --jump option return will not continue
272 processing in this chain but instead in the chain that called us via
273 --jump.
275 [\fB!\fP] \fB-i\fP, \fB--in-interface\fP \fIname\fP
276 Name of an interface via which a packet was received (only for
277 packets entering the \fBINPUT\fP, \fBFORWARD\fP and \fBPREROUTING\fP
278 chains).  When the "!" argument is used before the interface name, the
279 sense is inverted.  If the interface name ends in a "+", then any
280 interface which begins with this name will match.  If this option is
281 omitted, any interface name will match.
283 [\fB!\fP] \fB-o\fP, \fB--out-interface\fP \fIname\fP
284 Name of an interface via which a packet is going to be sent (for packets
285 entering the \fBFORWARD\fP, \fBOUTPUT\fP and \fBPOSTROUTING\fP
286 chains).  When the "!" argument is used before the interface name, the
287 sense is inverted.  If the interface name ends in a "+", then any
288 interface which begins with this name will match.  If this option is
289 omitted, any interface name will match.
291 [\fB!\fP] \fB-f\fP, \fB--fragment\fP
292 This means that the rule only refers to second and further fragments
293 of fragmented packets.  Since there is no way to tell the source or
294 destination ports of such a packet (or ICMP type), such a packet will
295 not match any rules which specify them.  When the "!" argument
296 precedes the "-f" flag, the rule will only match head fragments, or
297 unfragmented packets.
299 \fB-c\fP, \fB--set-counters\fP \fIpackets bytes\fP
300 This enables the administrator to initialize the packet and byte
301 counters of a rule (during \fBINSERT\fP, \fBAPPEND\fP, \fBREPLACE\fP
302 operations).
303 .SS "OTHER OPTIONS"
304 The following additional options can be specified:
306 \fB-v\fP, \fB--verbose\fP
307 Verbose output.  This option makes the list command show the interface
308 name, the rule options (if any), and the TOS masks.  The packet and
309 byte counters are also listed, with the suffix 'K', 'M' or 'G' for
310 1000, 1,000,000 and 1,000,000,000 multipliers respectively (but see
311 the \fB-x\fP flag to change this).
312 For appending, insertion, deletion and replacement, this causes
313 detailed information on the rule or rules to be printed.
315 \fB-n\fP, \fB--numeric\fP
316 Numeric output.
317 IP addresses and port numbers will be printed in numeric format.
318 By default, the program will try to display them as host names,
319 network names, or services (whenever applicable).
321 \fB-x\fP, \fB--exact\fP
322 Expand numbers.
323 Display the exact value of the packet and byte counters,
324 instead of only the rounded number in K's (multiples of 1000)
325 M's (multiples of 1000K) or G's (multiples of 1000M).  This option is
326 only relevant for the \fB-L\fP command.
328 .B "--line-numbers"
329 When listing rules, add line numbers to the beginning of each rule,
330 corresponding to that rule's position in the chain.
332 \fB--modprobe=\fP\fIcommand\fP
333 When adding or inserting rules into a chain, use \fIcommand\fP
334 to load any necessary modules (targets, match extensions, etc).
335 .SH MATCH EXTENSIONS
336 iptables can use extended packet matching modules.  These are loaded
337 in two ways: implicitly, when \fB-p\fP or \fB--protocol\fP
338 is specified, or with the \fB-m\fP or \fB--match\fP
339 options, followed by the matching module name; after these, various
340 extra command line options become available, depending on the specific
341 module.  You can specify multiple extended match modules in one line,
342 and you can use the \fB-h\fP or \fB--help\fP
343 options after the module has been specified to receive help specific
344 to that module.
346 The following are included in the base package, and most of these can
347 be preceded by a "\fB!\fP" to invert the sense of the match.
348 .\" @MATCH@
349 .SH TARGET EXTENSIONS
350 iptables can use extended target modules: the following are included
351 in the standard distribution.
352 .\" @TARGET@
353 .SH DIAGNOSTICS
354 Various error messages are printed to standard error.  The exit code
355 is 0 for correct functioning.  Errors which appear to be caused by
356 invalid or abused command line parameters cause an exit code of 2, and
357 other errors cause an exit code of 1.
358 .SH BUGS
359 Bugs?  What's this? ;-)
360 Well, you might want to have a look at http://bugzilla.netfilter.org/
361 .SH COMPATIBILITY WITH IPCHAINS
362 This \fBiptables\fP
363 is very similar to ipchains by Rusty Russell.  The main difference is
364 that the chains \fBINPUT\fP and \fBOUTPUT\fP
365 are only traversed for packets coming into the local host and
366 originating from the local host respectively.  Hence every packet only
367 passes through one of the three chains (except loopback traffic, which
368 involves both INPUT and OUTPUT chains); previously a forwarded packet
369 would pass through all three.
371 The other main difference is that \fB-i\fP refers to the input interface;
372 \fB-o\fP refers to the output interface, and both are available for packets
373 entering the \fBFORWARD\fP chain.
375 The various forms of NAT have been separated out; \fBiptables\fP
376 is a pure packet filter when using the default `filter' table, with
377 optional extension modules.  This should simplify much of the previous
378 confusion over the combination of IP masquerading and packet filtering
379 seen previously.  So the following options are handled differently:
381  -j MASQ
382  -M -S
383  -M -L
385 There are several other changes in iptables.
386 .SH SEE ALSO
387 .BR iptables-save (8),
388 .BR iptables-restore (8),
389 .BR ip6tables (8),
390 .BR ip6tables-save (8),
391 .BR ip6tables-restore (8),
392 .BR libipq (3).
394 The packet-filtering-HOWTO details iptables usage for
395 packet filtering, the NAT-HOWTO details NAT,
396 the netfilter-extensions-HOWTO details the extensions that are
397 not in the standard distribution,
398 and the netfilter-hacking-HOWTO details the netfilter internals.
401 .BR "http://www.netfilter.org/" .
402 .SH AUTHORS
403 Rusty Russell originally wrote iptables, in early consultation with Michael
404 Neuling.
406 Marc Boucher made Rusty abandon ipnatctl by lobbying for a generic packet
407 selection framework in iptables, then wrote the mangle table, the owner match,
408 the mark stuff, and ran around doing cool stuff everywhere.
410 James Morris wrote the TOS target, and tos match.
412 Jozsef Kadlecsik wrote the REJECT target.
414 Harald Welte wrote the ULOG and NFQUEUE target, the new libiptc, as well as the TTL, DSCP, ECN matches and targets.
416 The Netfilter Core Team is: Marc Boucher, Martin Josefsson, Yasuyuki Kozakai,
417 Jozsef Kadlecsik, Patrick McHardy, James Morris, Pablo Neira Ayuso,
418 Harald Welte and Rusty Russell.
420 Man page originally written by Herve Eychenne <rv@wallfire.org>.
421 .\" .. and did I mention that we are incredibly cool people?
422 .\" .. sexy, too ..
423 .\" .. witty, charming, powerful ..
424 .\" .. and most of all, modest ..