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