OSDN Git Service

iptables: Update original to 1.4.21
[linuxjm/iptables.git] / original / man8 / iptables.8
1 .TH IPTABLES 8 "" "iptables 1.4.21" "iptables 1.4.21"
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/ip6tables \(em administration tool for IPv4/IPv6 packet filtering and NAT
27 .SH SYNOPSIS
28 \fBiptables\fP [\fB\-t\fP \fItable\fP] {\fB\-A\fP|\fB\-C\fP|\fB\-D\fP}
29 \fIchain\fP \fIrule-specification\fP
30 .P
31 \fBip6tables\fP [\fB\-t\fP \fItable\fP] {\fB\-A\fP|\fB\-C\fP|\fB\-D\fP}
32 \fIchain rule-specification\fP
33 .PP
34 \fBiptables\fP [\fB\-t\fP \fItable\fP] \fB\-I\fP \fIchain\fP [\fIrulenum\fP] \fIrule-specification\fP
35 .PP
36 \fBiptables\fP [\fB\-t\fP \fItable\fP] \fB\-R\fP \fIchain rulenum rule-specification\fP
37 .PP
38 \fBiptables\fP [\fB\-t\fP \fItable\fP] \fB\-D\fP \fIchain rulenum\fP
39 .PP
40 \fBiptables\fP [\fB\-t\fP \fItable\fP] \fB\-S\fP [\fIchain\fP [\fIrulenum\fP]]
41 .PP
42 \fBiptables\fP [\fB\-t\fP \fItable\fP] {\fB\-F\fP|\fB\-L\fP|\fB\-Z\fP} [\fIchain\fP [\fIrulenum\fP]] [\fIoptions...\fP]
43 .PP
44 \fBiptables\fP [\fB\-t\fP \fItable\fP] \fB\-N\fP \fIchain\fP
45 .PP
46 \fBiptables\fP [\fB\-t\fP \fItable\fP] \fB\-X\fP [\fIchain\fP]
47 .PP
48 \fBiptables\fP [\fB\-t\fP \fItable\fP] \fB\-P\fP \fIchain target\fP
49 .PP
50 \fBiptables\fP [\fB\-t\fP \fItable\fP] \fB\-E\fP \fIold-chain-name new-chain-name\fP
51 .PP
52 rule-specification = [\fImatches...\fP] [\fItarget\fP]
53 .PP
54 match = \fB\-m\fP \fImatchname\fP [\fIper-match-options\fP]
55 .PP
56 target = \fB\-j\fP \fItargetname\fP [\fIper\-target\-options\fP]
57 .SH DESCRIPTION
58 \fBIptables\fP and \fBip6tables\fP are used to set up, maintain, and inspect the
59 tables of IPv4 and IPv6 packet
60 filter rules in the Linux kernel.  Several different tables
61 may be defined.  Each table contains a number of built-in
62 chains and may also contain user-defined chains.
63 .PP
64 Each chain is a list of rules which can match a set of packets.  Each
65 rule specifies what to do with a packet that matches.  This is called
66 a `target', which may be a jump to a user-defined chain in the same
67 table.
68 .SH TARGETS
69 A firewall rule specifies criteria for a packet and a target.  If the
70 packet does not match, the next rule in the chain is examined; if
71 it does match, then the next rule is specified by the value of the
72 target, which can be the name of a user-defined chain, one of the targets
73 described in \fBiptables\-extensions\fP(8), or one of the
74 special values \fBACCEPT\fP, \fBDROP\fP or \fBRETURN\fP.
75 .PP
76 \fBACCEPT\fP means to let the packet through.
77 \fBDROP\fP means to drop the packet on the floor.
78 \fBRETURN\fP means stop traversing this chain and resume at the next
79 rule in the
80 previous (calling) chain.  If the end of a built-in chain is reached
81 or a rule in a built-in chain with target \fBRETURN\fP
82 is matched, the target specified by the chain policy determines the
83 fate of the packet.
84 .SH TABLES
85 There are currently five independent tables (which tables are present
86 at any time depends on the kernel configuration options and which
87 modules are present).
88 .TP
89 \fB\-t\fP, \fB\-\-table\fP \fItable\fP
90 This option specifies the packet matching table which the command
91 should operate on.  If the kernel is configured with automatic module
92 loading, an attempt will be made to load the appropriate module for
93 that table if it is not already there.
94
95 The tables are as follows:
96 .RS
97 .TP .4i
98 \fBfilter\fP:
99 This is the default table (if no \-t option is passed). It contains
100 the built-in chains \fBINPUT\fP (for packets destined to local sockets),
101 \fBFORWARD\fP (for packets being routed through the box), and
102 \fBOUTPUT\fP (for locally-generated packets).
103 .TP
104 \fBnat\fP:
105 This table is consulted when a packet that creates a new
106 connection is encountered.  It consists of three built-ins: \fBPREROUTING\fP
107 (for altering packets as soon as they come in), \fBOUTPUT\fP
108 (for altering locally-generated packets before routing), and \fBPOSTROUTING\fP
109 (for altering packets as they are about to go out).
110 IPv6 NAT support is available since kernel 3.7.
111 .TP
112 \fBmangle\fP:
113 This table is used for specialized packet alteration.  Until kernel
114 2.4.17 it had two built-in chains: \fBPREROUTING\fP
115 (for altering incoming packets before routing) and \fBOUTPUT\fP
116 (for altering locally-generated packets before routing).
117 Since kernel 2.4.18, three other built-in chains are also supported:
118 \fBINPUT\fP (for packets coming into the box itself), \fBFORWARD\fP
119 (for altering packets being routed through the box), and \fBPOSTROUTING\fP
120 (for altering packets as they are about to go out).
121 .TP
122 \fBraw\fP:
123 This table is used mainly for configuring exemptions from connection
124 tracking in combination with the NOTRACK target.  It registers at the netfilter
125 hooks with higher priority and is thus called before ip_conntrack, or any other
126 IP tables.  It provides the following built-in chains: \fBPREROUTING\fP
127 (for packets arriving via any network interface) \fBOUTPUT\fP
128 (for packets generated by local processes)
129 .TP
130 \fBsecurity\fP:
131 This table is used for Mandatory Access Control (MAC) networking rules, such
132 as those enabled by the \fBSECMARK\fP and \fBCONNSECMARK\fP targets.
133 Mandatory Access Control is implemented by Linux Security Modules such as
134 SELinux.  The security table is called after the filter table, allowing any
135 Discretionary Access Control (DAC) rules in the filter table to take effect
136 before MAC rules.  This table provides the following built-in chains:
137 \fBINPUT\fP (for packets coming into the box itself),
138 \fBOUTPUT\fP (for altering locally-generated packets before routing), and
139 \fBFORWARD\fP (for altering packets being routed through the box).
140 .RE
141 .SH OPTIONS
142 The options that are recognized by
143 \fBiptables\fP and \fBip6tables\fP can be divided into several different groups.
144 .SS COMMANDS
145 These options specify the desired action to perform. Only one of them
146 can be specified on the command line unless otherwise stated
147 below. For long versions of the command and option names, you
148 need to use only enough letters to ensure that
149 \fBiptables\fP can differentiate it from all other options.
150 .TP
151 \fB\-A\fP, \fB\-\-append\fP \fIchain rule-specification\fP
152 Append one or more rules to the end of the selected chain.
153 When the source and/or destination names resolve to more than one
154 address, a rule will be added for each possible address combination.
155 .TP
156 \fB\-C\fP, \fB\-\-check\fP \fIchain rule-specification\fP
157 Check whether a rule matching the specification does exist in the
158 selected chain. This command uses the same logic as \fB\-D\fP to
159 find a matching entry, but does not alter the existing iptables
160 configuration and uses its exit code to indicate success or failure.
161 .TP
162 \fB\-D\fP, \fB\-\-delete\fP \fIchain rule-specification\fP
163 .ns
164 .TP
165 \fB\-D\fP, \fB\-\-delete\fP \fIchain rulenum\fP
166 Delete one or more rules from the selected chain.  There are two
167 versions of this command: the rule can be specified as a number in the
168 chain (starting at 1 for the first rule) or a rule to match.
169 .TP
170 \fB\-I\fP, \fB\-\-insert\fP \fIchain\fP [\fIrulenum\fP] \fIrule-specification\fP
171 Insert one or more rules in the selected chain as the given rule
172 number.  So, if the rule number is 1, the rule or rules are inserted
173 at the head of the chain.  This is also the default if no rule number
174 is specified.
175 .TP
176 \fB\-R\fP, \fB\-\-replace\fP \fIchain rulenum rule-specification\fP
177 Replace a rule in the selected chain.  If the source and/or
178 destination names resolve to multiple addresses, the command will
179 fail.  Rules are numbered starting at 1.
180 .TP
181 \fB\-L\fP, \fB\-\-list\fP [\fIchain\fP]
182 List all rules in the selected chain.  If no chain is selected, all
183 chains are listed. Like every other iptables command, it applies to the
184 specified table (filter is the default), so NAT rules get listed by
185 .nf
186  iptables \-t nat \-n \-L
187 .fi
188 Please note that it is often used with the \fB\-n\fP
189 option, in order to avoid long reverse DNS lookups.
190 It is legal to specify the \fB\-Z\fP
191 (zero) option as well, in which case the chain(s) will be atomically
192 listed and zeroed.  The exact output is affected by the other
193 arguments given. The exact rules are suppressed until you use
194 .nf
195  iptables \-L \-v
196 .fi
197 .TP
198 \fB\-S\fP, \fB\-\-list\-rules\fP [\fIchain\fP]
199 Print all rules in the selected chain.  If no chain is selected, all
200 chains are printed like iptables-save. Like every other iptables command,
201 it applies to the specified table (filter is the default).
202 .TP
203 \fB\-F\fP, \fB\-\-flush\fP [\fIchain\fP]
204 Flush the selected chain (all the chains in the table if none is given).
205 This is equivalent to deleting all the rules one by one.
206 .TP
207 \fB\-Z\fP, \fB\-\-zero\fP [\fIchain\fP [\fIrulenum\fP]]
208 Zero the packet and byte counters in all chains, or only the given chain,
209 or only the given rule in a chain. It is legal to
210 specify the
211 \fB\-L\fP, \fB\-\-list\fP
212 (list) option as well, to see the counters immediately before they are
213 cleared. (See above.)
214 .TP
215 \fB\-N\fP, \fB\-\-new\-chain\fP \fIchain\fP
216 Create a new user-defined chain by the given name.  There must be no
217 target of that name already.
218 .TP
219 \fB\-X\fP, \fB\-\-delete\-chain\fP [\fIchain\fP]
220 Delete the optional user-defined chain specified.  There must be no references
221 to the chain.  If there are, you must delete or replace the referring rules
222 before the chain can be deleted.  The chain must be empty, i.e. not contain
223 any rules.  If no argument is given, it will attempt to delete every
224 non-builtin chain in the table.
225 .TP
226 \fB\-P\fP, \fB\-\-policy\fP \fIchain target\fP
227 Set the policy for the chain to the given target.  See the section \fBTARGETS\fP
228 for the legal targets.  Only built-in (non-user-defined) chains can have
229 policies, and neither built-in nor user-defined chains can be policy
230 targets.
231 .TP
232 \fB\-E\fP, \fB\-\-rename\-chain\fP \fIold\-chain new\-chain\fP
233 Rename the user specified chain to the user supplied name.  This is
234 cosmetic, and has no effect on the structure of the table.
235 .TP
236 \fB\-h\fP
237 Help.
238 Give a (currently very brief) description of the command syntax.
239 .SS PARAMETERS
240 The following parameters make up a rule specification (as used in the
241 add, delete, insert, replace and append commands).
242 .TP
243 \fB\-4\fP, \fB\-\-ipv4\fP
244 This option has no effect in iptables and iptables-restore.
245 If a rule using the \fB\-4\fP option is inserted with (and only with)
246 ip6tables-restore, it will be silently ignored. Any other uses will throw an
247 error. This option allows to put both IPv4 and IPv6 rules in a single rule file
248 for use with both iptables-restore and ip6tables-restore.
249 .TP
250 \fB\-6\fP, \fB\-\-ipv6\fP
251 If a rule using the \fB\-6\fP option is inserted with (and only with)
252 iptables-restore, it will be silently ignored. Any other uses will throw an
253 error. This option allows to put both IPv4 and IPv6 rules in a single rule file
254 for use with both iptables-restore and ip6tables-restore.
255 This option has no effect in ip6tables and ip6tables-restore.
256 .TP
257 [\fB!\fP] \fB\-p\fP, \fB\-\-protocol\fP \fIprotocol\fP
258 The protocol of the rule or of the packet to check.
259 The specified protocol can be one of \fBtcp\fP, \fBudp\fP, \fBudplite\fP,
260 \fBicmp\fP, \fBicmpv6\fP,\fBesp\fP, \fBah\fP, \fBsctp\fP, \fBmh\fP or the special keyword "\fBall\fP",
261 or it can be a numeric value, representing one of these protocols or a
262 different one.  A protocol name from /etc/protocols is also allowed.
263 A "!" argument before the protocol inverts the
264 test.  The number zero is equivalent to \fBall\fP. "\fBall\fP"
265 will match with all protocols and is taken as default when this
266 option is omitted.
267 Note that, in ip6tables, IPv6 extension headers except \fBesp\fP are not allowed.
268 \fBesp\fP and \fBipv6\-nonext\fP
269 can be used with Kernel version 2.6.11 or later.
270 The number zero is equivalent to \fBall\fP, which means that you cannot
271 test the protocol field for the value 0 directly. To match on a HBH header,
272 even if it were the last, you cannot use \fB\-p 0\fP, but always need
273 \fB\-m hbh\fP.
274 .TP
275 [\fB!\fP] \fB\-s\fP, \fB\-\-source\fP \fIaddress\fP[\fB/\fP\fImask\fP][\fB,\fP\fI...\fP]
276 Source specification. \fIAddress\fP
277 can be either a network name, a hostname, a network IP address (with
278 \fB/\fP\fImask\fP), or a plain IP address. Hostnames will
279 be resolved once only, before the rule is submitted to the kernel.
280 Please note that specifying any name to be resolved with a remote query such as
281 DNS is a really bad idea.
282 The \fImask\fP
283 can be either an ipv4 network mask (for iptables) or a plain number,
284 specifying the number of 1's at the left side of the network mask.
285 Thus, an iptables mask of \fI24\fP is equivalent to \fI255.255.255.0\fP.
286 A "!" argument before the address specification inverts the sense of
287 the address. The flag \fB\-\-src\fP is an alias for this option.
288 Multiple addresses can be specified, but this will \fBexpand to multiple
289 rules\fP (when adding with \-A), or will cause multiple rules to be
290 deleted (with \-D).
291 .TP
292 [\fB!\fP] \fB\-d\fP, \fB\-\-destination\fP \fIaddress\fP[\fB/\fP\fImask\fP][\fB,\fP\fI...\fP]
293 Destination specification. 
294 See the description of the \fB\-s\fP
295 (source) flag for a detailed description of the syntax.  The flag
296 \fB\-\-dst\fP is an alias for this option.
297 .TP
298 \fB\-m\fP, \fB\-\-match\fP \fImatch\fP
299 Specifies a match to use, that is, an extension module that tests for a
300 specific property. The set of matches make up the condition under which a
301 target is invoked. Matches are evaluated first to last as specified on the
302 command line and work in short-circuit fashion, i.e. if one extension yields
303 false, evaluation will stop.
304 .TP
305 \fB\-j\fP, \fB\-\-jump\fP \fItarget\fP
306 This specifies the target of the rule; i.e., what to do if the packet
307 matches it.  The target can be a user-defined chain (other than the
308 one this rule is in), one of the special builtin targets which decide
309 the fate of the packet immediately, or an extension (see \fBEXTENSIONS\fP
310 below).  If this
311 option is omitted in a rule (and \fB\-g\fP
312 is not used), then matching the rule will have no
313 effect on the packet's fate, but the counters on the rule will be
314 incremented.
315 .TP
316 \fB\-g\fP, \fB\-\-goto\fP \fIchain\fP
317 This specifies that the processing should continue in a user
318 specified chain. Unlike the \-\-jump option return will not continue
319 processing in this chain but instead in the chain that called us via
320 \-\-jump.
321 .TP
322 [\fB!\fP] \fB\-i\fP, \fB\-\-in\-interface\fP \fIname\fP
323 Name of an interface via which a packet was received (only for
324 packets entering the \fBINPUT\fP, \fBFORWARD\fP and \fBPREROUTING\fP
325 chains).  When the "!" argument is used before the interface name, the
326 sense is inverted.  If the interface name ends in a "+", then any
327 interface which begins with this name will match.  If this option is
328 omitted, any interface name will match.
329 .TP
330 [\fB!\fP] \fB\-o\fP, \fB\-\-out\-interface\fP \fIname\fP
331 Name of an interface via which a packet is going to be sent (for packets
332 entering the \fBFORWARD\fP, \fBOUTPUT\fP and \fBPOSTROUTING\fP
333 chains).  When the "!" argument is used before the interface name, the
334 sense is inverted.  If the interface name ends in a "+", then any
335 interface which begins with this name will match.  If this option is
336 omitted, any interface name will match.
337 .TP
338 [\fB!\fP] \fB\-f\fP, \fB\-\-fragment\fP
339 This means that the rule only refers to second and further IPv4 fragments
340 of fragmented packets.  Since there is no way to tell the source or
341 destination ports of such a packet (or ICMP type), such a packet will
342 not match any rules which specify them.  When the "!" argument
343 precedes the "\-f" flag, the rule will only match head fragments, or
344 unfragmented packets. This option is IPv4 specific, it is not available
345 in ip6tables.
346 .TP
347 \fB\-c\fP, \fB\-\-set\-counters\fP \fIpackets bytes\fP
348 This enables the administrator to initialize the packet and byte
349 counters of a rule (during \fBINSERT\fP, \fBAPPEND\fP, \fBREPLACE\fP
350 operations).
351 .SS "OTHER OPTIONS"
352 The following additional options can be specified:
353 .TP
354 \fB\-v\fP, \fB\-\-verbose\fP
355 Verbose output.  This option makes the list command show the interface
356 name, the rule options (if any), and the TOS masks.  The packet and
357 byte counters are also listed, with the suffix 'K', 'M' or 'G' for
358 1000, 1,000,000 and 1,000,000,000 multipliers respectively (but see
359 the \fB\-x\fP flag to change this).
360 For appending, insertion, deletion and replacement, this causes
361 detailed information on the rule or rules to be printed. \fB\-v\fP may be
362 specified multiple times to possibly emit more detailed debug statements.
363 .TP
364 \fB\-w\fP, \fB\-\-wait\fP
365 Wait for the xtables lock.
366 To prevent multiple instances of the program from running concurrently,
367 an attempt will be made to obtain an exclusive lock at launch.  By default,
368 the program will exit if the lock cannot be obtained.  This option will
369 make the program wait until the exclusive lock can be obtained.
370 .TP
371 \fB\-n\fP, \fB\-\-numeric\fP
372 Numeric output.
373 IP addresses and port numbers will be printed in numeric format.
374 By default, the program will try to display them as host names,
375 network names, or services (whenever applicable).
376 .TP
377 \fB\-x\fP, \fB\-\-exact\fP
378 Expand numbers.
379 Display the exact value of the packet and byte counters,
380 instead of only the rounded number in K's (multiples of 1000)
381 M's (multiples of 1000K) or G's (multiples of 1000M).  This option is
382 only relevant for the \fB\-L\fP command.
383 .TP
384 \fB\-\-line\-numbers\fP
385 When listing rules, add line numbers to the beginning of each rule,
386 corresponding to that rule's position in the chain.
387 .TP
388 \fB\-\-modprobe=\fP\fIcommand\fP
389 When adding or inserting rules into a chain, use \fIcommand\fP
390 to load any necessary modules (targets, match extensions, etc).
391 .SH MATCH AND TARGET EXTENSIONS
392 .PP
393 iptables can use extended packet matching and target modules.
394 A list of these is available in the \fBiptables\-extensions\fP(8) manpage.
395 .SH DIAGNOSTICS
396 Various error messages are printed to standard error.  The exit code
397 is 0 for correct functioning.  Errors which appear to be caused by
398 invalid or abused command line parameters cause an exit code of 2, and
399 other errors cause an exit code of 1.
400 .SH BUGS
401 Bugs?  What's this? ;-)
402 Well, you might want to have a look at http://bugzilla.netfilter.org/
403 .SH COMPATIBILITY WITH IPCHAINS
404 This \fBiptables\fP
405 is very similar to ipchains by Rusty Russell.  The main difference is
406 that the chains \fBINPUT\fP and \fBOUTPUT\fP
407 are only traversed for packets coming into the local host and
408 originating from the local host respectively.  Hence every packet only
409 passes through one of the three chains (except loopback traffic, which
410 involves both INPUT and OUTPUT chains); previously a forwarded packet
411 would pass through all three.
412 .PP
413 The other main difference is that \fB\-i\fP refers to the input interface;
414 \fB\-o\fP refers to the output interface, and both are available for packets
415 entering the \fBFORWARD\fP chain.
416 .PP
417 The various forms of NAT have been separated out; \fBiptables\fP
418 is a pure packet filter when using the default `filter' table, with
419 optional extension modules.  This should simplify much of the previous
420 confusion over the combination of IP masquerading and packet filtering
421 seen previously.  So the following options are handled differently:
422 .nf
423  \-j MASQ
424  \-M \-S
425  \-M \-L
426 .fi
427 There are several other changes in iptables.
428 .SH SEE ALSO
429 \fBiptables\-apply\fP(8),
430 \fBiptables\-save\fP(8),
431 \fBiptables\-restore\fP(8),
432 \fBiptables\-extensions\fP(8),
433 .PP
434 The packet-filtering-HOWTO details iptables usage for
435 packet filtering, the NAT-HOWTO details NAT,
436 the netfilter-extensions-HOWTO details the extensions that are
437 not in the standard distribution,
438 and the netfilter-hacking-HOWTO details the netfilter internals.
439 .br
440 See
441 .BR "http://www.netfilter.org/" .
442 .SH AUTHORS
443 Rusty Russell originally wrote iptables, in early consultation with Michael
444 Neuling.
445 .PP
446 Marc Boucher made Rusty abandon ipnatctl by lobbying for a generic packet
447 selection framework in iptables, then wrote the mangle table, the owner match,
448 the mark stuff, and ran around doing cool stuff everywhere.
449 .PP
450 James Morris wrote the TOS target, and tos match.
451 .PP
452 Jozsef Kadlecsik wrote the REJECT target.
453 .PP
454 Harald Welte wrote the ULOG and NFQUEUE target, the new libiptc, as well as the TTL, DSCP, ECN matches and targets.
455 .PP
456 The Netfilter Core Team is: Marc Boucher, Martin Josefsson, Yasuyuki Kozakai,
457 Jozsef Kadlecsik, Patrick McHardy, James Morris, Pablo Neira Ayuso,
458 Harald Welte and Rusty Russell.
459 .PP
460 Man page originally written by Herve Eychenne <rv@wallfire.org>.
461 .\" .. and did I mention that we are incredibly cool people?
462 .\" .. sexy, too ..
463 .\" .. witty, charming, powerful ..
464 .\" .. and most of all, modest ..
465 .SH VERSION
466 .PP
467 This manual page applies to iptables/ip6tables 1.4.21.