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