blob: 94dbe1791bf0b5b875f1126ea20265417675c449 [file] [log] [blame]
Rusty Russell363112d2000-08-11 13:49:26 +00001.TH IPTABLES 8 "Aug 11, 2000" "" ""
Marc Bouchere6869a82000-03-20 06:03:29 +00002.\"
3.\" Man page written by Herve Eychenne <eychenne@info.enserb.u-bordeaux.fr>
4.\" It is based on ipchains man page.
5.\"
6.\" ipchains page by Paul ``Rusty'' Russell March 1997
7.\" Based on the original ipfwadm man page by Jos Vos <jos@xos.nl> (see README)
8.\"
9.\" This program is free software; you can redistribute it and/or modify
10.\" it under the terms of the GNU General Public License as published by
11.\" the Free Software Foundation; either version 2 of the License, or
12.\" (at your option) any later version.
13.\"
14.\" This program is distributed in the hope that it will be useful,
15.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
16.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17.\" GNU General Public License for more details.
18.\"
19.\" You should have received a copy of the GNU General Public License
20.\" along with this program; if not, write to the Free Software
21.\" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22.\"
23.\"
24.SH NAME
25iptables \- IP packet filter administration
26.SH SYNOPSIS
27.BR "iptables -[ADC] " "chain rule-specification [options]"
28.br
29.BR "iptables -[RI] " "chain rulenum rule-specification [options]"
30.br
31.BR "iptables -D " "chain rulenum [options]"
32.br
33.BR "iptables -[LFZ] " "[chain] [options]"
34.br
35.BR "iptables -[NX] " "chain"
36.br
37.BR "iptables -P " "chain target [options]"
38.br
39.BR "iptables -E " "old-chain-name new-chain-name"
40.SH DESCRIPTION
41.B Iptables
42is used to set up, maintain, and inspect the tables of IP packet
Harald Welte0112abb2001-02-19 21:48:13 +000043filter rules in the Linux kernel. Several different tables
44may be defined. Each table contains a number of built-in
45chains and may also contain user-defined chains.
Marc Bouchere6869a82000-03-20 06:03:29 +000046
Harald Welte0112abb2001-02-19 21:48:13 +000047Each chain is a list of rules which can match a set of packets. Each
48rule specifies what to do with a packet that matches. This is called
Marc Bouchere6869a82000-03-20 06:03:29 +000049a `target', which may be a jump to a user-defined chain in the same
50table.
51
52.SH TARGETS
53A firewall rule specifies criteria for a packet, and a target. If the
54packet does not match, the next rule in the chain is the examined; if
55it does match, then the next rule is specified by the value of the
Harald Welte0112abb2001-02-19 21:48:13 +000056target, which can be the name of a user-defined chain or one of the
Marc Bouchere6869a82000-03-20 06:03:29 +000057special values
58.IR ACCEPT ,
59.IR DROP ,
60.IR QUEUE ,
61or
62.IR RETURN .
63.PP
64.I ACCEPT
65means to let the packet through.
66.I DROP
67means to drop the packet on the floor.
68.I QUEUE
Rusty Russell363112d2000-08-11 13:49:26 +000069means to pass the packet to userspace (if supported by the kernel).
Marc Bouchere6869a82000-03-20 06:03:29 +000070.I RETURN
Harald Welte0112abb2001-02-19 21:48:13 +000071means stop traversing this chain and resume at the next rule in the
72previous (calling) chain. If the end of a built-in chain is reached
Marc Bouchere6869a82000-03-20 06:03:29 +000073or a rule in a built-in chain with target
74.I RETURN
75is matched, the target specified by the chain policy determines the
76fate of the packet.
77.SH TABLES
Rusty Russell363112d2000-08-11 13:49:26 +000078There are current three independent tables (which tables are present
79at any time depends on the kernel configuration options and which
80modules are present).
Marc Bouchere6869a82000-03-20 06:03:29 +000081.TP
82.B "-t, --table"
83This option specifies the packet matching table which the command
84should operate on. If the kernel is configured with automatic module
85loading, an attempt will be made to load the appropriate module for
86that table if it is not already there.
87
88The tables are as follows:
89.BR "filter"
Harald Welte0112abb2001-02-19 21:48:13 +000090This is the default table. It contains the built-in chains INPUT (for
Marc Bouchere6869a82000-03-20 06:03:29 +000091packets coming into the box itself), FORWARD (for packets being routed
92through the box), and OUTPUT (for locally-generated packets).
93.BR "nat"
Harald Welte0112abb2001-02-19 21:48:13 +000094This table is consulted when a packet that creates a new
Marc Bouchere6869a82000-03-20 06:03:29 +000095connection is encountered. It consists of three built-ins: PREROUTING
96(for altering packets as soon as they come in), OUTPUT (for altering
97locally-generated packets before routing), and POSTROUTING (for
98altering packets as they are about to go out).
99.BR "mangle"
100This table is used for specialized packet alteration. It has two
101built-in chains: PREROUTING (for altering incoming packets before
102routing) and OUTPUT (for altering locally-generated packets before
103routing).
104.SH OPTIONS
105The options that are recognized by
106.B iptables
107can be divided into several different groups.
108.SS COMMANDS
Harald Welte0112abb2001-02-19 21:48:13 +0000109These options specify the specific action to perform. Only one of them
110can be specified on the command line unless otherwise specified
Marc Bouchere6869a82000-03-20 06:03:29 +0000111below. For all the long versions of the command and option names, you
Harald Welte0112abb2001-02-19 21:48:13 +0000112need to use only enough letters to ensure that
Marc Bouchere6869a82000-03-20 06:03:29 +0000113.B iptables
114can differentiate it from all other options.
115.TP
116.BR "-A, --append"
117Append one or more rules to the end of the selected chain.
118When the source and/or destination names resolve to more than one
119address, a rule will be added for each possible address combination.
120.TP
121.BR "-D, --delete"
122Delete one or more rules from the selected chain. There are two
123versions of this command: the rule can be specified as a number in the
124chain (starting at 1 for the first rule) or a rule to match.
125.TP
126.B "-R, --replace"
127Replace a rule in the selected chain. If the source and/or
128destination names resolve to multiple addresses, the command will
129fail. Rules are numbered starting at 1.
130.TP
131.B "-I, --insert"
132Insert one or more rules in the selected chain as the given rule
133number. So, if the rule number is 1, the rule or rules are inserted
134at the head of the chain. This is also the default if no rule number
135is specified.
136.TP
137.B "-L, --list"
138List all rules in the selected chain. If no chain is selected, all
139chains are listed. It is legal to specify the
140.B -Z
141(zero) option as well, in which case the chain(s) will be atomically
Harald Welte0112abb2001-02-19 21:48:13 +0000142listed and zeroed. The exact output is affected by the other
Marc Bouchere6869a82000-03-20 06:03:29 +0000143arguments given.
144.TP
145.B "-F, --flush"
146Flush the selected chain. This is equivalent to deleting all the
147rules one by one.
148.TP
149.B "-Z, --zero"
150Zero the packet and byte counters in all chains. It is legal to
151specify the
152.B "-L, --list"
153(list) option as well, to see the counters immediately before they are
Harald Welte0112abb2001-02-19 21:48:13 +0000154cleared. (See above.)
Marc Bouchere6869a82000-03-20 06:03:29 +0000155.TP
156.B "-N, --new-chain"
Harald Welte0112abb2001-02-19 21:48:13 +0000157Create a new user-defined chain by the given name. There must be no
Marc Bouchere6869a82000-03-20 06:03:29 +0000158target of that name already.
159.TP
160.B "-X, --delete-chain"
161Delete the specified user-defined chain. There must be no references
Harald Welte0112abb2001-02-19 21:48:13 +0000162to the chain. If there are, you must delete or replace the referring
163rules before the chain can be deleted. If no argument is given, it
Rusty Russell363112d2000-08-11 13:49:26 +0000164will attempt to delete every non-builtin chain in the table.
Marc Bouchere6869a82000-03-20 06:03:29 +0000165.TP
166.B "-P, --policy"
167Set the policy for the chain to the given target. See the section
Rusty Russell363112d2000-08-11 13:49:26 +0000168.B TARGETS
Rusty Russell86573e52000-10-11 06:01:13 +0000169for the legal targets. Only non-user-defined chains can have policies,
Rusty Russell363112d2000-08-11 13:49:26 +0000170and neither built-in nor user-defined chains can be policy targets.
Marc Bouchere6869a82000-03-20 06:03:29 +0000171.TP
172.B "-E, --rename-chain"
Harald Welte0112abb2001-02-19 21:48:13 +0000173Rename the user specified chain to the user supplied name. This is
Marc Bouchere6869a82000-03-20 06:03:29 +0000174cosmetic, and has no effect on the structure of the table.
Marc Bouchere6869a82000-03-20 06:03:29 +0000175.TP
176.B -h
177Help.
178Give a (currently very brief) description of the command syntax.
179.SS PARAMETERS
180The following parameters make up a rule specification (as used in the
Harald Welte0112abb2001-02-19 21:48:13 +0000181add, delete, insert, replace and append commands).
Marc Bouchere6869a82000-03-20 06:03:29 +0000182.TP
Rusty Russell2e0a3212000-04-19 11:23:18 +0000183.BR "-p, --protocol " "[!] \fIprotocol\fP"
Marc Bouchere6869a82000-03-20 06:03:29 +0000184The protocol of the rule or of the packet to check.
185The specified protocol can be one of
186.IR tcp ,
187.IR udp ,
188.IR icmp ,
189or
190.IR all ,
191or it can be a numeric value, representing one of these protocols or a
Rusty Russell363112d2000-08-11 13:49:26 +0000192different one. A protocol name from /etc/protocols is also allowed.
Marc Bouchere6869a82000-03-20 06:03:29 +0000193A "!" argument before the protocol inverts the
194test. The number zero is equivalent to
195.IR all .
196Protocol
197.I all
198will match with all protocols and is taken as default when this
199option is omitted.
Marc Bouchere6869a82000-03-20 06:03:29 +0000200.TP
201.BR "-s, --source " "[!] \fIaddress\fP[/\fImask\fP]"
202Source specification.
203.I Address
204can be either a hostname, a network name, or a plain IP address.
205The
206.I mask
207can be either a network mask or a plain number,
208specifying the number of 1's at the left side of the network mask.
209Thus, a mask of
210.I 24
211is equivalent to
212.IR 255.255.255.0 .
213A "!" argument before the address specification inverts the sense of
214the address. The flag
215.B --src
216is a convenient alias for this option.
217.TP
218.BR "-d, --destination " "[!] \fIaddress\fP[/\fImask\fP]"
219Destination specification.
220See the description of the
221.B -s
222(source) flag for a detailed description of the syntax. The flag
223.B --dst
224is an alias for this option.
225.TP
226.BI "-j, --jump " "target"
Harald Welte0112abb2001-02-19 21:48:13 +0000227This specifies the target of the rule; i.e., what to do if the packet
228matches it. The target can be a user-defined chain (other than the
229one this rule is in), one of the special builtin targets which decide
230the fate of the packet immediately, or an extension (see
Marc Bouchere6869a82000-03-20 06:03:29 +0000231.B EXTENSIONS
232below). If this
233option is omitted in a rule, then matching the rule will have no
234effect on the packet's fate, but the counters on the rule will be
235incremented.
236.TP
237.BR "-i, --in-interface " "[!] [\fIname\fP]"
238Optional name of an interface via which a packet is received (for
239packets entering the
240.BR INPUT ,
241.B FORWARD
242and
243.B PREROUTING
244chains). When the "!" argument is used before the interface name, the
245sense is inverted. If the interface name ends in a "+", then any
246interface which begins with this name will match. If this option is
247omitted, the string "+" is assumed, which will match with any
248interface name.
249.TP
250.BR "-o, --out-interface " "[!] [\fIname\fP]"
251Optional name of an interface via which a packet is going to
252be sent (for packets entering the
253.BR FORWARD ,
254.B OUTPUT
255and
256.B POSTROUTING
257chains). When the "!" argument is used before the interface name,
258the sense is inverted. If the interface name ends in a "+", then any
259interface which begins with this name will match. If this option is
260omitted, the string "+" is assumed, which will match with any
261interface name.
262.TP
263.B "[!] " "-f, --fragment"
264This means that the rule only refers to second and further fragments
265of fragmented packets. Since there is no way to tell the source or
266destination ports of such a packet (or ICMP type), such a packet will
267not match any rules which specify them. When the "!" argument
Rusty Russell363112d2000-08-11 13:49:26 +0000268precedes the "-f" flag, the rule will only match head fragments, or
269unfragmented packets.
Harald Welteccd49e52001-01-23 22:54:34 +0000270.TP
271.B "-c, --set-counters " "PKTS BYTES"
272This enables the administrater to initialize the packet and byte
273counters of a rule (during
274.B INSERT,
275.B APPEND,
276.B REPLACE
277operations)
Marc Bouchere6869a82000-03-20 06:03:29 +0000278.SS "OTHER OPTIONS"
279The following additional options can be specified:
280.TP
281.B "-v, --verbose"
282Verbose output. This option makes the list command show the interface
283address, the rule options (if any), and the TOS masks. The packet and
284byte counters are also listed, with the suffix 'K', 'M' or 'G' for
2851000, 1,000,000 and 1,000,000,000 multipliers respectively (but see
286the
287.B -x
288flag to change this).
289For appending, insertion, deletion and replacement, this causes
290detailed information on the rule or rules to be printed.
291.TP
292.B "-n, --numeric"
293Numeric output.
294IP addresses and port numbers will be printed in numeric format.
295By default, the program will try to display them as host names,
296network names, or services (whenever applicable).
297.TP
298.B "-x, --exact"
299Expand numbers.
300Display the exact value of the packet and byte counters,
301instead of only the rounded number in K's (multiples of 1000)
302M's (multiples of 1000K) or G's (multiples of 1000M). This option is
Marc Boucherf127a192000-03-20 08:32:15 +0000303only relevant for the
Marc Bouchere6869a82000-03-20 06:03:29 +0000304.B -L
305command.
306.TP
307.B "--line-numbers"
308When listing rules, add line numbers to the beginning of each rule,
309corresponding to that rule's position in the chain.
Chapman Brad45493a82001-02-23 09:08:13 +0000310.TP
311.B "--modprobe=<command>"
312When adding or inserting rules into a chain, use
313.B command
314to load any necessary modules (targets, match extensions, etc).
Marc Bouchere6869a82000-03-20 06:03:29 +0000315.SH MATCH EXTENSIONS
Rusty Russell363112d2000-08-11 13:49:26 +0000316iptables can use extended packet matching modules. These are loaded
317in two ways: implicitly, when
318.B -p
319or
320.B --protocol
321is specified, or with the
322.B -m
323or
324.B --match
325options, followed by the matching module name; after these, various
326extra command line options become available, depending on the specific
327module. You can specify multiple extended match modules in one line, and you can use the
328.B -h
329or
330.B --help
331options after the module has been specified to receive help specific
332to that module.
333
334The following are included in the base package, and most of these can
335be preceded by a
Marc Bouchere6869a82000-03-20 06:03:29 +0000336.B !
337to invert the sense of the match.
338.SS tcp
Rusty Russell363112d2000-08-11 13:49:26 +0000339These extensions are loaded if `--protocol tcp' is specified. It
340provides the following options:
Marc Bouchere6869a82000-03-20 06:03:29 +0000341.TP
James Morris59e90fd2000-06-23 16:44:47 +0000342.BR "--source-port " "[!] [\fIport[:port]\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000343Source port or port range specification. This can either be a service
344name or a port number. An inclusive range can also be specified,
345using the format
James Morris59e90fd2000-06-23 16:44:47 +0000346.IR port : port .
Marc Bouchere6869a82000-03-20 06:03:29 +0000347If the first port is omitted, "0" is assumed; if the last is omitted,
348"65535" is assumed.
349If the second port greater then the first they will be swapped.
350The flag
351.B --sport
352is an alias for this option.
353.TP
James Morris59e90fd2000-06-23 16:44:47 +0000354.BR "--destination-port " "[!] [\fIport[:port]\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000355Destination port or port range specification. The flag
356.B --dport
357is an alias for this option.
358.TP
359.BR "--tcp-flags " "[!] \fImask\fP \fIcomp\fP"
360Match when the TCP flags are as specified. The first argument is the
361flags which we should examine, written as a comma-separated list, and
362the second argument is a comma-separated list of flags which must be
363set. Flags are:
364.BR "SYN ACK FIN RST URG PSH ALL NONE" .
365Hence the command
366.br
Marc Boucherf127a192000-03-20 08:32:15 +0000367 iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST SYN
Marc Bouchere6869a82000-03-20 06:03:29 +0000368.br
369will only match packets with the SYN flag set, and the ACK, FIN and
370RST flags unset.
371.TP
372.B "[!] --syn"
373Only match TCP packets with the SYN bit set and the ACK and FIN bits
374cleared. Such packets are used to request TCP connection initiation;
375for example, blocking such packets coming in an interface will prevent
376incoming TCP connections, but outgoing TCP connections will be
377unaffected.
378It is equivalent to \fB--tcp-flags SYN,RST,ACK SYN\fP.
379If the "!" flag precedes the "--syn", the sense of the
380option is inverted.
381.TP
382.BR "--tcp-option " "[!] \fInumber\fP"
383Match if TCP option set.
384.SS udp
Rusty Russell363112d2000-08-11 13:49:26 +0000385These extensions are loaded if `--protocol udp' is specified. It
386provides the following options:
Marc Bouchere6869a82000-03-20 06:03:29 +0000387.TP
James Morris59e90fd2000-06-23 16:44:47 +0000388.BR "--source-port " "[!] [\fIport[:port]\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000389Source port or port range specification.
390See the description of the
391.B --source-port
392option of the TCP extension for details.
393.TP
James Morris59e90fd2000-06-23 16:44:47 +0000394.BR "--destination-port " "[!] [\fIport[:port]\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000395Destination port or port range specification.
396See the description of the
397.B --destination-port
398option of the TCP extension for details.
399.SS icmp
Rusty Russell363112d2000-08-11 13:49:26 +0000400This extension is loaded if `--protocol icmp' is specified. It
401provides the following option:
Marc Bouchere6869a82000-03-20 06:03:29 +0000402.TP
403.BR "--icmp-type " "[!] \fItypename\fP"
404This allows specification of the ICMP type, which can be a numeric
405ICMP type, or one of the ICMP type names shown by the command
406.br
407 iptables -p icmp -h
408.br
409.SS mac
410.TP
411.BR "--mac-source " "[!] \fIaddress\fP"
412Match source MAC address. It must be of the form XX:XX:XX:XX:XX:XX.
413Note that this only makes sense for packets entering the
414.BR PREROUTING ,
Rusty Russell4b3c03d2000-07-03 10:11:55 +0000415.B FORWARD
Marc Bouchere6869a82000-03-20 06:03:29 +0000416or
417.B INPUT
Rusty Russell4b3c03d2000-07-03 10:11:55 +0000418chains for packets coming from an ethernet device.
Marc Bouchere6869a82000-03-20 06:03:29 +0000419.SS limit
420This module matches at a limited rate using a token bucket filter: it
Rusty Russell363112d2000-08-11 13:49:26 +0000421can be used in combination with the
422.B LOG
423target to give limited logging. A rule using this extension will
424match until this limit is reached (unless the `!' flag is used).
Marc Bouchere6869a82000-03-20 06:03:29 +0000425.TP
426.BI "--limit " "rate"
427Maximum average matching rate: specified as a number, with an optional
428`/second', `/minute', `/hour', or `/day' suffix; the default is
4293/hour.
430.TP
431.BI "--limit-burst " "number"
432The maximum initial number of packets to match: this number gets
433recharged by one every time the limit specified above is not reached,
434up to this number; the default is 5.
435.SS multiport
436This module matches a set of source or destination ports. Up to 15
437ports can be specified. It can only be used in conjunction with
438.B "-p tcp"
439or
440.BR "-p udp" .
441.TP
442.BR "--source-port" " [\fIport[,port]\fP]"
443Match if the source port is one of the given ports.
444.TP
445.BR "--destination-port" " [\fIport[,port]\fP]"
446Match if the destination port is one of the given ports.
447.TP
448.BR "--port" " [\fIport[,port]\fP]"
449Match if the both the source and destination ports are equal to each
450other and to one of the given ports.
451.SS mark
452This module matches the netfilter mark field associated with a packet
453(which can be set using the
454.B MARK
455target below).
456.TP
457.BI "--mark " "value[/mask]"
458Matches packets with the given unsigned mark value (if a mask is
459specified, this is logically ANDed with the mark before the
460comparison).
461.SS owner
462This module attempts to match various characteristics of the packet
463creator, for locally-generated packets. It is only valid in the
Rusty Russell363112d2000-08-11 13:49:26 +0000464.B OUTPUT
465chain, and even this some packets (such as ICMP ping responses) may
466have no owner, and hence never match.
Marc Bouchere6869a82000-03-20 06:03:29 +0000467.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000468.BI "--uid-owner " "userid"
Marc Bouchere6869a82000-03-20 06:03:29 +0000469Matches if the packet was created by a process with the given
470effective user id.
471.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000472.BI "--gid-owner " "groupid"
Marc Bouchere6869a82000-03-20 06:03:29 +0000473Matches if the packet was created by a process with the given
474effective group id.
475.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000476.BI "--pid-owner " "processid"
Marc Bouchere6869a82000-03-20 06:03:29 +0000477Matches if the packet was created by a process with the given
478process id.
479.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000480.BI "--sid-owner " "sessionid"
Marc Bouchere6869a82000-03-20 06:03:29 +0000481Matches if the packet was created by a process in the given session
482group.
483.SS state
484This module, when combined with connection tracking, allows access to
485the connection tracking state for this packet.
486.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000487.BI "--state " "state"
Marc Bouchere6869a82000-03-20 06:03:29 +0000488Where state is a comma separated list of the connection states to
489match. Possible states are
490.B INVALID
491meaning that the packet is associated with no known connection,
492.B ESTABLISHED
493meaning that the packet is associated with a connection which has seen
494packets in both directions,
495.B NEW
496meaning that the packet has started a new connection, or otherwise
497associated with a connection which has not seen packets in both
498directions, and
499.B RELATED
500meaning that the packet is starting a new connection, but is
501associated with an existing connection, such as an FTP data transfer,
502or an ICMP error.
503.SS unclean
504This module takes no options, but attempts to match packets which seem
505malformed or unusual. This is regarded as experimental.
506.SS tos
507This module matches the 8 bits of Type of Service field in the IP
508header (ie. including the precedence bits).
509.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000510.BI "--tos " "tos"
Marc Bouchere6869a82000-03-20 06:03:29 +0000511The argument is either a standard name, (use
512.br
513 iptables -m tos -h
514.br
515to see the list), or a numeric value to match.
516.SH TARGET EXTENSIONS
517iptables can use extended target modules: the following are included
518in the standard distribution.
519.SS LOG
520Turn on kernel logging of matching packets. When this option is set
521for a rule, the Linux kernel will print some information on all
Rusty Russell363112d2000-08-11 13:49:26 +0000522matching packets (like most IP header fields) via the kernel log
523(where it can be read with
524.I dmesg
525or
526.IR syslogd (8)).
Marc Bouchere6869a82000-03-20 06:03:29 +0000527.TP
528.BI "--log-level " "level"
529Level of logging (numeric or see \fIsyslog.conf\fP(5)).
530.TP
531.BI "--log-prefix " "prefix"
Rusty Russellf81427e2000-09-13 04:20:38 +0000532Prefix log messages with the specified prefix; up to 29 letters long,
Marc Bouchere6869a82000-03-20 06:03:29 +0000533and useful for distinguishing messages in the logs.
534.TP
535.B --log-tcp-sequence
536Log TCP sequence numbers. This is a security risk if the log is
537readable by users.
538.TP
539.B --log-tcp-options
540Log options from the TCP packet header.
541.TP
542.B --log-ip-options
543Log options from the IP packet header.
544.SS MARK
545This is used to set the netfilter mark value associated with the
546packet. It is only valid in the
547.B mangle
548table.
549.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000550.BI "--set-mark " "mark"
Marc Bouchere6869a82000-03-20 06:03:29 +0000551.SS REJECT
552This is used to send back an error packet in response to the matched
553packet: otherwise it is equivalent to
554.BR DROP .
555This target is only valid in the
556.BR INPUT ,
557.B FORWARD
558and
559.B OUTPUT
Rusty Russell9cadb432000-05-10 00:18:06 +0000560chains, and user-defined chains which are only called from those
Marc Bouchere6869a82000-03-20 06:03:29 +0000561chains. Several options control the nature of the error packet
562returned:
563.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000564.BI "--reject-with " "type"
Marc Bouchere6869a82000-03-20 06:03:29 +0000565The type given can be
566.BR icmp-net-unreachable ,
567.BR icmp-host-unreachable ,
Rusty Russell14f390f2000-07-30 01:10:04 +0000568.BR icmp-port-unreachable ,
569.BR icmp-proto-unreachable ,
570.BR icmp-net-prohibited or
571.BR icmp-host-prohibited ,
Rusty Russellddd5b3b2000-05-31 06:32:47 +0000572which return the appropriate ICMP error message (port-unreachable is
Rusty Russella1ce9f92000-03-24 08:39:16 +0000573the default). The option
Marc Bouchere6869a82000-03-20 06:03:29 +0000574.B echo-reply
Rusty Russella1ce9f92000-03-24 08:39:16 +0000575is also allowed; it can only be used for rules which specify an ICMP
Rusty Russell14f390f2000-07-30 01:10:04 +0000576ping packet, and generates a ping reply. Finally, the option
577.B tcp-reset
Rusty Russell363112d2000-08-11 13:49:26 +0000578can be used on rules which only match the TCP protocol: this causes a
579TCP RST packet to be sent back. This is mainly useful for blocking
580.I ident
581probes which frequently occur when sending mail to broken mail hosts
582(which won't accept your mail otherwise).
Marc Bouchere6869a82000-03-20 06:03:29 +0000583.SS TOS
584This is used to set the 8-bit Type of Service field in the IP header.
585It is only valid in the
586.B mangle
587table.
588.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000589.BI "--set-tos " "tos"
Marc Bouchere6869a82000-03-20 06:03:29 +0000590You can use a numeric TOS values, or use
591.br
592 iptables -j TOS -h
593.br
594to see the list of valid TOS names.
595.SS MIRROR
596This is an experimental demonstration target which inverts the source
597and destination fields in the IP header and retransmits the packet.
598It is only valid in the
599.BR INPUT ,
600.B FORWARD
601and
Rusty Russell363112d2000-08-11 13:49:26 +0000602.B PREROUTING
603chains, and user-defined chains which are only called from those
604chains. Note that the outgoing packets are
605.B NOT
606seen by any packet filtering chains, connection tracking or NAT, to
607avoid loops and other problems.
Marc Bouchere6869a82000-03-20 06:03:29 +0000608.SS SNAT
609This target is only valid in the
610.B nat
611table, in the
612.B POSTROUTING
613chain. It specifies that the source address of the packet should be
614modified (and all future packets in this connection will also be
615mangled), and rules should cease being examined. It takes one option:
616.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000617.BI "--to-source " "<ipaddr>[-<ipaddr>][:port-port]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000618which can specify a single new source IP address, an inclusive range
619of IP addresses, and optionally, a port range (which is only valid if
620the rule also specifies
621.B "-p tcp"
622or
623.BR "-p udp" ).
624If no port range is specified, then source ports below 512 will be
Harald Welte0112abb2001-02-19 21:48:13 +0000625mapped to other ports below 512: those between 512 and 1023 inclusive
626will be mapped to ports below 1024, and other ports will be mapped to
6271024 or above. Where possible, no port alteration will occur.
Marc Bouchere6869a82000-03-20 06:03:29 +0000628.SS DNAT
629This target is only valid in the
630.B nat
631table, in the
632.B PREROUTING
633and
634.B OUTPUT
Rusty Russell9cadb432000-05-10 00:18:06 +0000635chains, and user-defined chains which are only called from those
Marc Bouchere6869a82000-03-20 06:03:29 +0000636chains. It specifies that the destination address of the packet
637should be modified (and all future packets in this connection will
638also be mangled), and rules should cease being examined. It takes one
639option:
640.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000641.BI "--to-destination " "<ipaddr>[-<ipaddr>][:port-port]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000642which can specify a single new destination IP address, an inclusive
643range of IP addresses, and optionally, a port range (which is only
644valid if the rule also specifies
645.B "-p tcp"
646or
647.BR "-p udp" ).
648If no port range is specified, then the destination port will never be
649modified.
650.SS MASQUERADE
651This target is only valid in the
652.B nat
653table, in the
654.B POSTROUTING
655chain. It should only be used with dynamically assigned IP (dialup)
656connections: if you have a static IP address, you should use the SNAT
657target. Masquerading is equivalent to specifying a mapping to the IP
658address of the interface the packet is going out, but also has the
659effect that connections are
660.I forgotten
Marc Boucherf127a192000-03-20 08:32:15 +0000661when the interface goes down. This is the correct behavior when the
Marc Bouchere6869a82000-03-20 06:03:29 +0000662next dialup is unlikely to have the same interface address (and hence
663any established connections are lost anyway). It takes one option:
664.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000665.BI "--to-ports " "<port>[-<port>]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000666This specifies a range of source ports to use, overriding the default
667.B SNAT
668source port-selection heuristics (see above). This is only valid with
669if the rule also specifies
670.B "-p tcp"
671or
672.BR "-p udp" ).
673.SS REDIRECT
674This target is only valid in the
675.B nat
676table, in the
677.B PREROUTING
678and
679.B OUTPUT
Rusty Russell9cadb432000-05-10 00:18:06 +0000680chains, and user-defined chains which are only called from those
Marc Bouchere6869a82000-03-20 06:03:29 +0000681chains. It alters the destination IP address to send the packet to
682the machine itself (locally-generated packets are mapped to the
Rusty Russell9cadb432000-05-10 00:18:06 +0000683127.0.0.1 address). It takes one option:
Marc Bouchere6869a82000-03-20 06:03:29 +0000684.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000685.BI "--to-ports " "<port>[-<port>]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000686This specifies a destination port or range or ports to use: without
687this, the destination port is never altered. This is only valid with
688if the rule also specifies
689.B "-p tcp"
690or
691.BR "-p udp" ).
Rusty Russell86573e52000-10-11 06:01:13 +0000692.SH EXTRA EXTENSIONS
693The following extensions are not included by default in the standard
694distribution.
695.SS ttl
696This module matches the time to live field in the IP header.
697.TP
698.BI "--ttl " "ttl"
699Matches the given TTL value.
700.SS TTL
701This target is used to modify the time to live field in the IP header.
702It is only valid in the
703.B mangle
704table.
705.TP
706.BI "--ttl-set " "ttl"
707Set the TTL to the given value.
708.TP
709.BI "--ttl-dec " "ttl"
710Decrement the TTL by the given value.
711.TP
712.BI "--ttl-inc " "ttl"
713Increment the TTL by the given value.
Rusty Russell52451822000-08-27 07:47:46 +0000714.SS ULOG
Rusty Russell86573e52000-10-11 06:01:13 +0000715This target provides userspace logging of matching packets. When this
716target is set for a rule, the Linux kernel will multicast this packet
717through a
Rusty Russell52451822000-08-27 07:47:46 +0000718.IR netlink
Rusty Russell86573e52000-10-11 06:01:13 +0000719socket. One or more userspace processes may then subscribe to various
Rusty Russell52451822000-08-27 07:47:46 +0000720multicast groups and receive the packets.
721.TP
Harald Welte02d00ff2001-01-30 12:05:09 +0000722.BI "--ulog-nlgroup " "<nlgroup>"
Rusty Russell52451822000-08-27 07:47:46 +0000723This specifies the netlink group (1-32) to which the packet is sent.
Harald Welte02d00ff2001-01-30 12:05:09 +0000724Default value is 1.
Rusty Russell52451822000-08-27 07:47:46 +0000725.TP
Harald Welte02d00ff2001-01-30 12:05:09 +0000726.BI "--ulog-prefix " "<prefix>"
Rusty Russell52451822000-08-27 07:47:46 +0000727Prefix log messages with the specified prefix; up to 32 characters
728long, and useful fro distinguishing messages in the logs.
729.TP
Harald Welte02d00ff2001-01-30 12:05:09 +0000730.BI "--ulog-cprange " "<size>"
Rusty Russell86573e52000-10-11 06:01:13 +0000731Number of bytes to be copied to userspace. A value of 0 always copies
Harald Welte02d00ff2001-01-30 12:05:09 +0000732the entire packet, regardless of its size. Default is 0
733.TP
734.BI "--ulog-qthreshold " "<size>"
735Number of packet to queue inside kernel. Setting this value to, e.g. 10
736accumulates ten packets inside the kernel and transmits them as one
737netlink multpart message to userspace. Default is 1 (for backwards
738compatibility)
Rusty Russell86573e52000-10-11 06:01:13 +0000739.SH DIAGNOSTICS
740Various error messages are printed to standard error. The exit code
741is 0 for correct functioning. Errors which appear to be caused by
742invalid or abused command line parameters cause an exit code of 2, and
743other errors cause an exit code of 1.
Marc Bouchere6869a82000-03-20 06:03:29 +0000744.SH BUGS
745Check is not implemented (yet).
746.SH COMPATIBILITY WITH IPCHAINS
747This
748.B iptables
749is very similar to ipchains by Rusty Russell. The main difference is
750that the chains
751.B INPUT
752and
753.B OUTPUT
754are only traversed for packets coming into the local host and
755originating from the local host respectively. Hence every packet only
756passes through one of the three chains; previously a forwarded packet
757would pass through all three.
758.PP
759The other main difference is that
760.B -i
761refers to the input interface;
762.B -o
763refers to the output interface, and both are available for packets
764entering the
765.B FORWARD
766chain.
767.PP The various forms of NAT have been separated out;
768.B iptables
769is a pure packet filter when using the default `filter' table, with
770optional extension modules. This should simplify much of the previous
771confusion over the combination of IP masquerading and packet filtering
772seen previously. So the following options are handled differently:
773.br
774 -j MASQ
775.br
776 -M -S
777.br
778 -M -L
779.br
780There are several other changes in iptables.
781.SH SEE ALSO
Rusty Russell363112d2000-08-11 13:49:26 +0000782The iptables-HOWTO, which details more iptables usage, the NAT-HOWTO,
783which details NAT, and the netfilter-hacking-HOWTO which details the
784internals.
Marc Boucherf127a192000-03-20 08:32:15 +0000785.SH AUTHORS
Marc Bouchere6869a82000-03-20 06:03:29 +0000786Rusty Russell wrote iptables, in early consultation with Michael
787Neuling.
788.PP
Marc Boucherf127a192000-03-20 08:32:15 +0000789Marc Boucher made Rusty abandon ipnatctl by lobbying for a generic packet
790selection framework in iptables, then wrote the mangle table, the owner match,
791the mark stuff, and ran around doing cool stuff everywhere.
Marc Bouchere6869a82000-03-20 06:03:29 +0000792.PP
793James Morris wrote the TOS target, and tos match.
794.PP
795Jozsef Kadlecsik wrote the REJECT target.
796.PP
Rusty Russell86573e52000-10-11 06:01:13 +0000797Harald Welte wrote the ULOG target, TTL match+target and libipulog.
Rusty Russell52451822000-08-27 07:47:46 +0000798.PP
Rusty Russellf61bb5f2000-10-13 07:11:24 +0000799The Netfilter Core Team is: Marc Boucher, James Morris, Harald Welte
800and Rusty Russell.
Marc Bouchere6869a82000-03-20 06:03:29 +0000801.\" .. and did I mention that we are incredibly cool people?
Rusty Russell363112d2000-08-11 13:49:26 +0000802.\" .. sexy, too ..
Rusty Russell86573e52000-10-11 06:01:13 +0000803.\" .. witty, charming, powerful ..
James Morris060ae4c2000-10-29 01:29:57 +0000804.\" .. and most of all, modest ..