blob: c2b451f5dfae2308f528e6abcf1436909990e85e [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
43filter rules in the Linux kernel. There are several different tables
44which may be defined, and each table contains a number of built-in
45chains, and may contain user-defined chains.
46
47Each chain is a list of rules which can match a set of packets: each
48rule specifies what to do with a packet which matches. This is called
49a `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
56target, which can be the name of a user-defined chain, or one of the
57special 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
71means 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,
73or 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"
90This is the default table, and contains the built-in chains INPUT (for
91packets coming into the box itself), FORWARD (for packets being routed
92through the box), and OUTPUT (for locally-generated packets).
93.BR "nat"
94This table is consulted when a packet which is creates a new
95connection 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
109These options specify the specific action to perform; only one of them
110can be specified on the command line, unless otherwise specified
111below. For all the long versions of the command and option names, you
112only need to use enough letters to ensure that
113.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
142listed and zeroed. The exact output is effected by the other
143arguments 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
154cleared; see above.
155.TP
156.B "-N, --new-chain"
157Create a new user-defined chain of the given name. There must be no
158target of that name already.
159.TP
160.B "-X, --delete-chain"
161Delete the specified user-defined chain. There must be no references
162to 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"
173Rename the user specified chain to the user supplied name; this is
174cosmetic, 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
181add, delete, replace, append and check commands).
182.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"
227This specifies the target of the rule; ie. what to do if the packet
228matches it. The target can be a user-defined chain (not the one this
229rule is in), one of the special builtin targets which decide the fate
230of the packet immediately, or an extension (see
231.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.
Marc Bouchere6869a82000-03-20 06:03:29 +0000270.SS "OTHER OPTIONS"
271The following additional options can be specified:
272.TP
273.B "-v, --verbose"
274Verbose output. This option makes the list command show the interface
275address, the rule options (if any), and the TOS masks. The packet and
276byte counters are also listed, with the suffix 'K', 'M' or 'G' for
2771000, 1,000,000 and 1,000,000,000 multipliers respectively (but see
278the
279.B -x
280flag to change this).
281For appending, insertion, deletion and replacement, this causes
282detailed information on the rule or rules to be printed.
283.TP
284.B "-n, --numeric"
285Numeric output.
286IP addresses and port numbers will be printed in numeric format.
287By default, the program will try to display them as host names,
288network names, or services (whenever applicable).
289.TP
290.B "-x, --exact"
291Expand numbers.
292Display the exact value of the packet and byte counters,
293instead of only the rounded number in K's (multiples of 1000)
294M's (multiples of 1000K) or G's (multiples of 1000M). This option is
Marc Boucherf127a192000-03-20 08:32:15 +0000295only relevant for the
Marc Bouchere6869a82000-03-20 06:03:29 +0000296.B -L
297command.
298.TP
299.B "--line-numbers"
300When listing rules, add line numbers to the beginning of each rule,
301corresponding to that rule's position in the chain.
302.SH MATCH EXTENSIONS
Rusty Russell363112d2000-08-11 13:49:26 +0000303iptables can use extended packet matching modules. These are loaded
304in two ways: implicitly, when
305.B -p
306or
307.B --protocol
308is specified, or with the
309.B -m
310or
311.B --match
312options, followed by the matching module name; after these, various
313extra command line options become available, depending on the specific
314module. You can specify multiple extended match modules in one line, and you can use the
315.B -h
316or
317.B --help
318options after the module has been specified to receive help specific
319to that module.
320
321The following are included in the base package, and most of these can
322be preceded by a
Marc Bouchere6869a82000-03-20 06:03:29 +0000323.B !
324to invert the sense of the match.
325.SS tcp
Rusty Russell363112d2000-08-11 13:49:26 +0000326These extensions are loaded if `--protocol tcp' is specified. It
327provides the following options:
Marc Bouchere6869a82000-03-20 06:03:29 +0000328.TP
James Morris59e90fd2000-06-23 16:44:47 +0000329.BR "--source-port " "[!] [\fIport[:port]\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000330Source port or port range specification. This can either be a service
331name or a port number. An inclusive range can also be specified,
332using the format
James Morris59e90fd2000-06-23 16:44:47 +0000333.IR port : port .
Marc Bouchere6869a82000-03-20 06:03:29 +0000334If the first port is omitted, "0" is assumed; if the last is omitted,
335"65535" is assumed.
336If the second port greater then the first they will be swapped.
337The flag
338.B --sport
339is an alias for this option.
340.TP
James Morris59e90fd2000-06-23 16:44:47 +0000341.BR "--destination-port " "[!] [\fIport[:port]\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000342Destination port or port range specification. The flag
343.B --dport
344is an alias for this option.
345.TP
346.BR "--tcp-flags " "[!] \fImask\fP \fIcomp\fP"
347Match when the TCP flags are as specified. The first argument is the
348flags which we should examine, written as a comma-separated list, and
349the second argument is a comma-separated list of flags which must be
350set. Flags are:
351.BR "SYN ACK FIN RST URG PSH ALL NONE" .
352Hence the command
353.br
Marc Boucherf127a192000-03-20 08:32:15 +0000354 iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST SYN
Marc Bouchere6869a82000-03-20 06:03:29 +0000355.br
356will only match packets with the SYN flag set, and the ACK, FIN and
357RST flags unset.
358.TP
359.B "[!] --syn"
360Only match TCP packets with the SYN bit set and the ACK and FIN bits
361cleared. Such packets are used to request TCP connection initiation;
362for example, blocking such packets coming in an interface will prevent
363incoming TCP connections, but outgoing TCP connections will be
364unaffected.
365It is equivalent to \fB--tcp-flags SYN,RST,ACK SYN\fP.
366If the "!" flag precedes the "--syn", the sense of the
367option is inverted.
368.TP
369.BR "--tcp-option " "[!] \fInumber\fP"
370Match if TCP option set.
371.SS udp
Rusty Russell363112d2000-08-11 13:49:26 +0000372These extensions are loaded if `--protocol udp' is specified. It
373provides the following options:
Marc Bouchere6869a82000-03-20 06:03:29 +0000374.TP
James Morris59e90fd2000-06-23 16:44:47 +0000375.BR "--source-port " "[!] [\fIport[:port]\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000376Source port or port range specification.
377See the description of the
378.B --source-port
379option of the TCP extension for details.
380.TP
James Morris59e90fd2000-06-23 16:44:47 +0000381.BR "--destination-port " "[!] [\fIport[:port]\fP]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000382Destination port or port range specification.
383See the description of the
384.B --destination-port
385option of the TCP extension for details.
386.SS icmp
Rusty Russell363112d2000-08-11 13:49:26 +0000387This extension is loaded if `--protocol icmp' is specified. It
388provides the following option:
Marc Bouchere6869a82000-03-20 06:03:29 +0000389.TP
390.BR "--icmp-type " "[!] \fItypename\fP"
391This allows specification of the ICMP type, which can be a numeric
392ICMP type, or one of the ICMP type names shown by the command
393.br
394 iptables -p icmp -h
395.br
396.SS mac
397.TP
398.BR "--mac-source " "[!] \fIaddress\fP"
399Match source MAC address. It must be of the form XX:XX:XX:XX:XX:XX.
400Note that this only makes sense for packets entering the
401.BR PREROUTING ,
Rusty Russell4b3c03d2000-07-03 10:11:55 +0000402.B FORWARD
Marc Bouchere6869a82000-03-20 06:03:29 +0000403or
404.B INPUT
Rusty Russell4b3c03d2000-07-03 10:11:55 +0000405chains for packets coming from an ethernet device.
Marc Bouchere6869a82000-03-20 06:03:29 +0000406.SS limit
407This module matches at a limited rate using a token bucket filter: it
Rusty Russell363112d2000-08-11 13:49:26 +0000408can be used in combination with the
409.B LOG
410target to give limited logging. A rule using this extension will
411match until this limit is reached (unless the `!' flag is used).
Marc Bouchere6869a82000-03-20 06:03:29 +0000412.TP
413.BI "--limit " "rate"
414Maximum average matching rate: specified as a number, with an optional
415`/second', `/minute', `/hour', or `/day' suffix; the default is
4163/hour.
417.TP
418.BI "--limit-burst " "number"
419The maximum initial number of packets to match: this number gets
420recharged by one every time the limit specified above is not reached,
421up to this number; the default is 5.
422.SS multiport
423This module matches a set of source or destination ports. Up to 15
424ports can be specified. It can only be used in conjunction with
425.B "-p tcp"
426or
427.BR "-p udp" .
428.TP
429.BR "--source-port" " [\fIport[,port]\fP]"
430Match if the source port is one of the given ports.
431.TP
432.BR "--destination-port" " [\fIport[,port]\fP]"
433Match if the destination port is one of the given ports.
434.TP
435.BR "--port" " [\fIport[,port]\fP]"
436Match if the both the source and destination ports are equal to each
437other and to one of the given ports.
438.SS mark
439This module matches the netfilter mark field associated with a packet
440(which can be set using the
441.B MARK
442target below).
443.TP
444.BI "--mark " "value[/mask]"
445Matches packets with the given unsigned mark value (if a mask is
446specified, this is logically ANDed with the mark before the
447comparison).
448.SS owner
449This module attempts to match various characteristics of the packet
450creator, for locally-generated packets. It is only valid in the
Rusty Russell363112d2000-08-11 13:49:26 +0000451.B OUTPUT
452chain, and even this some packets (such as ICMP ping responses) may
453have no owner, and hence never match.
Marc Bouchere6869a82000-03-20 06:03:29 +0000454.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000455.BI "--uid-owner " "userid"
Marc Bouchere6869a82000-03-20 06:03:29 +0000456Matches if the packet was created by a process with the given
457effective user id.
458.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000459.BI "--gid-owner " "groupid"
Marc Bouchere6869a82000-03-20 06:03:29 +0000460Matches if the packet was created by a process with the given
461effective group id.
462.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000463.BI "--pid-owner " "processid"
Marc Bouchere6869a82000-03-20 06:03:29 +0000464Matches if the packet was created by a process with the given
465process id.
466.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000467.BI "--sid-owner " "sessionid"
Marc Bouchere6869a82000-03-20 06:03:29 +0000468Matches if the packet was created by a process in the given session
469group.
470.SS state
471This module, when combined with connection tracking, allows access to
472the connection tracking state for this packet.
473.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000474.BI "--state " "state"
Marc Bouchere6869a82000-03-20 06:03:29 +0000475Where state is a comma separated list of the connection states to
476match. Possible states are
477.B INVALID
478meaning that the packet is associated with no known connection,
479.B ESTABLISHED
480meaning that the packet is associated with a connection which has seen
481packets in both directions,
482.B NEW
483meaning that the packet has started a new connection, or otherwise
484associated with a connection which has not seen packets in both
485directions, and
486.B RELATED
487meaning that the packet is starting a new connection, but is
488associated with an existing connection, such as an FTP data transfer,
489or an ICMP error.
490.SS unclean
491This module takes no options, but attempts to match packets which seem
492malformed or unusual. This is regarded as experimental.
493.SS tos
494This module matches the 8 bits of Type of Service field in the IP
495header (ie. including the precedence bits).
496.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000497.BI "--tos " "tos"
Marc Bouchere6869a82000-03-20 06:03:29 +0000498The argument is either a standard name, (use
499.br
500 iptables -m tos -h
501.br
502to see the list), or a numeric value to match.
503.SH TARGET EXTENSIONS
504iptables can use extended target modules: the following are included
505in the standard distribution.
506.SS LOG
507Turn on kernel logging of matching packets. When this option is set
508for a rule, the Linux kernel will print some information on all
Rusty Russell363112d2000-08-11 13:49:26 +0000509matching packets (like most IP header fields) via the kernel log
510(where it can be read with
511.I dmesg
512or
513.IR syslogd (8)).
Marc Bouchere6869a82000-03-20 06:03:29 +0000514.TP
515.BI "--log-level " "level"
516Level of logging (numeric or see \fIsyslog.conf\fP(5)).
517.TP
518.BI "--log-prefix " "prefix"
Rusty Russellf81427e2000-09-13 04:20:38 +0000519Prefix log messages with the specified prefix; up to 29 letters long,
Marc Bouchere6869a82000-03-20 06:03:29 +0000520and useful for distinguishing messages in the logs.
521.TP
522.B --log-tcp-sequence
523Log TCP sequence numbers. This is a security risk if the log is
524readable by users.
525.TP
526.B --log-tcp-options
527Log options from the TCP packet header.
528.TP
529.B --log-ip-options
530Log options from the IP packet header.
531.SS MARK
532This is used to set the netfilter mark value associated with the
533packet. It is only valid in the
534.B mangle
535table.
536.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000537.BI "--set-mark " "mark"
Marc Bouchere6869a82000-03-20 06:03:29 +0000538.SS REJECT
539This is used to send back an error packet in response to the matched
540packet: otherwise it is equivalent to
541.BR DROP .
542This target is only valid in the
543.BR INPUT ,
544.B FORWARD
545and
546.B OUTPUT
Rusty Russell9cadb432000-05-10 00:18:06 +0000547chains, and user-defined chains which are only called from those
Marc Bouchere6869a82000-03-20 06:03:29 +0000548chains. Several options control the nature of the error packet
549returned:
550.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000551.BI "--reject-with " "type"
Marc Bouchere6869a82000-03-20 06:03:29 +0000552The type given can be
553.BR icmp-net-unreachable ,
554.BR icmp-host-unreachable ,
Rusty Russell14f390f2000-07-30 01:10:04 +0000555.BR icmp-port-unreachable ,
556.BR icmp-proto-unreachable ,
557.BR icmp-net-prohibited or
558.BR icmp-host-prohibited ,
Rusty Russellddd5b3b2000-05-31 06:32:47 +0000559which return the appropriate ICMP error message (port-unreachable is
Rusty Russella1ce9f92000-03-24 08:39:16 +0000560the default). The option
Marc Bouchere6869a82000-03-20 06:03:29 +0000561.B echo-reply
Rusty Russella1ce9f92000-03-24 08:39:16 +0000562is also allowed; it can only be used for rules which specify an ICMP
Rusty Russell14f390f2000-07-30 01:10:04 +0000563ping packet, and generates a ping reply. Finally, the option
564.B tcp-reset
Rusty Russell363112d2000-08-11 13:49:26 +0000565can be used on rules which only match the TCP protocol: this causes a
566TCP RST packet to be sent back. This is mainly useful for blocking
567.I ident
568probes which frequently occur when sending mail to broken mail hosts
569(which won't accept your mail otherwise).
Marc Bouchere6869a82000-03-20 06:03:29 +0000570.SS TOS
571This is used to set the 8-bit Type of Service field in the IP header.
572It is only valid in the
573.B mangle
574table.
575.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000576.BI "--set-tos " "tos"
Marc Bouchere6869a82000-03-20 06:03:29 +0000577You can use a numeric TOS values, or use
578.br
579 iptables -j TOS -h
580.br
581to see the list of valid TOS names.
582.SS MIRROR
583This is an experimental demonstration target which inverts the source
584and destination fields in the IP header and retransmits the packet.
585It is only valid in the
586.BR INPUT ,
587.B FORWARD
588and
Rusty Russell363112d2000-08-11 13:49:26 +0000589.B PREROUTING
590chains, and user-defined chains which are only called from those
591chains. Note that the outgoing packets are
592.B NOT
593seen by any packet filtering chains, connection tracking or NAT, to
594avoid loops and other problems.
Marc Bouchere6869a82000-03-20 06:03:29 +0000595.SS SNAT
596This target is only valid in the
597.B nat
598table, in the
599.B POSTROUTING
600chain. It specifies that the source address of the packet should be
601modified (and all future packets in this connection will also be
602mangled), and rules should cease being examined. It takes one option:
603.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000604.BI "--to-source " "<ipaddr>[-<ipaddr>][:port-port]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000605which can specify a single new source IP address, an inclusive range
606of IP addresses, and optionally, a port range (which is only valid if
607the rule also specifies
608.B "-p tcp"
609or
610.BR "-p udp" ).
611If no port range is specified, then source ports below 512 will be
612mapped to other ports below 512: those between 1024 will be mapped to
613ports below 1024, and other ports will be mapped to 1024 or above.
614Where possible, no port alteration will occur.
615.SS DNAT
616This target is only valid in the
617.B nat
618table, in the
619.B PREROUTING
620and
621.B OUTPUT
Rusty Russell9cadb432000-05-10 00:18:06 +0000622chains, and user-defined chains which are only called from those
Marc Bouchere6869a82000-03-20 06:03:29 +0000623chains. It specifies that the destination address of the packet
624should be modified (and all future packets in this connection will
625also be mangled), and rules should cease being examined. It takes one
626option:
627.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000628.BI "--to-destination " "<ipaddr>[-<ipaddr>][:port-port]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000629which can specify a single new destination IP address, an inclusive
630range of IP addresses, and optionally, a port range (which is only
631valid if the rule also specifies
632.B "-p tcp"
633or
634.BR "-p udp" ).
635If no port range is specified, then the destination port will never be
636modified.
637.SS MASQUERADE
638This target is only valid in the
639.B nat
640table, in the
641.B POSTROUTING
642chain. It should only be used with dynamically assigned IP (dialup)
643connections: if you have a static IP address, you should use the SNAT
644target. Masquerading is equivalent to specifying a mapping to the IP
645address of the interface the packet is going out, but also has the
646effect that connections are
647.I forgotten
Marc Boucherf127a192000-03-20 08:32:15 +0000648when the interface goes down. This is the correct behavior when the
Marc Bouchere6869a82000-03-20 06:03:29 +0000649next dialup is unlikely to have the same interface address (and hence
650any established connections are lost anyway). It takes one option:
651.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000652.BI "--to-ports " "<port>[-<port>]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000653This specifies a range of source ports to use, overriding the default
654.B SNAT
655source port-selection heuristics (see above). This is only valid with
656if the rule also specifies
657.B "-p tcp"
658or
659.BR "-p udp" ).
660.SS REDIRECT
661This target is only valid in the
662.B nat
663table, in the
664.B PREROUTING
665and
666.B OUTPUT
Rusty Russell9cadb432000-05-10 00:18:06 +0000667chains, and user-defined chains which are only called from those
Marc Bouchere6869a82000-03-20 06:03:29 +0000668chains. It alters the destination IP address to send the packet to
669the machine itself (locally-generated packets are mapped to the
Rusty Russell9cadb432000-05-10 00:18:06 +0000670127.0.0.1 address). It takes one option:
Marc Bouchere6869a82000-03-20 06:03:29 +0000671.TP
Bert Hubert20ecf7a2000-03-24 01:56:37 +0000672.BI "--to-ports " "<port>[-<port>]"
Marc Bouchere6869a82000-03-20 06:03:29 +0000673This specifies a destination port or range or ports to use: without
674this, the destination port is never altered. This is only valid with
675if the rule also specifies
676.B "-p tcp"
677or
678.BR "-p udp" ).
Rusty Russell86573e52000-10-11 06:01:13 +0000679.SH EXTRA EXTENSIONS
680The following extensions are not included by default in the standard
681distribution.
682.SS ttl
683This module matches the time to live field in the IP header.
684.TP
685.BI "--ttl " "ttl"
686Matches the given TTL value.
687.SS TTL
688This target is used to modify the time to live field in the IP header.
689It is only valid in the
690.B mangle
691table.
692.TP
693.BI "--ttl-set " "ttl"
694Set the TTL to the given value.
695.TP
696.BI "--ttl-dec " "ttl"
697Decrement the TTL by the given value.
698.TP
699.BI "--ttl-inc " "ttl"
700Increment the TTL by the given value.
Rusty Russell52451822000-08-27 07:47:46 +0000701.SS ULOG
Rusty Russell86573e52000-10-11 06:01:13 +0000702This target provides userspace logging of matching packets. When this
703target is set for a rule, the Linux kernel will multicast this packet
704through a
Rusty Russell52451822000-08-27 07:47:46 +0000705.IR netlink
Rusty Russell86573e52000-10-11 06:01:13 +0000706socket. One or more userspace processes may then subscribe to various
Rusty Russell52451822000-08-27 07:47:46 +0000707multicast groups and receive the packets.
708.TP
709.BI "--ulog-nlgroup" "<nlgroup>"
710This specifies the netlink group (1-32) to which the packet is sent.
711.TP
712.BI "--ulog-prefix" "<prefix>"
713Prefix log messages with the specified prefix; up to 32 characters
714long, and useful fro distinguishing messages in the logs.
715.TP
716.BI "--ulog-cprange" "<size>"
Rusty Russell86573e52000-10-11 06:01:13 +0000717Number of bytes to be copied to userspace. A value of 0 always copies
Rusty Russell52451822000-08-27 07:47:46 +0000718the entire packet, regardless of its size.
Rusty Russell86573e52000-10-11 06:01:13 +0000719.SH DIAGNOSTICS
720Various error messages are printed to standard error. The exit code
721is 0 for correct functioning. Errors which appear to be caused by
722invalid or abused command line parameters cause an exit code of 2, and
723other errors cause an exit code of 1.
Marc Bouchere6869a82000-03-20 06:03:29 +0000724.SH BUGS
725Check is not implemented (yet).
726.SH COMPATIBILITY WITH IPCHAINS
727This
728.B iptables
729is very similar to ipchains by Rusty Russell. The main difference is
730that the chains
731.B INPUT
732and
733.B OUTPUT
734are only traversed for packets coming into the local host and
735originating from the local host respectively. Hence every packet only
736passes through one of the three chains; previously a forwarded packet
737would pass through all three.
738.PP
739The other main difference is that
740.B -i
741refers to the input interface;
742.B -o
743refers to the output interface, and both are available for packets
744entering the
745.B FORWARD
746chain.
747.PP The various forms of NAT have been separated out;
748.B iptables
749is a pure packet filter when using the default `filter' table, with
750optional extension modules. This should simplify much of the previous
751confusion over the combination of IP masquerading and packet filtering
752seen previously. So the following options are handled differently:
753.br
754 -j MASQ
755.br
756 -M -S
757.br
758 -M -L
759.br
760There are several other changes in iptables.
761.SH SEE ALSO
Rusty Russell363112d2000-08-11 13:49:26 +0000762The iptables-HOWTO, which details more iptables usage, the NAT-HOWTO,
763which details NAT, and the netfilter-hacking-HOWTO which details the
764internals.
Marc Boucherf127a192000-03-20 08:32:15 +0000765.SH AUTHORS
Marc Bouchere6869a82000-03-20 06:03:29 +0000766Rusty Russell wrote iptables, in early consultation with Michael
767Neuling.
768.PP
Marc Boucherf127a192000-03-20 08:32:15 +0000769Marc Boucher made Rusty abandon ipnatctl by lobbying for a generic packet
770selection framework in iptables, then wrote the mangle table, the owner match,
771the mark stuff, and ran around doing cool stuff everywhere.
Marc Bouchere6869a82000-03-20 06:03:29 +0000772.PP
773James Morris wrote the TOS target, and tos match.
774.PP
775Jozsef Kadlecsik wrote the REJECT target.
776.PP
Rusty Russell86573e52000-10-11 06:01:13 +0000777Harald Welte wrote the ULOG target, TTL match+target and libipulog.
Rusty Russell52451822000-08-27 07:47:46 +0000778.PP
Rusty Russell363112d2000-08-11 13:49:26 +0000779The Netfilter Core Team is: Marc Boucher, James Morris and Rusty Russell.
Marc Bouchere6869a82000-03-20 06:03:29 +0000780.\" .. and did I mention that we are incredibly cool people?
Rusty Russell363112d2000-08-11 13:49:26 +0000781.\" .. sexy, too ..
Rusty Russell86573e52000-10-11 06:01:13 +0000782.\" .. witty, charming, powerful ..