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