blob: 870eeb12caa42696c5d40cb21b1ee07a140a32ad [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.
5.\" TODO : add a word for protocol helpers (FTP, IRC, SNMP-ALG)
6.\" add EXTRA EXTENSIONS matches
Marc Bouchere6869a82000-03-20 06:03:29 +00007.\"
8.\" ipchains page by Paul ``Rusty'' Russell March 1997
Hervé Eychenne9e518062002-03-14 09:25:40 +00009.\" Based on the original ipfwadm man page by Jos Vos <jos@xos.nl>
Marc Bouchere6869a82000-03-20 06:03:29 +000010.\"
11.\" This program is free software; you can redistribute it and/or modify
12.\" it under the terms of the GNU General Public License as published by
13.\" the Free Software Foundation; either version 2 of the License, or
14.\" (at your option) any later version.
15.\"
16.\" This program is distributed in the hope that it will be useful,
17.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
18.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19.\" GNU General Public License for more details.
20.\"
21.\" You should have received a copy of the GNU General Public License
22.\" along with this program; if not, write to the Free Software
23.\" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24.\"
25.\"
26.SH NAME
27iptables \- IP packet filter administration
28.SH SYNOPSIS
29.BR "iptables -[ADC] " "chain rule-specification [options]"
30.br
Hervé Eychenne9e518062002-03-14 09:25:40 +000031.BR "iptables -I " "chain [rulenum] rule-specification [options]"
32.br
33.BR "iptables -R " "chain rulenum rule-specification [options]"
Marc Bouchere6869a82000-03-20 06:03:29 +000034.br
35.BR "iptables -D " "chain rulenum [options]"
36.br
37.BR "iptables -[LFZ] " "[chain] [options]"
38.br
Hervé Eychenne9e518062002-03-14 09:25:40 +000039.BR "iptables -N " "chain"
40.br
41.BR "iptables -X " "[chain]"
Marc Bouchere6869a82000-03-20 06:03:29 +000042.br
43.BR "iptables -P " "chain target [options]"
44.br
45.BR "iptables -E " "old-chain-name new-chain-name"
46.SH DESCRIPTION
47.B Iptables
48is used to set up, maintain, and inspect the tables of IP packet
Harald Welte0112abb2001-02-19 21:48:13 +000049filter rules in the Linux kernel. Several different tables
50may be defined. Each table contains a number of built-in
51chains and may also contain user-defined chains.
Marc Bouchere6869a82000-03-20 06:03:29 +000052
Harald Welte0112abb2001-02-19 21:48:13 +000053Each chain is a list of rules which can match a set of packets. Each
54rule specifies what to do with a packet that matches. This is called
Marc Bouchere6869a82000-03-20 06:03:29 +000055a `target', which may be a jump to a user-defined chain in the same
56table.
57
58.SH TARGETS
59A firewall rule specifies criteria for a packet, and a target. If the
60packet does not match, the next rule in the chain is the examined; if
61it does match, then the next rule is specified by the value of the
Harald Welte0112abb2001-02-19 21:48:13 +000062target, which can be the name of a user-defined chain or one of the
Marc Bouchere6869a82000-03-20 06:03:29 +000063special values
64.IR ACCEPT ,
65.IR DROP ,
66.IR QUEUE ,
67or
68.IR RETURN .
69.PP
70.I ACCEPT
71means to let the packet through.
72.I DROP
73means to drop the packet on the floor.
74.I QUEUE
Rusty Russell363112d2000-08-11 13:49:26 +000075means to pass the packet to userspace (if supported by the kernel).
Marc Bouchere6869a82000-03-20 06:03:29 +000076.I RETURN
Harald Welte0112abb2001-02-19 21:48:13 +000077means stop traversing this chain and resume at the next rule in the
78previous (calling) chain. If the end of a built-in chain is reached
Marc Bouchere6869a82000-03-20 06:03:29 +000079or a rule in a built-in chain with target
80.I RETURN
81is matched, the target specified by the chain policy determines the
82fate of the packet.
83.SH TABLES
Rusty Russell363112d2000-08-11 13:49:26 +000084There are current three independent tables (which tables are present
85at any time depends on the kernel configuration options and which
86modules are present).
Marc Bouchere6869a82000-03-20 06:03:29 +000087.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +000088.BI "-t, --table " "table"
Marc Bouchere6869a82000-03-20 06:03:29 +000089This option specifies the packet matching table which the command
90should operate on. If the kernel is configured with automatic module
91loading, an attempt will be made to load the appropriate module for
92that table if it is not already there.
93
94The tables are as follows:
Harald Welte87d4be42001-07-05 06:26:37 +000095.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +000096.B "filter"
Harald Welte0112abb2001-02-19 21:48:13 +000097This is the default table. It contains the built-in chains INPUT (for
Marc Bouchere6869a82000-03-20 06:03:29 +000098packets coming into the box itself), FORWARD (for packets being routed
99through the box), and OUTPUT (for locally-generated packets).
Harald Welte87d4be42001-07-05 06:26:37 +0000100.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000101.B "nat"
Harald Welte0112abb2001-02-19 21:48:13 +0000102This table is consulted when a packet that creates a new
Marc Bouchere6869a82000-03-20 06:03:29 +0000103connection is encountered. It consists of three built-ins: PREROUTING
104(for altering packets as soon as they come in), OUTPUT (for altering
105locally-generated packets before routing), and POSTROUTING (for
106altering packets as they are about to go out).
Harald Welte87d4be42001-07-05 06:26:37 +0000107.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000108.B "mangle"
109This table is used for specialized packet alteration. Until kernel
1102.4.17 it had two built-in chains: PREROUTING (for altering incoming
111packets before routing) and OUTPUT (for altering locally-generated
112packets before routing). Since kernel 2.4.18, three other built-in
113chains are also supported : INPUT (for packets coming into the box itself),
114FORWARD (for altering packets being routed through the box), and
115POSTROUTING (for altering packets as they are about to go out).
Marc Bouchere6869a82000-03-20 06:03:29 +0000116.SH OPTIONS
117The options that are recognized by
118.B iptables
119can be divided into several different groups.
120.SS COMMANDS
Harald Welte0112abb2001-02-19 21:48:13 +0000121These options specify the specific action to perform. Only one of them
122can be specified on the command line unless otherwise specified
Marc Bouchere6869a82000-03-20 06:03:29 +0000123below. For all the long versions of the command and option names, you
Harald Welte0112abb2001-02-19 21:48:13 +0000124need to use only enough letters to ensure that
Marc Bouchere6869a82000-03-20 06:03:29 +0000125.B iptables
126can differentiate it from all other options.
127.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000128.BI "-A, --append " "chain rule-specification"
Marc Bouchere6869a82000-03-20 06:03:29 +0000129Append one or more rules to the end of the selected chain.
130When the source and/or destination names resolve to more than one
131address, a rule will be added for each possible address combination.
132.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000133.BI "-D, --delete " "chain rule-specification"
134.ns
135.TP
136.BI "-D, --delete " "chain rulenum"
Marc Bouchere6869a82000-03-20 06:03:29 +0000137Delete one or more rules from the selected chain. There are two
138versions of this command: the rule can be specified as a number in the
139chain (starting at 1 for the first rule) or a rule to match.
140.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000141.BR "-I, --insert " "\fIchain\fP [\fIrulenum\fP] \fIrule-specification\fP"
Marc Bouchere6869a82000-03-20 06:03:29 +0000142Insert one or more rules in the selected chain as the given rule
143number. So, if the rule number is 1, the rule or rules are inserted
144at the head of the chain. This is also the default if no rule number
145is specified.
146.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000147.BI "-R, --replace " "chain rulenum rule-specification"
148Replace a rule in the selected chain. If the source and/or
149destination names resolve to multiple addresses, the command will
150fail. Rules are numbered starting at 1.
151.TP
152.BR "-L, --list " "[\fIchain\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000153List all rules in the selected chain. If no chain is selected, all
Hervé Eychenne9e518062002-03-14 09:25:40 +0000154chains are listed. As every other iptables command, it applies to the
155specified table (filter is the default), so NAT rules get listed by
156.br
157 iptables -t nat -n -L
158.br
159Please note that it is often used with the
160.B -n
161option, in order to avoid long reverse DNS lookups.
162It is legal to specify the
Marc Bouchere6869a82000-03-20 06:03:29 +0000163.B -Z
164(zero) option as well, in which case the chain(s) will be atomically
Harald Welte0112abb2001-02-19 21:48:13 +0000165listed and zeroed. The exact output is affected by the other
Marc Bouchere6869a82000-03-20 06:03:29 +0000166arguments given.
167.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000168.BR "-F, --flush " "[\fIchain\fP]"
169Flush the selected chain (all the chains in the table if none is given).
170This is equivalent to deleting all the rules one by one.
Marc Bouchere6869a82000-03-20 06:03:29 +0000171.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000172.BR "-Z, --zero " "[\fIchain\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000173Zero the packet and byte counters in all chains. It is legal to
174specify the
175.B "-L, --list"
176(list) option as well, to see the counters immediately before they are
Harald Welte0112abb2001-02-19 21:48:13 +0000177cleared. (See above.)
Marc Bouchere6869a82000-03-20 06:03:29 +0000178.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000179.BI "-N, --new-chain " "chain"
Harald Welte0112abb2001-02-19 21:48:13 +0000180Create a new user-defined chain by the given name. There must be no
Marc Bouchere6869a82000-03-20 06:03:29 +0000181target of that name already.
182.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000183.BR "-X, --delete-chain " "[\fIchain\fP]"
184Delete the optional user-defined chain specified. There must be no references
Harald Welte0112abb2001-02-19 21:48:13 +0000185to the chain. If there are, you must delete or replace the referring
186rules before the chain can be deleted. If no argument is given, it
Rusty Russell363112d2000-08-11 13:49:26 +0000187will attempt to delete every non-builtin chain in the table.
Marc Bouchere6869a82000-03-20 06:03:29 +0000188.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000189.BI "-P, --policy " "chain target"
Marc Bouchere6869a82000-03-20 06:03:29 +0000190Set the policy for the chain to the given target. See the section
Rusty Russell363112d2000-08-11 13:49:26 +0000191.B TARGETS
Hervé Eychenne9e518062002-03-14 09:25:40 +0000192for the legal targets. Only built-in (non-user-defined) chains can have
193policies, and neither built-in nor user-defined chains can be policy
194targets.
Marc Bouchere6869a82000-03-20 06:03:29 +0000195.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000196.BI "-E, --rename-chain " "old-chain new-chain"
Harald Welte0112abb2001-02-19 21:48:13 +0000197Rename the user specified chain to the user supplied name. This is
Marc Bouchere6869a82000-03-20 06:03:29 +0000198cosmetic, and has no effect on the structure of the table.
Marc Bouchere6869a82000-03-20 06:03:29 +0000199.TP
200.B -h
201Help.
202Give a (currently very brief) description of the command syntax.
203.SS PARAMETERS
204The following parameters make up a rule specification (as used in the
Harald Welte0112abb2001-02-19 21:48:13 +0000205add, delete, insert, replace and append commands).
Marc Bouchere6869a82000-03-20 06:03:29 +0000206.TP
Rusty Russell2e0a3212000-04-19 11:23:18 +0000207.BR "-p, --protocol " "[!] \fIprotocol\fP"
Marc Bouchere6869a82000-03-20 06:03:29 +0000208The protocol of the rule or of the packet to check.
209The specified protocol can be one of
210.IR tcp ,
211.IR udp ,
212.IR icmp ,
213or
214.IR all ,
215or it can be a numeric value, representing one of these protocols or a
Rusty Russell363112d2000-08-11 13:49:26 +0000216different one. A protocol name from /etc/protocols is also allowed.
Marc Bouchere6869a82000-03-20 06:03:29 +0000217A "!" argument before the protocol inverts the
218test. The number zero is equivalent to
219.IR all .
220Protocol
221.I all
222will match with all protocols and is taken as default when this
223option is omitted.
Marc Bouchere6869a82000-03-20 06:03:29 +0000224.TP
225.BR "-s, --source " "[!] \fIaddress\fP[/\fImask\fP]"
226Source specification.
227.I Address
Hervé Eychenne9e518062002-03-14 09:25:40 +0000228can be either a network name, a hostname (please note that specifying
229any name to be resolved with a remote query such as DNS is a really bad idea),
230a network IP address (with /mask), or a plain IP address.
Marc Bouchere6869a82000-03-20 06:03:29 +0000231The
232.I mask
233can be either a network mask or a plain number,
234specifying the number of 1's at the left side of the network mask.
235Thus, a mask of
236.I 24
237is equivalent to
238.IR 255.255.255.0 .
239A "!" argument before the address specification inverts the sense of
240the address. The flag
241.B --src
Hervé Eychenne9e518062002-03-14 09:25:40 +0000242is an alias for this option.
Marc Bouchere6869a82000-03-20 06:03:29 +0000243.TP
244.BR "-d, --destination " "[!] \fIaddress\fP[/\fImask\fP]"
245Destination specification.
246See the description of the
247.B -s
248(source) flag for a detailed description of the syntax. The flag
249.B --dst
250is an alias for this option.
251.TP
252.BI "-j, --jump " "target"
Harald Welte0112abb2001-02-19 21:48:13 +0000253This specifies the target of the rule; i.e., what to do if the packet
254matches it. The target can be a user-defined chain (other than the
255one this rule is in), one of the special builtin targets which decide
256the fate of the packet immediately, or an extension (see
Marc Bouchere6869a82000-03-20 06:03:29 +0000257.B EXTENSIONS
258below). If this
259option is omitted in a rule, then matching the rule will have no
260effect on the packet's fate, but the counters on the rule will be
261incremented.
262.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000263.BR "-i, --in-interface " "[!] \fIname\fP"
264Name of an interface via which a packet is going to be received (only for
Marc Bouchere6869a82000-03-20 06:03:29 +0000265packets entering the
266.BR INPUT ,
267.B FORWARD
268and
269.B PREROUTING
270chains). When the "!" argument is used before the interface name, the
271sense is inverted. If the interface name ends in a "+", then any
272interface which begins with this name will match. If this option is
Hervé Eychenne9e518062002-03-14 09:25:40 +0000273omitted, any interface name will match.
Marc Bouchere6869a82000-03-20 06:03:29 +0000274.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000275.BR "-o, --out-interface " "[!] \fIname\fP"
276Name of an interface via which a packet is going to be sent (for packets
277entering the
Marc Bouchere6869a82000-03-20 06:03:29 +0000278.BR FORWARD ,
279.B OUTPUT
280and
281.B POSTROUTING
Hervé Eychenne9e518062002-03-14 09:25:40 +0000282chains). When the "!" argument is used before the interface name, the
283sense is inverted. If the interface name ends in a "+", then any
Marc Bouchere6869a82000-03-20 06:03:29 +0000284interface 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
287.B "[!] " "-f, --fragment"
288This means that the rule only refers to second and further fragments
289of fragmented packets. Since there is no way to tell the source or
290destination ports of such a packet (or ICMP type), such a packet will
291not match any rules which specify them. When the "!" argument
Rusty Russell363112d2000-08-11 13:49:26 +0000292precedes the "-f" flag, the rule will only match head fragments, or
293unfragmented packets.
Harald Welteccd49e52001-01-23 22:54:34 +0000294.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000295.BI "-c, --set-counters " "PKTS BYTES"
Harald Welteccd49e52001-01-23 22:54:34 +0000296This enables the administrater to initialize the packet and byte
297counters of a rule (during
298.B INSERT,
299.B APPEND,
300.B REPLACE
Hervé Eychenne9e518062002-03-14 09:25:40 +0000301operations).
Marc Bouchere6869a82000-03-20 06:03:29 +0000302.SS "OTHER OPTIONS"
303The following additional options can be specified:
304.TP
305.B "-v, --verbose"
306Verbose output. This option makes the list command show the interface
307address, 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
311.B -x
312flag to change this).
313For appending, insertion, deletion and replacement, this causes
314detailed information on the rule or rules to be printed.
315.TP
316.B "-n, --numeric"
317Numeric output.
318IP addresses and port numbers will be printed in numeric format.
319By default, the program will try to display them as host names,
320network names, or services (whenever applicable).
321.TP
322.B "-x, --exact"
323Expand numbers.
324Display the exact value of the packet and byte counters,
325instead of only the rounded number in K's (multiples of 1000)
326M's (multiples of 1000K) or G's (multiples of 1000M). This option is
Marc Boucherf127a192000-03-20 08:32:15 +0000327only relevant for the
Marc Bouchere6869a82000-03-20 06:03:29 +0000328.B -L
329command.
330.TP
331.B "--line-numbers"
332When listing rules, add line numbers to the beginning of each rule,
333corresponding to that rule's position in the chain.
Chapman Brad45493a82001-02-23 09:08:13 +0000334.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000335.B "--modprobe=command"
Chapman Brad45493a82001-02-23 09:08:13 +0000336When adding or inserting rules into a chain, use
337.B command
338to load any necessary modules (targets, match extensions, etc).
Marc Bouchere6869a82000-03-20 06:03:29 +0000339.SH MATCH EXTENSIONS
Rusty Russell363112d2000-08-11 13:49:26 +0000340iptables can use extended packet matching modules. These are loaded
341in two ways: implicitly, when
342.B -p
343or
344.B --protocol
345is specified, or with the
346.B -m
347or
348.B --match
349options, followed by the matching module name; after these, various
350extra command line options become available, depending on the specific
Hervé Eychenne9e518062002-03-14 09:25:40 +0000351module. You can specify multiple extended match modules in one line,
352and you can use the
Rusty Russell363112d2000-08-11 13:49:26 +0000353.B -h
354or
355.B --help
356options after the module has been specified to receive help specific
357to that module.
358
359The following are included in the base package, and most of these can
360be preceded by a
Marc Bouchere6869a82000-03-20 06:03:29 +0000361.B !
362to invert the sense of the match.
363.SS tcp
Rusty Russell363112d2000-08-11 13:49:26 +0000364These extensions are loaded if `--protocol tcp' is specified. It
365provides the following options:
Marc Bouchere6869a82000-03-20 06:03:29 +0000366.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000367.BR "--source-port " "[!] \fIport\fP[:\fIport\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000368Source port or port range specification. This can either be a service
369name or a port number. An inclusive range can also be specified,
370using the format
James Morris59e90fd2000-06-23 16:44:47 +0000371.IR port : port .
Marc Bouchere6869a82000-03-20 06:03:29 +0000372If the first port is omitted, "0" is assumed; if the last is omitted,
373"65535" is assumed.
374If the second port greater then the first they will be swapped.
375The flag
376.B --sport
Hervé Eychenne9e518062002-03-14 09:25:40 +0000377is a convenient alias for this option.
Marc Bouchere6869a82000-03-20 06:03:29 +0000378.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000379.BR "--destination-port " "[!] \fIport\fP[:\fIport\fP]"
380Destination port or port range specification. The flag
Marc Bouchere6869a82000-03-20 06:03:29 +0000381.B --dport
Hervé Eychenne9e518062002-03-14 09:25:40 +0000382is a convenient alias for this option.
Marc Bouchere6869a82000-03-20 06:03:29 +0000383.TP
384.BR "--tcp-flags " "[!] \fImask\fP \fIcomp\fP"
385Match when the TCP flags are as specified. The first argument is the
386flags which we should examine, written as a comma-separated list, and
387the second argument is a comma-separated list of flags which must be
388set. Flags are:
389.BR "SYN ACK FIN RST URG PSH ALL NONE" .
390Hence the command
391.br
Marc Boucherf127a192000-03-20 08:32:15 +0000392 iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST SYN
Marc Bouchere6869a82000-03-20 06:03:29 +0000393.br
394will only match packets with the SYN flag set, and the ACK, FIN and
395RST flags unset.
396.TP
397.B "[!] --syn"
398Only match TCP packets with the SYN bit set and the ACK and FIN bits
399cleared. Such packets are used to request TCP connection initiation;
400for example, blocking such packets coming in an interface will prevent
401incoming TCP connections, but outgoing TCP connections will be
402unaffected.
403It is equivalent to \fB--tcp-flags SYN,RST,ACK SYN\fP.
404If the "!" flag precedes the "--syn", the sense of the
405option is inverted.
406.TP
407.BR "--tcp-option " "[!] \fInumber\fP"
408Match if TCP option set.
Hervé Eychenne9e518062002-03-14 09:25:40 +0000409.TP
410.BR "--mss " "\fIvalue\fP[:\fIvalue\fP]"
411Match TCP SYN or SYN/ACK packets with the specified MSS value (or range),
412which control the maximum packet size for that connection.
Marc Bouchere6869a82000-03-20 06:03:29 +0000413.SS udp
Rusty Russell363112d2000-08-11 13:49:26 +0000414These extensions are loaded if `--protocol udp' is specified. It
415provides the following options:
Marc Bouchere6869a82000-03-20 06:03:29 +0000416.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000417.BR "--source-port " "[!] \fIport\fP[:\fIport\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000418Source port or port range specification.
419See the description of the
420.B --source-port
421option of the TCP extension for details.
422.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000423.BR "--destination-port " "[!] \fIport\fP[:\fIport\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000424Destination port or port range specification.
425See the description of the
426.B --destination-port
427option of the TCP extension for details.
428.SS icmp
Rusty Russell363112d2000-08-11 13:49:26 +0000429This extension is loaded if `--protocol icmp' is specified. It
430provides the following option:
Marc Bouchere6869a82000-03-20 06:03:29 +0000431.TP
432.BR "--icmp-type " "[!] \fItypename\fP"
433This allows specification of the ICMP type, which can be a numeric
434ICMP type, or one of the ICMP type names shown by the command
435.br
436 iptables -p icmp -h
437.br
438.SS mac
439.TP
440.BR "--mac-source " "[!] \fIaddress\fP"
441Match source MAC address. It must be of the form XX:XX:XX:XX:XX:XX.
Hervé Eychenne9e518062002-03-14 09:25:40 +0000442Note that this only makes sense for packets coming from an Ethernet device
443and entering the
Marc Bouchere6869a82000-03-20 06:03:29 +0000444.BR PREROUTING ,
Rusty Russell4b3c03d2000-07-03 10:11:55 +0000445.B FORWARD
Marc Bouchere6869a82000-03-20 06:03:29 +0000446or
447.B INPUT
Hervé Eychenne9e518062002-03-14 09:25:40 +0000448chains.
Marc Bouchere6869a82000-03-20 06:03:29 +0000449.SS limit
Hervé Eychenne9e518062002-03-14 09:25:40 +0000450This module matches at a limited rate using a token bucket filter.
451A rule using this extension will match until this limit is reached
452(unless the `!' flag is used). It can be used in combination with the
Rusty Russell363112d2000-08-11 13:49:26 +0000453.B LOG
Hervé Eychenne9e518062002-03-14 09:25:40 +0000454target to give limited logging, for example.
Marc Bouchere6869a82000-03-20 06:03:29 +0000455.TP
456.BI "--limit " "rate"
457Maximum average matching rate: specified as a number, with an optional
458`/second', `/minute', `/hour', or `/day' suffix; the default is
4593/hour.
460.TP
461.BI "--limit-burst " "number"
Hervé Eychenne9e518062002-03-14 09:25:40 +0000462Maximum initial number of packets to match: this number gets
Marc Bouchere6869a82000-03-20 06:03:29 +0000463recharged by one every time the limit specified above is not reached,
464up to this number; the default is 5.
465.SS multiport
Hervé Eychenne9e518062002-03-14 09:25:40 +0000466This module matches a set of source or destination ports. Up to 15
467ports can be specified. It can only be used in conjunction with
Marc Bouchere6869a82000-03-20 06:03:29 +0000468.B "-p tcp"
469or
470.BR "-p udp" .
471.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000472.BR "--source-ports " "\fIport\fP[,\fIport\fP[,\fIport\fP...]]"
473Match if the source port is one of the given ports. The flag
474.B --sports
475is a convenient alias for this option.
Marc Bouchere6869a82000-03-20 06:03:29 +0000476.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000477.BR "--destination-ports " "\fIport\fP[,\fIport\fP[,\fIport\fP...]]"
478Match if the destination port is one of the given ports. The flag
479.B --dports
480is a convenient alias for this option.
Marc Bouchere6869a82000-03-20 06:03:29 +0000481.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000482.BR "--ports " "\fIport\fP[,\fIport\fP[,\fIport\fP...]]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000483Match if the both the source and destination ports are equal to each
484other and to one of the given ports.
485.SS mark
486This module matches the netfilter mark field associated with a packet
487(which can be set using the
488.B MARK
489target below).
490.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000491.BR "--mark " "\fIvalue\fP[/\fImask\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000492Matches packets with the given unsigned mark value (if a mask is
Harald Welte87d4be42001-07-05 06:26:37 +0000493specified, this is logically ANDed with the mask before the
Marc Bouchere6869a82000-03-20 06:03:29 +0000494comparison).
495.SS owner
496This module attempts to match various characteristics of the packet
497creator, for locally-generated packets. It is only valid in the
Rusty Russell363112d2000-08-11 13:49:26 +0000498.B OUTPUT
499chain, and even this some packets (such as ICMP ping responses) may
500have no owner, and hence never match.
Marc Bouchere6869a82000-03-20 06:03:29 +0000501.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000502.BI "--uid-owner " "userid"
Marc Bouchere6869a82000-03-20 06:03:29 +0000503Matches if the packet was created by a process with the given
504effective user id.
505.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000506.BI "--gid-owner " "groupid"
Marc Bouchere6869a82000-03-20 06:03:29 +0000507Matches if the packet was created by a process with the given
508effective group id.
509.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000510.BI "--pid-owner " "processid"
Marc Bouchere6869a82000-03-20 06:03:29 +0000511Matches if the packet was created by a process with the given
512process id.
513.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000514.BI "--sid-owner " "sessionid"
Marc Bouchere6869a82000-03-20 06:03:29 +0000515Matches if the packet was created by a process in the given session
516group.
Marc Boucherf5c32d62002-01-19 12:46:04 +0000517.TP
518.BI "--cmd-owner " "name"
519Matches if the packet was created by a process with the given command name.
520(this option is present only if iptables was compiled under a kernel
521supporting this feature)
Marc Bouchere6869a82000-03-20 06:03:29 +0000522.SS state
523This module, when combined with connection tracking, allows access to
524the connection tracking state for this packet.
525.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000526.BI "--state " "state"
Marc Bouchere6869a82000-03-20 06:03:29 +0000527Where state is a comma separated list of the connection states to
528match. Possible states are
529.B INVALID
530meaning that the packet is associated with no known connection,
531.B ESTABLISHED
532meaning that the packet is associated with a connection which has seen
533packets in both directions,
534.B NEW
535meaning that the packet has started a new connection, or otherwise
536associated with a connection which has not seen packets in both
537directions, and
538.B RELATED
539meaning that the packet is starting a new connection, but is
540associated with an existing connection, such as an FTP data transfer,
541or an ICMP error.
Marc Bouchere6869a82000-03-20 06:03:29 +0000542.SS tos
543This module matches the 8 bits of Type of Service field in the IP
544header (ie. including the precedence bits).
545.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000546.BI "--tos " "tos"
Marc Bouchere6869a82000-03-20 06:03:29 +0000547The argument is either a standard name, (use
548.br
549 iptables -m tos -h
550.br
551to see the list), or a numeric value to match.
Hervé Eychenne9e518062002-03-14 09:25:40 +0000552.SS ah
553This module matches the SPIs in AH header of IPSec packets.
554.TP
555.BR "--ahspi " "[!] \fIspi\fP[:\fIspi\fP]"
556.SS esp
557This module matches the SPIs in ESP header of IPSec packets.
558.TP
559.BR "--espspi " "[!] \fIspi\fP[:\fIspi\fP]"
560.SS length
561This module matches the length of a packet against a specific value
562or range of values.
563.TP
564.BR "--length " "\fIlength\fP[:\fIlength\fP]"
565.SS ttl
566This module matches the time to live field in the IP header.
567.TP
568.BI "--ttl " "ttl"
569Matches the given TTL value.
570.SS owner
571This module attempts to match various characteristics of the packet
572creator, for locally-generated packets. It is only valid in the
573.B OUTPUT
574chain, and even this some packets (such as ICMP ping responses) may
575have no owner, and hence never match. This is regarded as experimental.
576.TP
577.BI "--uid-owner " "userid"
578Matches if the packet was created by a process with the given
579effective user id.
580.TP
581.BI "--gid-owner " "groupid"
582Matches if the packet was created by a process with the given
583effective group id.
584.TP
585.BI "--pid-owner " "processid"
586Matches if the packet was created by a process with the given
587process id.
588.TP
589.BI "--sid-owner " "sessionid"
590Matches if the packet was created by a process in the given session
591group.
592.SS unclean
593This module takes no options, but attempts to match packets which seem
594malformed or unusual. This is regarded as experimental.
Marc Bouchere6869a82000-03-20 06:03:29 +0000595.SH TARGET EXTENSIONS
596iptables can use extended target modules: the following are included
597in the standard distribution.
598.SS LOG
599Turn on kernel logging of matching packets. When this option is set
600for a rule, the Linux kernel will print some information on all
Rusty Russell363112d2000-08-11 13:49:26 +0000601matching packets (like most IP header fields) via the kernel log
602(where it can be read with
603.I dmesg
604or
605.IR syslogd (8)).
Hervé Eychenne9e518062002-03-14 09:25:40 +0000606This is a "non-terminating target", i.e. rule traversal continues at
607the next rule. So if you want to LOG the packets you refuse, use two
608separate rules with the same matching criterias, first using target LOG
609then DROP (or REJECT).
Marc Bouchere6869a82000-03-20 06:03:29 +0000610.TP
611.BI "--log-level " "level"
612Level of logging (numeric or see \fIsyslog.conf\fP(5)).
613.TP
614.BI "--log-prefix " "prefix"
Rusty Russellf81427e2000-09-13 04:20:38 +0000615Prefix log messages with the specified prefix; up to 29 letters long,
Marc Bouchere6869a82000-03-20 06:03:29 +0000616and useful for distinguishing messages in the logs.
617.TP
618.B --log-tcp-sequence
619Log TCP sequence numbers. This is a security risk if the log is
620readable by users.
621.TP
622.B --log-tcp-options
623Log options from the TCP packet header.
624.TP
625.B --log-ip-options
626Log options from the IP packet header.
627.SS MARK
628This is used to set the netfilter mark value associated with the
629packet. It is only valid in the
630.B mangle
Hervé Eychenne9e518062002-03-14 09:25:40 +0000631table. It can for example be used in conjunction with iproute2.
Marc Bouchere6869a82000-03-20 06:03:29 +0000632.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000633.BI "--set-mark " "mark"
Marc Bouchere6869a82000-03-20 06:03:29 +0000634.SS REJECT
635This is used to send back an error packet in response to the matched
636packet: otherwise it is equivalent to
Hervé Eychenne9e518062002-03-14 09:25:40 +0000637.B DROP
638so it is a terminating TARGET, ending rule traversal.
Marc Bouchere6869a82000-03-20 06:03:29 +0000639This target is only valid in the
640.BR INPUT ,
641.B FORWARD
642and
643.B OUTPUT
Rusty Russell9cadb432000-05-10 00:18:06 +0000644chains, and user-defined chains which are only called from those
Hervé Eychenne9e518062002-03-14 09:25:40 +0000645chains. The following option controls the nature of the error packet
Marc Bouchere6869a82000-03-20 06:03:29 +0000646returned:
647.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000648.BI "--reject-with " "type"
Marc Bouchere6869a82000-03-20 06:03:29 +0000649The type given can be
650.BR icmp-net-unreachable ,
651.BR icmp-host-unreachable ,
Rusty Russell14f390f2000-07-30 01:10:04 +0000652.BR icmp-port-unreachable ,
653.BR icmp-proto-unreachable ,
Hervé Eychenne9e518062002-03-14 09:25:40 +0000654.BR "icmp-net-prohibited or"
Rusty Russell14f390f2000-07-30 01:10:04 +0000655.BR icmp-host-prohibited ,
Hervé Eychenne9e518062002-03-14 09:25:40 +0000656which return the appropriate ICMP error message (\fBport-unreachable\fP is
657the default). The option
Rusty Russell14f390f2000-07-30 01:10:04 +0000658.B tcp-reset
Rusty Russell363112d2000-08-11 13:49:26 +0000659can be used on rules which only match the TCP protocol: this causes a
660TCP RST packet to be sent back. This is mainly useful for blocking
661.I ident
Hervé Eychenne9e518062002-03-14 09:25:40 +0000662(113/tcp) probes which frequently occur when sending mail to broken mail
663hosts (which won't accept your mail otherwise).
Marc Bouchere6869a82000-03-20 06:03:29 +0000664.SS TOS
665This is used to set the 8-bit Type of Service field in the IP header.
666It is only valid in the
667.B mangle
668table.
669.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000670.BI "--set-tos " "tos"
Marc Bouchere6869a82000-03-20 06:03:29 +0000671You can use a numeric TOS values, or use
672.br
673 iptables -j TOS -h
674.br
675to see the list of valid TOS names.
676.SS MIRROR
677This is an experimental demonstration target which inverts the source
678and destination fields in the IP header and retransmits the packet.
679It is only valid in the
680.BR INPUT ,
681.B FORWARD
682and
Rusty Russell363112d2000-08-11 13:49:26 +0000683.B PREROUTING
684chains, and user-defined chains which are only called from those
685chains. Note that the outgoing packets are
686.B NOT
687seen by any packet filtering chains, connection tracking or NAT, to
688avoid loops and other problems.
Marc Bouchere6869a82000-03-20 06:03:29 +0000689.SS SNAT
690This target is only valid in the
691.B nat
692table, in the
693.B POSTROUTING
694chain. It specifies that the source address of the packet should be
695modified (and all future packets in this connection will also be
696mangled), and rules should cease being examined. It takes one option:
697.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000698.BR "--to-source " "\fIipaddr\fP[-\fIipaddr\fP][:\fIport\fP-\fIport\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000699which can specify a single new source IP address, an inclusive range
700of IP addresses, and optionally, a port range (which is only valid if
701the rule also specifies
702.B "-p tcp"
703or
704.BR "-p udp" ).
705If no port range is specified, then source ports below 512 will be
Harald Welte0112abb2001-02-19 21:48:13 +0000706mapped to other ports below 512: those between 512 and 1023 inclusive
707will be mapped to ports below 1024, and other ports will be mapped to
7081024 or above. Where possible, no port alteration will occur.
Marc Bouchere6869a82000-03-20 06:03:29 +0000709.SS DNAT
710This target is only valid in the
711.B nat
712table, in the
713.B PREROUTING
714and
715.B OUTPUT
Rusty Russell9cadb432000-05-10 00:18:06 +0000716chains, and user-defined chains which are only called from those
Marc Bouchere6869a82000-03-20 06:03:29 +0000717chains. It specifies that the destination address of the packet
718should be modified (and all future packets in this connection will
719also be mangled), and rules should cease being examined. It takes one
720option:
721.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000722.BR "--to-destination " "\fIipaddr\fP[-\fIipaddr\fP][:\fIport\fP-\fIport\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000723which can specify a single new destination IP address, an inclusive
724range of IP addresses, and optionally, a port range (which is only
725valid if the rule also specifies
726.B "-p tcp"
727or
728.BR "-p udp" ).
729If no port range is specified, then the destination port will never be
730modified.
731.SS MASQUERADE
732This target is only valid in the
733.B nat
734table, in the
735.B POSTROUTING
736chain. It should only be used with dynamically assigned IP (dialup)
737connections: if you have a static IP address, you should use the SNAT
738target. Masquerading is equivalent to specifying a mapping to the IP
739address of the interface the packet is going out, but also has the
740effect that connections are
741.I forgotten
Marc Boucherf127a192000-03-20 08:32:15 +0000742when the interface goes down. This is the correct behavior when the
Marc Bouchere6869a82000-03-20 06:03:29 +0000743next dialup is unlikely to have the same interface address (and hence
744any established connections are lost anyway). It takes one option:
745.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000746.BR "--to-ports " "\fIport\fP[-\fIport\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000747This specifies a range of source ports to use, overriding the default
748.B SNAT
Hervé Eychenne9e518062002-03-14 09:25:40 +0000749source port-selection heuristics (see above). This is only valid
Marc Bouchere6869a82000-03-20 06:03:29 +0000750if the rule also specifies
751.B "-p tcp"
752or
Hervé Eychenne9e518062002-03-14 09:25:40 +0000753.BR "-p udp" .
Marc Bouchere6869a82000-03-20 06:03:29 +0000754.SS REDIRECT
755This target is only valid in the
756.B nat
757table, in the
758.B PREROUTING
759and
760.B OUTPUT
Rusty Russell9cadb432000-05-10 00:18:06 +0000761chains, and user-defined chains which are only called from those
Marc Bouchere6869a82000-03-20 06:03:29 +0000762chains. It alters the destination IP address to send the packet to
763the machine itself (locally-generated packets are mapped to the
Rusty Russell9cadb432000-05-10 00:18:06 +0000764127.0.0.1 address). It takes one option:
Marc Bouchere6869a82000-03-20 06:03:29 +0000765.TP
Hervé Eychenne9e518062002-03-14 09:25:40 +0000766.BR "--to-ports " "\fIport\fP[-\fIport\fP]"
767This specifies a destination port or range of ports to use: without
768this, the destination port is never altered. This is only valid
Marc Bouchere6869a82000-03-20 06:03:29 +0000769if the rule also specifies
770.B "-p tcp"
771or
Hervé Eychenne9e518062002-03-14 09:25:40 +0000772.BR "-p udp" .
773.SS ULOG
774This target provides userspace logging of matching packets. When this
775target is set for a rule, the Linux kernel will multicast this packet
776through a
777.IR netlink
778socket. One or more userspace processes may then subscribe to various
779multicast groups and receive the packets.
780.TP
781.BI "--ulog-nlgroup " "nlgroup"
782This specifies the netlink group (1-32) to which the packet is sent.
783Default value is 1.
784.TP
785.BI "--ulog-prefix " "prefix"
786Prefix log messages with the specified prefix; up to 32 characters
787long, and useful fro distinguishing messages in the logs.
788.TP
789.BI "--ulog-cprange " "size"
790Number of bytes to be copied to userspace. A value of 0 always copies
791the entire packet, regardless of its size. Default is 0.
792.TP
793.BI "--ulog-qthreshold " "size"
794Number of packet to queue inside kernel. Setting this value to, e.g. 10
795accumulates ten packets inside the kernel and transmits them as one
796netlink multipart message to userspace. Default is 1 (for backwards
797compatibility).
798.SS TCPMSS
799This target allows to alter the MSS value of TCP SYN packets, to control
800the maximum size for that connection (usually limiting it to your
801outgoing interface's MTU minus 40). Of course, it can only be used
802in conjunction with
803.BR "-p tcp" .
804.br
805This target is used to overcome criminally braindead ISPs or servers
806which block ICMP Fragmentation Needed packets. The symptoms of this
807problem are that everything works fine from your Linux
808firewall/router, but machines behind it can never exchange large
809packets:
810.br
811 1) Web browsers connect, then hang with no data received.
812.br
813 2) Small mail works fine, but large emails hang.
814.br
815 3) ssh works fine, but scp hangs after initial handshaking.
816.br
817Workaround: activate this option and add a rule to your firewall
818configuration like:
819.br
820 iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN \\
821.br
822 -j TCPMSS --clamp-mss-to-pmtu
823.TP
824.BI "--set-mss " "value"
825Explicitly set MSS option to specified value.
826.TP
827.B "--clamp-mss-to-pmtu"
828Automatically clamp MSS value to (path_MTU - 40).
829.TP
830These options are mutually exclusive.
Rusty Russell86573e52000-10-11 06:01:13 +0000831.SH EXTRA EXTENSIONS
832The following extensions are not included by default in the standard
833distribution.
Rusty Russell86573e52000-10-11 06:01:13 +0000834.SS TTL
835This target is used to modify the time to live field in the IP header.
836It is only valid in the
837.B mangle
838table.
839.TP
840.BI "--ttl-set " "ttl"
841Set the TTL to the given value.
842.TP
843.BI "--ttl-dec " "ttl"
844Decrement the TTL by the given value.
845.TP
846.BI "--ttl-inc " "ttl"
847Increment the TTL by the given value.
Rusty Russell86573e52000-10-11 06:01:13 +0000848.SH DIAGNOSTICS
849Various error messages are printed to standard error. The exit code
850is 0 for correct functioning. Errors which appear to be caused by
851invalid or abused command line parameters cause an exit code of 2, and
852other errors cause an exit code of 1.
Marc Bouchere6869a82000-03-20 06:03:29 +0000853.SH BUGS
854Check is not implemented (yet).
855.SH COMPATIBILITY WITH IPCHAINS
856This
857.B iptables
858is very similar to ipchains by Rusty Russell. The main difference is
859that the chains
860.B INPUT
861and
862.B OUTPUT
863are only traversed for packets coming into the local host and
864originating from the local host respectively. Hence every packet only
865passes through one of the three chains; previously a forwarded packet
866would pass through all three.
867.PP
868The other main difference is that
869.B -i
870refers to the input interface;
871.B -o
872refers to the output interface, and both are available for packets
873entering the
874.B FORWARD
875chain.
876.PP The various forms of NAT have been separated out;
877.B iptables
878is a pure packet filter when using the default `filter' table, with
879optional extension modules. This should simplify much of the previous
880confusion over the combination of IP masquerading and packet filtering
881seen previously. So the following options are handled differently:
882.br
883 -j MASQ
884.br
885 -M -S
886.br
887 -M -L
888.br
889There are several other changes in iptables.
890.SH SEE ALSO
Hervé Eychenne9e518062002-03-14 09:25:40 +0000891The packet-filtering-HOWTO, which details more iptables usage for
892packet filtering, the NAT-HOWTO, which details NAT,
893and the netfilter-hacking-HOWTO which details the internals.
894.br
895See
896.BR "http://www.netfilter.org/" .
Marc Boucherf127a192000-03-20 08:32:15 +0000897.SH AUTHORS
Marc Bouchere6869a82000-03-20 06:03:29 +0000898Rusty Russell wrote iptables, in early consultation with Michael
899Neuling.
900.PP
Marc Boucherf127a192000-03-20 08:32:15 +0000901Marc Boucher made Rusty abandon ipnatctl by lobbying for a generic packet
902selection framework in iptables, then wrote the mangle table, the owner match,
903the mark stuff, and ran around doing cool stuff everywhere.
Marc Bouchere6869a82000-03-20 06:03:29 +0000904.PP
905James Morris wrote the TOS target, and tos match.
906.PP
907Jozsef Kadlecsik wrote the REJECT target.
908.PP
Rusty Russell86573e52000-10-11 06:01:13 +0000909Harald Welte wrote the ULOG target, TTL match+target and libipulog.
Rusty Russell52451822000-08-27 07:47:46 +0000910.PP
James Morrisedfce4e2001-12-07 10:23:22 +0000911The Netfilter Core Team is: Marc Boucher, Jozsef Kadlecsik, James Morris,
912Harald Welte and Rusty Russell.
Hervé Eychenne9e518062002-03-14 09:25:40 +0000913.PP
914Man page written by Herve Eychenne <rv@wallfire.org>.
Marc Bouchere6869a82000-03-20 06:03:29 +0000915.\" .. and did I mention that we are incredibly cool people?
Rusty Russell363112d2000-08-11 13:49:26 +0000916.\" .. sexy, too ..
Rusty Russell86573e52000-10-11 06:01:13 +0000917.\" .. witty, charming, powerful ..
James Morris060ae4c2000-10-29 01:29:57 +0000918.\" .. and most of all, modest ..