blob: 6007dbcce6b832ae19b6ae88c2786c99dbc5e860 [file] [log] [blame]
Hervé Eychenne9e518062002-03-14 09:25:40 +00001.TH IPTABLES 8 "Mar 09, 2002" "" ""
Marc Bouchere6869a82000-03-20 06:03:29 +00002.\"
Hervé Eychenne9e518062002-03-14 09:25:40 +00003.\" Man page written by Herve Eychenne <rv@wallfire.org> (May 1999)
4.\" It is based on ipchains page.
Hervé Eychennecea2ca32002-05-27 11:16:09 +00005.\" TODO: add a word for protocol helpers (FTP, IRC, SNMP-ALG)
Marc Bouchere6869a82000-03-20 06:03:29 +00006.\"
7.\" ipchains page by Paul ``Rusty'' Russell March 1997
Hervé Eychenne9e518062002-03-14 09:25:40 +00008.\" Based on the original ipfwadm man page by Jos Vos <jos@xos.nl>
Marc Bouchere6869a82000-03-20 06:03:29 +00009.\"
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
Hervé Eychennecea2ca32002-05-27 11:16:09 +000026iptables \- administration tool for IPv4 packet filtering and NAT
Marc Bouchere6869a82000-03-20 06:03:29 +000027.SH SYNOPSIS
28.BR "iptables -[ADC] " "chain rule-specification [options]"
29.br
Hervé Eychenne9e518062002-03-14 09:25:40 +000030.BR "iptables -I " "chain [rulenum] rule-specification [options]"
31.br
32.BR "iptables -R " "chain rulenum rule-specification [options]"
Marc Bouchere6869a82000-03-20 06:03:29 +000033.br
34.BR "iptables -D " "chain rulenum [options]"
35.br
36.BR "iptables -[LFZ] " "[chain] [options]"
37.br
Hervé Eychenne9e518062002-03-14 09:25:40 +000038.BR "iptables -N " "chain"
39.br
40.BR "iptables -X " "[chain]"
Marc Bouchere6869a82000-03-20 06:03:29 +000041.br
42.BR "iptables -P " "chain target [options]"
43.br
44.BR "iptables -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
Harald Welte0112abb2001-02-19 21:48:13 +000048filter 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.
Marc Bouchere6869a82000-03-20 06:03:29 +000051
Harald Welte0112abb2001-02-19 21:48:13 +000052Each 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
Marc Bouchere6869a82000-03-20 06:03:29 +000054a `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
Harald Welte0112abb2001-02-19 21:48:13 +000061target, which can be the name of a user-defined chain or one of the
Marc Bouchere6869a82000-03-20 06:03:29 +000062special 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
Rusty Russell363112d2000-08-11 13:49:26 +000074means to pass the packet to userspace (if supported by the kernel).
Marc Bouchere6869a82000-03-20 06:03:29 +000075.I RETURN
Harald Welte0112abb2001-02-19 21:48:13 +000076means 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
Marc Bouchere6869a82000-03-20 06:03:29 +000078or 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
Rusty Russell363112d2000-08-11 13:49:26 +000083There are current three independent tables (which tables are present
84at any time depends on the kernel configuration options and which
85modules are present).
Marc Bouchere6869a82000-03-20 06:03:29 +000086.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +000087.BI "-t, --table " "table"
Marc Bouchere6869a82000-03-20 06:03:29 +000088This 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:
Harald Welte87d4be42001-07-05 06:26:37 +000094.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +000095.B "filter"
Hervé Eychennecea2ca32002-05-27 11:16:09 +000096This is the default table. It contains the built-in chains
97.B INPUT
98(for packets coming into the box itself),
99.B FORWARD
100(for packets being routed through the box), and
101.B OUTPUT
102(for locally-generated packets).
Harald Welte87d4be42001-07-05 06:26:37 +0000103.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000104.B "nat"
Harald Welte0112abb2001-02-19 21:48:13 +0000105This table is consulted when a packet that creates a new
Hervé Eychennecea2ca32002-05-27 11:16:09 +0000106connection is encountered. It consists of three built-ins:
107.B PREROUTING
108(for altering packets as soon as they come in),
109.B OUTPUT
110(for altering locally-generated packets before routing), and
111.B POSTROUTING
112(for altering packets as they are about to go out).
Harald Welte87d4be42001-07-05 06:26:37 +0000113.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000114.B "mangle"
115This table is used for specialized packet alteration. Until kernel
Hervé Eychennecea2ca32002-05-27 11:16:09 +00001162.4.17 it had two built-in chains:
117.B PREROUTING
118(for altering incoming packets before routing) and
119.B OUTPUT
120(for altering locally-generated packets before routing).
121Since kernel 2.4.18, three other built-in chains are also supported:
122.B INPUT
123(for packets coming into the box itself),
124.B FORWARD
125(for altering packets being routed through the box), and
126.B POSTROUTING
127(for altering packets as they are about to go out).
Marc Bouchere6869a82000-03-20 06:03:29 +0000128.SH OPTIONS
129The options that are recognized by
130.B iptables
131can be divided into several different groups.
132.SS COMMANDS
Harald Welte0112abb2001-02-19 21:48:13 +0000133These options specify the specific action to perform. Only one of them
134can be specified on the command line unless otherwise specified
Marc Bouchere6869a82000-03-20 06:03:29 +0000135below. For all the long versions of the command and option names, you
Harald Welte0112abb2001-02-19 21:48:13 +0000136need to use only enough letters to ensure that
Marc Bouchere6869a82000-03-20 06:03:29 +0000137.B iptables
138can differentiate it from all other options.
139.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000140.BI "-A, --append " "chain rule-specification"
Marc Bouchere6869a82000-03-20 06:03:29 +0000141Append one or more rules to the end of the selected chain.
142When the source and/or destination names resolve to more than one
143address, a rule will be added for each possible address combination.
144.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000145.BI "-D, --delete " "chain rule-specification"
146.ns
147.TP
148.BI "-D, --delete " "chain rulenum"
Marc Bouchere6869a82000-03-20 06:03:29 +0000149Delete one or more rules from the selected chain. There are two
150versions of this command: the rule can be specified as a number in the
151chain (starting at 1 for the first rule) or a rule to match.
152.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000153.BR "-I, --insert " "\fIchain\fP [\fIrulenum\fP] \fIrule-specification\fP"
Marc Bouchere6869a82000-03-20 06:03:29 +0000154Insert one or more rules in the selected chain as the given rule
155number. So, if the rule number is 1, the rule or rules are inserted
156at the head of the chain. This is also the default if no rule number
157is specified.
158.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000159.BI "-R, --replace " "chain rulenum rule-specification"
160Replace a rule in the selected chain. If the source and/or
161destination names resolve to multiple addresses, the command will
162fail. Rules are numbered starting at 1.
163.TP
164.BR "-L, --list " "[\fIchain\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000165List all rules in the selected chain. If no chain is selected, all
Hervé Eychenne9e518062002-03-14 09:25:40 +0000166chains are listed. As every other iptables command, it applies to the
167specified table (filter is the default), so NAT rules get listed by
168.br
169 iptables -t nat -n -L
170.br
171Please note that it is often used with the
172.B -n
173option, in order to avoid long reverse DNS lookups.
174It is legal to specify the
Marc Bouchere6869a82000-03-20 06:03:29 +0000175.B -Z
176(zero) option as well, in which case the chain(s) will be atomically
Harald Welte0112abb2001-02-19 21:48:13 +0000177listed and zeroed. The exact output is affected by the other
Marc Bouchere6869a82000-03-20 06:03:29 +0000178arguments given.
179.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000180.BR "-F, --flush " "[\fIchain\fP]"
181Flush the selected chain (all the chains in the table if none is given).
182This is equivalent to deleting all the rules one by one.
Marc Bouchere6869a82000-03-20 06:03:29 +0000183.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000184.BR "-Z, --zero " "[\fIchain\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000185Zero the packet and byte counters in all chains. It is legal to
186specify the
187.B "-L, --list"
188(list) option as well, to see the counters immediately before they are
Harald Welte0112abb2001-02-19 21:48:13 +0000189cleared. (See above.)
Marc Bouchere6869a82000-03-20 06:03:29 +0000190.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000191.BI "-N, --new-chain " "chain"
Harald Welte0112abb2001-02-19 21:48:13 +0000192Create a new user-defined chain by the given name. There must be no
Marc Bouchere6869a82000-03-20 06:03:29 +0000193target of that name already.
194.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000195.BR "-X, --delete-chain " "[\fIchain\fP]"
196Delete the optional user-defined chain specified. There must be no references
Harald Welte0112abb2001-02-19 21:48:13 +0000197to the chain. If there are, you must delete or replace the referring
198rules before the chain can be deleted. If no argument is given, it
Rusty Russell363112d2000-08-11 13:49:26 +0000199will attempt to delete every non-builtin chain in the table.
Marc Bouchere6869a82000-03-20 06:03:29 +0000200.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000201.BI "-P, --policy " "chain target"
Marc Bouchere6869a82000-03-20 06:03:29 +0000202Set the policy for the chain to the given target. See the section
Rusty Russell363112d2000-08-11 13:49:26 +0000203.B TARGETS
Hervé Eychenne9e518062002-03-14 09:25:40 +0000204for the legal targets. Only built-in (non-user-defined) chains can have
205policies, and neither built-in nor user-defined chains can be policy
206targets.
Marc Bouchere6869a82000-03-20 06:03:29 +0000207.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000208.BI "-E, --rename-chain " "old-chain new-chain"
Harald Welte0112abb2001-02-19 21:48:13 +0000209Rename the user specified chain to the user supplied name. This is
Marc Bouchere6869a82000-03-20 06:03:29 +0000210cosmetic, and has no effect on the structure of the table.
Marc Bouchere6869a82000-03-20 06:03:29 +0000211.TP
212.B -h
213Help.
214Give a (currently very brief) description of the command syntax.
215.SS PARAMETERS
216The following parameters make up a rule specification (as used in the
Harald Welte0112abb2001-02-19 21:48:13 +0000217add, delete, insert, replace and append commands).
Marc Bouchere6869a82000-03-20 06:03:29 +0000218.TP
Rusty Russell2e0a3212000-04-19 11:23:18 +0000219.BR "-p, --protocol " "[!] \fIprotocol\fP"
Marc Bouchere6869a82000-03-20 06:03:29 +0000220The protocol of the rule or of the packet to check.
221The specified protocol can be one of
222.IR tcp ,
223.IR udp ,
224.IR icmp ,
225or
226.IR all ,
227or it can be a numeric value, representing one of these protocols or a
Rusty Russell363112d2000-08-11 13:49:26 +0000228different one. A protocol name from /etc/protocols is also allowed.
Marc Bouchere6869a82000-03-20 06:03:29 +0000229A "!" argument before the protocol inverts the
230test. The number zero is equivalent to
231.IR all .
232Protocol
233.I all
234will match with all protocols and is taken as default when this
235option is omitted.
Marc Bouchere6869a82000-03-20 06:03:29 +0000236.TP
237.BR "-s, --source " "[!] \fIaddress\fP[/\fImask\fP]"
238Source specification.
239.I Address
Hervé Eychenne9e518062002-03-14 09:25:40 +0000240can be either a network name, a hostname (please note that specifying
241any name to be resolved with a remote query such as DNS is a really bad idea),
242a network IP address (with /mask), or a plain IP address.
Marc Bouchere6869a82000-03-20 06:03:29 +0000243The
244.I mask
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
248.I 24
249is equivalent to
250.IR 255.255.255.0 .
251A "!" argument before the address specification inverts the sense of
252the address. The flag
253.B --src
Hervé Eychenne9e518062002-03-14 09:25:40 +0000254is an alias for this option.
Marc Bouchere6869a82000-03-20 06:03:29 +0000255.TP
256.BR "-d, --destination " "[!] \fIaddress\fP[/\fImask\fP]"
257Destination specification.
258See the description of the
259.B -s
260(source) flag for a detailed description of the syntax. The flag
261.B --dst
262is an alias for this option.
263.TP
264.BI "-j, --jump " "target"
Harald Welte0112abb2001-02-19 21:48:13 +0000265This specifies the target of the rule; i.e., what to do if the packet
266matches it. The target can be a user-defined chain (other than the
267one this rule is in), one of the special builtin targets which decide
268the fate of the packet immediately, or an extension (see
Marc Bouchere6869a82000-03-20 06:03:29 +0000269.B EXTENSIONS
270below). If this
271option is omitted in a rule, then matching the rule will have no
272effect on the packet's fate, but the counters on the rule will be
273incremented.
274.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000275.BR "-i, --in-interface " "[!] \fIname\fP"
276Name of an interface via which a packet is going to be received (only for
Marc Bouchere6869a82000-03-20 06:03:29 +0000277packets entering the
278.BR INPUT ,
279.B FORWARD
280and
281.B PREROUTING
282chains). When the "!" argument is used before the interface name, the
283sense is inverted. If the interface name ends in a "+", then any
284interface which begins with this name will match. If this option is
Hervé Eychenne9e518062002-03-14 09:25:40 +0000285omitted, any interface name will match.
Marc Bouchere6869a82000-03-20 06:03:29 +0000286.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000287.BR "-o, --out-interface " "[!] \fIname\fP"
288Name of an interface via which a packet is going to be sent (for packets
289entering the
Marc Bouchere6869a82000-03-20 06:03:29 +0000290.BR FORWARD ,
291.B OUTPUT
292and
293.B POSTROUTING
Hervé Eychenne9e518062002-03-14 09:25:40 +0000294chains). When the "!" argument is used before the interface name, the
295sense is inverted. If the interface name ends in a "+", then any
Marc Bouchere6869a82000-03-20 06:03:29 +0000296interface which begins with this name will match. If this option is
Hervé Eychenne9e518062002-03-14 09:25:40 +0000297omitted, any interface name will match.
Marc Bouchere6869a82000-03-20 06:03:29 +0000298.TP
299.B "[!] " "-f, --fragment"
300This means that the rule only refers to second and further fragments
301of fragmented packets. Since there is no way to tell the source or
302destination ports of such a packet (or ICMP type), such a packet will
303not match any rules which specify them. When the "!" argument
Rusty Russell363112d2000-08-11 13:49:26 +0000304precedes the "-f" flag, the rule will only match head fragments, or
305unfragmented packets.
Harald Welteccd49e52001-01-23 22:54:34 +0000306.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000307.BI "-c, --set-counters " "PKTS BYTES"
Harald Welteccd49e52001-01-23 22:54:34 +0000308This enables the administrater to initialize the packet and byte
309counters of a rule (during
310.B INSERT,
311.B APPEND,
312.B REPLACE
Hervé Eychenne9e518062002-03-14 09:25:40 +0000313operations).
Marc Bouchere6869a82000-03-20 06:03:29 +0000314.SS "OTHER OPTIONS"
315The following additional options can be specified:
316.TP
317.B "-v, --verbose"
318Verbose output. This option makes the list command show the interface
319address, the rule options (if any), and the TOS masks. The packet and
320byte counters are also listed, with the suffix 'K', 'M' or 'G' for
3211000, 1,000,000 and 1,000,000,000 multipliers respectively (but see
322the
323.B -x
324flag to change this).
325For appending, insertion, deletion and replacement, this causes
326detailed information on the rule or rules to be printed.
327.TP
328.B "-n, --numeric"
329Numeric output.
330IP addresses and port numbers will be printed in numeric format.
331By default, the program will try to display them as host names,
332network names, or services (whenever applicable).
333.TP
334.B "-x, --exact"
335Expand numbers.
336Display the exact value of the packet and byte counters,
337instead of only the rounded number in K's (multiples of 1000)
338M's (multiples of 1000K) or G's (multiples of 1000M). This option is
Marc Boucherf127a192000-03-20 08:32:15 +0000339only relevant for the
Marc Bouchere6869a82000-03-20 06:03:29 +0000340.B -L
341command.
342.TP
343.B "--line-numbers"
344When listing rules, add line numbers to the beginning of each rule,
345corresponding to that rule's position in the chain.
Chapman Brad45493a82001-02-23 09:08:13 +0000346.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000347.B "--modprobe=command"
Chapman Brad45493a82001-02-23 09:08:13 +0000348When adding or inserting rules into a chain, use
349.B command
350to load any necessary modules (targets, match extensions, etc).
Marc Bouchere6869a82000-03-20 06:03:29 +0000351.SH MATCH EXTENSIONS
Rusty Russell363112d2000-08-11 13:49:26 +0000352iptables can use extended packet matching modules. These are loaded
353in two ways: implicitly, when
354.B -p
355or
356.B --protocol
357is specified, or with the
358.B -m
359or
360.B --match
361options, followed by the matching module name; after these, various
362extra command line options become available, depending on the specific
Hervé Eychenne9e518062002-03-14 09:25:40 +0000363module. You can specify multiple extended match modules in one line,
364and you can use the
Rusty Russell363112d2000-08-11 13:49:26 +0000365.B -h
366or
367.B --help
368options after the module has been specified to receive help specific
369to that module.
370
371The following are included in the base package, and most of these can
372be preceded by a
Marc Bouchere6869a82000-03-20 06:03:29 +0000373.B !
374to invert the sense of the match.
375.SS tcp
Rusty Russell363112d2000-08-11 13:49:26 +0000376These extensions are loaded if `--protocol tcp' is specified. It
377provides the following options:
Marc Bouchere6869a82000-03-20 06:03:29 +0000378.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000379.BR "--source-port " "[!] \fIport\fP[:\fIport\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000380Source port or port range specification. This can either be a service
381name or a port number. An inclusive range can also be specified,
382using the format
James Morris59e90fd2000-06-23 16:44:47 +0000383.IR port : port .
Marc Bouchere6869a82000-03-20 06:03:29 +0000384If the first port is omitted, "0" is assumed; if the last is omitted,
385"65535" is assumed.
386If the second port greater then the first they will be swapped.
387The flag
388.B --sport
Hervé Eychenne9e518062002-03-14 09:25:40 +0000389is a convenient alias for this option.
Marc Bouchere6869a82000-03-20 06:03:29 +0000390.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000391.BR "--destination-port " "[!] \fIport\fP[:\fIport\fP]"
392Destination port or port range specification. The flag
Marc Bouchere6869a82000-03-20 06:03:29 +0000393.B --dport
Hervé Eychenne9e518062002-03-14 09:25:40 +0000394is a convenient alias for this option.
Marc Bouchere6869a82000-03-20 06:03:29 +0000395.TP
396.BR "--tcp-flags " "[!] \fImask\fP \fIcomp\fP"
397Match when the TCP flags are as specified. The first argument is the
398flags which we should examine, written as a comma-separated list, and
399the second argument is a comma-separated list of flags which must be
400set. Flags are:
401.BR "SYN ACK FIN RST URG PSH ALL NONE" .
402Hence the command
403.br
Marc Boucherf127a192000-03-20 08:32:15 +0000404 iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST SYN
Marc Bouchere6869a82000-03-20 06:03:29 +0000405.br
406will only match packets with the SYN flag set, and the ACK, FIN and
407RST flags unset.
408.TP
409.B "[!] --syn"
410Only match TCP packets with the SYN bit set and the ACK and FIN bits
411cleared. Such packets are used to request TCP connection initiation;
412for example, blocking such packets coming in an interface will prevent
413incoming TCP connections, but outgoing TCP connections will be
414unaffected.
415It is equivalent to \fB--tcp-flags SYN,RST,ACK SYN\fP.
416If the "!" flag precedes the "--syn", the sense of the
417option is inverted.
418.TP
419.BR "--tcp-option " "[!] \fInumber\fP"
420Match if TCP option set.
Hervé Eychenne9e518062002-03-14 09:25:40 +0000421.TP
422.BR "--mss " "\fIvalue\fP[:\fIvalue\fP]"
423Match TCP SYN or SYN/ACK packets with the specified MSS value (or range),
424which control the maximum packet size for that connection.
Marc Bouchere6869a82000-03-20 06:03:29 +0000425.SS udp
Rusty Russell363112d2000-08-11 13:49:26 +0000426These extensions are loaded if `--protocol udp' is specified. It
427provides the following options:
Marc Bouchere6869a82000-03-20 06:03:29 +0000428.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000429.BR "--source-port " "[!] \fIport\fP[:\fIport\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000430Source port or port range specification.
431See the description of the
432.B --source-port
433option of the TCP extension for details.
434.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000435.BR "--destination-port " "[!] \fIport\fP[:\fIport\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000436Destination port or port range specification.
437See the description of the
438.B --destination-port
439option of the TCP extension for details.
440.SS icmp
Rusty Russell363112d2000-08-11 13:49:26 +0000441This extension is loaded if `--protocol icmp' is specified. It
442provides the following option:
Marc Bouchere6869a82000-03-20 06:03:29 +0000443.TP
444.BR "--icmp-type " "[!] \fItypename\fP"
445This allows specification of the ICMP type, which can be a numeric
446ICMP type, or one of the ICMP type names shown by the command
447.br
448 iptables -p icmp -h
449.br
450.SS mac
451.TP
452.BR "--mac-source " "[!] \fIaddress\fP"
453Match source MAC address. It must be of the form XX:XX:XX:XX:XX:XX.
Hervé Eychenne9e518062002-03-14 09:25:40 +0000454Note that this only makes sense for packets coming from an Ethernet device
455and entering the
Marc Bouchere6869a82000-03-20 06:03:29 +0000456.BR PREROUTING ,
Rusty Russell4b3c03d2000-07-03 10:11:55 +0000457.B FORWARD
Marc Bouchere6869a82000-03-20 06:03:29 +0000458or
459.B INPUT
Hervé Eychenne9e518062002-03-14 09:25:40 +0000460chains.
Marc Bouchere6869a82000-03-20 06:03:29 +0000461.SS limit
Hervé Eychenne9e518062002-03-14 09:25:40 +0000462This module matches at a limited rate using a token bucket filter.
463A rule using this extension will match until this limit is reached
464(unless the `!' flag is used). It can be used in combination with the
Rusty Russell363112d2000-08-11 13:49:26 +0000465.B LOG
Hervé Eychenne9e518062002-03-14 09:25:40 +0000466target to give limited logging, for example.
Marc Bouchere6869a82000-03-20 06:03:29 +0000467.TP
468.BI "--limit " "rate"
469Maximum average matching rate: specified as a number, with an optional
470`/second', `/minute', `/hour', or `/day' suffix; the default is
4713/hour.
472.TP
473.BI "--limit-burst " "number"
Hervé Eychenne9e518062002-03-14 09:25:40 +0000474Maximum initial number of packets to match: this number gets
Marc Bouchere6869a82000-03-20 06:03:29 +0000475recharged by one every time the limit specified above is not reached,
476up to this number; the default is 5.
477.SS multiport
Hervé Eychenne9e518062002-03-14 09:25:40 +0000478This module matches a set of source or destination ports. Up to 15
479ports can be specified. It can only be used in conjunction with
Marc Bouchere6869a82000-03-20 06:03:29 +0000480.B "-p tcp"
481or
482.BR "-p udp" .
483.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000484.BR "--source-ports " "\fIport\fP[,\fIport\fP[,\fIport\fP...]]"
485Match if the source port is one of the given ports. The flag
486.B --sports
487is a convenient alias for this option.
Marc Bouchere6869a82000-03-20 06:03:29 +0000488.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000489.BR "--destination-ports " "\fIport\fP[,\fIport\fP[,\fIport\fP...]]"
490Match if the destination port is one of the given ports. The flag
491.B --dports
492is a convenient alias for this option.
Marc Bouchere6869a82000-03-20 06:03:29 +0000493.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000494.BR "--ports " "\fIport\fP[,\fIport\fP[,\fIport\fP...]]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000495Match if the both the source and destination ports are equal to each
496other and to one of the given ports.
497.SS mark
498This module matches the netfilter mark field associated with a packet
499(which can be set using the
500.B MARK
501target below).
502.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000503.BR "--mark " "\fIvalue\fP[/\fImask\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000504Matches packets with the given unsigned mark value (if a mask is
Harald Welte87d4be42001-07-05 06:26:37 +0000505specified, this is logically ANDed with the mask before the
Marc Bouchere6869a82000-03-20 06:03:29 +0000506comparison).
507.SS owner
508This module attempts to match various characteristics of the packet
509creator, for locally-generated packets. It is only valid in the
Rusty Russell363112d2000-08-11 13:49:26 +0000510.B OUTPUT
511chain, and even this some packets (such as ICMP ping responses) may
512have no owner, and hence never match.
Marc Bouchere6869a82000-03-20 06:03:29 +0000513.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000514.BI "--uid-owner " "userid"
Marc Bouchere6869a82000-03-20 06:03:29 +0000515Matches if the packet was created by a process with the given
516effective user id.
517.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000518.BI "--gid-owner " "groupid"
Marc Bouchere6869a82000-03-20 06:03:29 +0000519Matches if the packet was created by a process with the given
520effective group id.
521.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000522.BI "--pid-owner " "processid"
Marc Bouchere6869a82000-03-20 06:03:29 +0000523Matches if the packet was created by a process with the given
524process id.
525.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000526.BI "--sid-owner " "sessionid"
Marc Bouchere6869a82000-03-20 06:03:29 +0000527Matches if the packet was created by a process in the given session
528group.
Marc Boucherf5c32d62002-01-19 12:46:04 +0000529.TP
530.BI "--cmd-owner " "name"
531Matches if the packet was created by a process with the given command name.
532(this option is present only if iptables was compiled under a kernel
533supporting this feature)
Marc Bouchere6869a82000-03-20 06:03:29 +0000534.SS state
535This module, when combined with connection tracking, allows access to
536the connection tracking state for this packet.
537.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000538.BI "--state " "state"
Marc Bouchere6869a82000-03-20 06:03:29 +0000539Where state is a comma separated list of the connection states to
540match. Possible states are
541.B INVALID
542meaning that the packet is associated with no known connection,
543.B ESTABLISHED
544meaning that the packet is associated with a connection which has seen
545packets in both directions,
546.B NEW
547meaning that the packet has started a new connection, or otherwise
548associated with a connection which has not seen packets in both
549directions, and
550.B RELATED
551meaning that the packet is starting a new connection, but is
552associated with an existing connection, such as an FTP data transfer,
553or an ICMP error.
Marc Bouchere6869a82000-03-20 06:03:29 +0000554.SS tos
555This module matches the 8 bits of Type of Service field in the IP
556header (ie. including the precedence bits).
557.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000558.BI "--tos " "tos"
Marc Bouchere6869a82000-03-20 06:03:29 +0000559The argument is either a standard name, (use
560.br
561 iptables -m tos -h
562.br
563to see the list), or a numeric value to match.
Hervé Eychenne9e518062002-03-14 09:25:40 +0000564.SS ah
565This module matches the SPIs in AH header of IPSec packets.
566.TP
567.BR "--ahspi " "[!] \fIspi\fP[:\fIspi\fP]"
568.SS esp
569This module matches the SPIs in ESP header of IPSec packets.
570.TP
571.BR "--espspi " "[!] \fIspi\fP[:\fIspi\fP]"
572.SS length
573This module matches the length of a packet against a specific value
574or range of values.
575.TP
576.BR "--length " "\fIlength\fP[:\fIlength\fP]"
577.SS ttl
578This module matches the time to live field in the IP header.
579.TP
580.BI "--ttl " "ttl"
581Matches the given TTL value.
Hervé Eychenne9e518062002-03-14 09:25:40 +0000582.SS unclean
583This module takes no options, but attempts to match packets which seem
584malformed or unusual. This is regarded as experimental.
Marc Bouchere6869a82000-03-20 06:03:29 +0000585.SH TARGET EXTENSIONS
586iptables can use extended target modules: the following are included
587in the standard distribution.
588.SS LOG
589Turn on kernel logging of matching packets. When this option is set
590for a rule, the Linux kernel will print some information on all
Rusty Russell363112d2000-08-11 13:49:26 +0000591matching packets (like most IP header fields) via the kernel log
592(where it can be read with
593.I dmesg
594or
595.IR syslogd (8)).
Hervé Eychenne9e518062002-03-14 09:25:40 +0000596This is a "non-terminating target", i.e. rule traversal continues at
597the next rule. So if you want to LOG the packets you refuse, use two
598separate rules with the same matching criterias, first using target LOG
599then DROP (or REJECT).
Marc Bouchere6869a82000-03-20 06:03:29 +0000600.TP
601.BI "--log-level " "level"
602Level of logging (numeric or see \fIsyslog.conf\fP(5)).
603.TP
604.BI "--log-prefix " "prefix"
Rusty Russellf81427e2000-09-13 04:20:38 +0000605Prefix log messages with the specified prefix; up to 29 letters long,
Marc Bouchere6869a82000-03-20 06:03:29 +0000606and useful for distinguishing messages in the logs.
607.TP
608.B --log-tcp-sequence
609Log TCP sequence numbers. This is a security risk if the log is
610readable by users.
611.TP
612.B --log-tcp-options
613Log options from the TCP packet header.
614.TP
615.B --log-ip-options
616Log options from the IP packet header.
617.SS MARK
618This is used to set the netfilter mark value associated with the
619packet. It is only valid in the
620.B mangle
Hervé Eychenne9e518062002-03-14 09:25:40 +0000621table. It can for example be used in conjunction with iproute2.
Marc Bouchere6869a82000-03-20 06:03:29 +0000622.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000623.BI "--set-mark " "mark"
Marc Bouchere6869a82000-03-20 06:03:29 +0000624.SS REJECT
625This is used to send back an error packet in response to the matched
626packet: otherwise it is equivalent to
Hervé Eychenne9e518062002-03-14 09:25:40 +0000627.B DROP
628so it is a terminating TARGET, ending rule traversal.
Marc Bouchere6869a82000-03-20 06:03:29 +0000629This target is only valid in the
630.BR INPUT ,
631.B FORWARD
632and
633.B OUTPUT
Rusty Russell9cadb432000-05-10 00:18:06 +0000634chains, and user-defined chains which are only called from those
Hervé Eychenne9e518062002-03-14 09:25:40 +0000635chains. The following option controls the nature of the error packet
Marc Bouchere6869a82000-03-20 06:03:29 +0000636returned:
637.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000638.BI "--reject-with " "type"
Marc Bouchere6869a82000-03-20 06:03:29 +0000639The type given can be
640.BR icmp-net-unreachable ,
641.BR icmp-host-unreachable ,
Rusty Russell14f390f2000-07-30 01:10:04 +0000642.BR icmp-port-unreachable ,
643.BR icmp-proto-unreachable ,
Hervé Eychenne9e518062002-03-14 09:25:40 +0000644.BR "icmp-net-prohibited or"
Rusty Russell14f390f2000-07-30 01:10:04 +0000645.BR icmp-host-prohibited ,
Hervé Eychenne9e518062002-03-14 09:25:40 +0000646which return the appropriate ICMP error message (\fBport-unreachable\fP is
647the default). The option
Rusty Russell14f390f2000-07-30 01:10:04 +0000648.B tcp-reset
Rusty Russell363112d2000-08-11 13:49:26 +0000649can be used on rules which only match the TCP protocol: this causes a
650TCP RST packet to be sent back. This is mainly useful for blocking
651.I ident
Hervé Eychenne9e518062002-03-14 09:25:40 +0000652(113/tcp) probes which frequently occur when sending mail to broken mail
653hosts (which won't accept your mail otherwise).
Marc Bouchere6869a82000-03-20 06:03:29 +0000654.SS TOS
655This is used to set the 8-bit Type of Service field in the IP header.
656It is only valid in the
657.B mangle
658table.
659.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000660.BI "--set-tos " "tos"
Marc Bouchere6869a82000-03-20 06:03:29 +0000661You can use a numeric TOS values, or use
662.br
663 iptables -j TOS -h
664.br
665to see the list of valid TOS names.
666.SS MIRROR
667This is an experimental demonstration target which inverts the source
668and destination fields in the IP header and retransmits the packet.
669It is only valid in the
670.BR INPUT ,
671.B FORWARD
672and
Rusty Russell363112d2000-08-11 13:49:26 +0000673.B PREROUTING
674chains, and user-defined chains which are only called from those
675chains. Note that the outgoing packets are
676.B NOT
677seen by any packet filtering chains, connection tracking or NAT, to
678avoid loops and other problems.
Marc Bouchere6869a82000-03-20 06:03:29 +0000679.SS SNAT
680This target is only valid in the
681.B nat
682table, in the
683.B POSTROUTING
684chain. It specifies that the source address of the packet should be
685modified (and all future packets in this connection will also be
686mangled), and rules should cease being examined. It takes one option:
687.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000688.BR "--to-source " "\fIipaddr\fP[-\fIipaddr\fP][:\fIport\fP-\fIport\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000689which can specify a single new source IP address, an inclusive range
690of IP addresses, and optionally, a port range (which is only valid if
691the rule also specifies
692.B "-p tcp"
693or
694.BR "-p udp" ).
695If no port range is specified, then source ports below 512 will be
Harald Welte0112abb2001-02-19 21:48:13 +0000696mapped to other ports below 512: those between 512 and 1023 inclusive
697will be mapped to ports below 1024, and other ports will be mapped to
6981024 or above. Where possible, no port alteration will occur.
Marc Bouchere6869a82000-03-20 06:03:29 +0000699.SS DNAT
700This target is only valid in the
701.B nat
702table, in the
703.B PREROUTING
704and
705.B OUTPUT
Rusty Russell9cadb432000-05-10 00:18:06 +0000706chains, and user-defined chains which are only called from those
Marc Bouchere6869a82000-03-20 06:03:29 +0000707chains. It specifies that the destination address of the packet
708should be modified (and all future packets in this connection will
709also be mangled), and rules should cease being examined. It takes one
710option:
711.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000712.BR "--to-destination " "\fIipaddr\fP[-\fIipaddr\fP][:\fIport\fP-\fIport\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000713which can specify a single new destination IP address, an inclusive
714range of IP addresses, and optionally, a port range (which is only
715valid if the rule also specifies
716.B "-p tcp"
717or
718.BR "-p udp" ).
719If no port range is specified, then the destination port will never be
720modified.
721.SS MASQUERADE
722This target is only valid in the
723.B nat
724table, in the
725.B POSTROUTING
726chain. It should only be used with dynamically assigned IP (dialup)
727connections: if you have a static IP address, you should use the SNAT
728target. Masquerading is equivalent to specifying a mapping to the IP
729address of the interface the packet is going out, but also has the
730effect that connections are
731.I forgotten
Marc Boucherf127a192000-03-20 08:32:15 +0000732when the interface goes down. This is the correct behavior when the
Marc Bouchere6869a82000-03-20 06:03:29 +0000733next dialup is unlikely to have the same interface address (and hence
734any established connections are lost anyway). It takes one option:
735.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000736.BR "--to-ports " "\fIport\fP[-\fIport\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000737This specifies a range of source ports to use, overriding the default
738.B SNAT
Hervé Eychenne9e518062002-03-14 09:25:40 +0000739source port-selection heuristics (see above). This is only valid
Marc Bouchere6869a82000-03-20 06:03:29 +0000740if the rule also specifies
741.B "-p tcp"
742or
Hervé Eychenne9e518062002-03-14 09:25:40 +0000743.BR "-p udp" .
Marc Bouchere6869a82000-03-20 06:03:29 +0000744.SS REDIRECT
745This target is only valid in the
746.B nat
747table, in the
748.B PREROUTING
749and
750.B OUTPUT
Rusty Russell9cadb432000-05-10 00:18:06 +0000751chains, and user-defined chains which are only called from those
Marc Bouchere6869a82000-03-20 06:03:29 +0000752chains. It alters the destination IP address to send the packet to
753the machine itself (locally-generated packets are mapped to the
Rusty Russell9cadb432000-05-10 00:18:06 +0000754127.0.0.1 address). It takes one option:
Marc Bouchere6869a82000-03-20 06:03:29 +0000755.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000756.BR "--to-ports " "\fIport\fP[-\fIport\fP]"
757This specifies a destination port or range of ports to use: without
758this, the destination port is never altered. This is only valid
Marc Bouchere6869a82000-03-20 06:03:29 +0000759if the rule also specifies
760.B "-p tcp"
761or
Hervé Eychenne9e518062002-03-14 09:25:40 +0000762.BR "-p udp" .
763.SS ULOG
764This target provides userspace logging of matching packets. When this
765target is set for a rule, the Linux kernel will multicast this packet
766through a
767.IR netlink
768socket. One or more userspace processes may then subscribe to various
769multicast groups and receive the packets.
Hervé Eychennecea2ca32002-05-27 11:16:09 +0000770Like LOG, this is a "non-terminating target", i.e. rule traversal
771continues at the next rule.
Hervé Eychenne9e518062002-03-14 09:25:40 +0000772.TP
773.BI "--ulog-nlgroup " "nlgroup"
774This specifies the netlink group (1-32) to which the packet is sent.
775Default value is 1.
776.TP
777.BI "--ulog-prefix " "prefix"
778Prefix log messages with the specified prefix; up to 32 characters
Hervé Eychennecea2ca32002-05-27 11:16:09 +0000779long, and useful for distinguishing messages in the logs.
Hervé Eychenne9e518062002-03-14 09:25:40 +0000780.TP
781.BI "--ulog-cprange " "size"
Hervé Eychennecea2ca32002-05-27 11:16:09 +0000782Number of bytes to be copied to userspace. A value of 0 always copies
783the entire packet, regardless of its size. Default is 0.
Hervé Eychenne9e518062002-03-14 09:25:40 +0000784.TP
785.BI "--ulog-qthreshold " "size"
Hervé Eychennecea2ca32002-05-27 11:16:09 +0000786Number of packet to queue inside kernel. Setting this value to, e.g. 10
Hervé Eychenne9e518062002-03-14 09:25:40 +0000787accumulates ten packets inside the kernel and transmits them as one
788netlink multipart message to userspace. Default is 1 (for backwards
789compatibility).
790.SS TCPMSS
791This target allows to alter the MSS value of TCP SYN packets, to control
792the maximum size for that connection (usually limiting it to your
Hervé Eychennecea2ca32002-05-27 11:16:09 +0000793outgoing interface's MTU minus 40). Of course, it can only be used
Hervé Eychenne9e518062002-03-14 09:25:40 +0000794in conjunction with
795.BR "-p tcp" .
796.br
797This target is used to overcome criminally braindead ISPs or servers
798which block ICMP Fragmentation Needed packets. The symptoms of this
799problem are that everything works fine from your Linux
800firewall/router, but machines behind it can never exchange large
801packets:
802.br
803 1) Web browsers connect, then hang with no data received.
804.br
805 2) Small mail works fine, but large emails hang.
806.br
807 3) ssh works fine, but scp hangs after initial handshaking.
808.br
809Workaround: activate this option and add a rule to your firewall
810configuration like:
811.br
812 iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN \\
813.br
814 -j TCPMSS --clamp-mss-to-pmtu
815.TP
816.BI "--set-mss " "value"
817Explicitly set MSS option to specified value.
818.TP
819.B "--clamp-mss-to-pmtu"
820Automatically clamp MSS value to (path_MTU - 40).
821.TP
822These options are mutually exclusive.
Rusty Russell86573e52000-10-11 06:01:13 +0000823.SH DIAGNOSTICS
824Various error messages are printed to standard error. The exit code
825is 0 for correct functioning. Errors which appear to be caused by
826invalid or abused command line parameters cause an exit code of 2, and
827other errors cause an exit code of 1.
Marc Bouchere6869a82000-03-20 06:03:29 +0000828.SH BUGS
Hervé Eychennecea2ca32002-05-27 11:16:09 +0000829Bugs? What's this? ;-)
Marc Bouchere6869a82000-03-20 06:03:29 +0000830.SH COMPATIBILITY WITH IPCHAINS
831This
832.B iptables
833is very similar to ipchains by Rusty Russell. The main difference is
834that the chains
835.B INPUT
836and
837.B OUTPUT
838are only traversed for packets coming into the local host and
839originating from the local host respectively. Hence every packet only
840passes through one of the three chains; previously a forwarded packet
841would pass through all three.
842.PP
843The other main difference is that
844.B -i
845refers to the input interface;
846.B -o
847refers to the output interface, and both are available for packets
848entering the
849.B FORWARD
850chain.
851.PP The various forms of NAT have been separated out;
852.B iptables
853is a pure packet filter when using the default `filter' table, with
854optional extension modules. This should simplify much of the previous
855confusion over the combination of IP masquerading and packet filtering
856seen previously. So the following options are handled differently:
857.br
858 -j MASQ
859.br
860 -M -S
861.br
862 -M -L
863.br
864There are several other changes in iptables.
865.SH SEE ALSO
Hervé Eychennecea2ca32002-05-27 11:16:09 +0000866.BR iptables-save (8),
867.BR iptables-restore (8),
868.BR ip6tables (8),
869.BR ip6tables-save (8),
870.BR ip6tables-restore(8).
871.P
872The packet-filtering-HOWTO details iptables usage for
873packet filtering, the NAT-HOWTO details NAT,
874the netfilter-extensions-HOWTO details the extensions that are
875not in the standard distribution,
876and the netfilter-hacking-HOWTO details the netfilter internals.
Hervé Eychenne9e518062002-03-14 09:25:40 +0000877.br
878See
879.BR "http://www.netfilter.org/" .
Marc Boucherf127a192000-03-20 08:32:15 +0000880.SH AUTHORS
Marc Bouchere6869a82000-03-20 06:03:29 +0000881Rusty Russell wrote iptables, in early consultation with Michael
882Neuling.
883.PP
Marc Boucherf127a192000-03-20 08:32:15 +0000884Marc Boucher made Rusty abandon ipnatctl by lobbying for a generic packet
885selection framework in iptables, then wrote the mangle table, the owner match,
886the mark stuff, and ran around doing cool stuff everywhere.
Marc Bouchere6869a82000-03-20 06:03:29 +0000887.PP
888James Morris wrote the TOS target, and tos match.
889.PP
890Jozsef Kadlecsik wrote the REJECT target.
891.PP
Rusty Russell86573e52000-10-11 06:01:13 +0000892Harald Welte wrote the ULOG target, TTL match+target and libipulog.
Rusty Russell52451822000-08-27 07:47:46 +0000893.PP
James Morrisedfce4e2001-12-07 10:23:22 +0000894The Netfilter Core Team is: Marc Boucher, Jozsef Kadlecsik, James Morris,
895Harald Welte and Rusty Russell.
Hervé Eychenne9e518062002-03-14 09:25:40 +0000896.PP
897Man page written by Herve Eychenne <rv@wallfire.org>.
Hervé Eychennecea2ca32002-05-27 11:16:09 +0000898
Marc Bouchere6869a82000-03-20 06:03:29 +0000899.\" .. and did I mention that we are incredibly cool people?
Rusty Russell363112d2000-08-11 13:49:26 +0000900.\" .. sexy, too ..
Rusty Russell86573e52000-10-11 06:01:13 +0000901.\" .. witty, charming, powerful ..
James Morris060ae4c2000-10-29 01:29:57 +0000902.\" .. and most of all, modest ..