blob: a4e44a3519fe060d6d6f60f051039dd49de99452 [file] [log] [blame]
Marc Bouchere6869a82000-03-20 06:03:29 +00001.TH IPTABLES 8 "Mar 20, 2000" "" ""
2.\"
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
69means to pass the packet to userspace.
70.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
78There are current three tables (which tables are present at any time
79depends on the kernel configuration options and which modules are
80present).
81.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
164will attempt to delete every non-builtin chain.
165.TP
166.B "-P, --policy"
167Set the policy for the chain to the given target. See the section
168.TP
169.B "-E, --rename-chain"
170Rename the user specified chain to the user supplied name; this is
171cosmetic, and has no effect on the structure of the table.
172.B TARGETS
173for the legal targets. Only non-userdefined chains can have policies,
174and neither built-in nor user-defined chains can be policy targets.
175.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
183.BR "-p, --proto " "[!] \fIprotocol\fP"
184The 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
192different one. Also a protocol name from /etc/protocols is allowed.
193A "!" 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.
200.I All
201may not be used in in combination with the check command.
202.TP
203.BR "-s, --source " "[!] \fIaddress\fP[/\fImask\fP]"
204Source specification.
205.I Address
206can be either a hostname, a network name, or a plain IP address.
207The
208.I mask
209can be either a network mask or a plain number,
210specifying the number of 1's at the left side of the network mask.
211Thus, a mask of
212.I 24
213is equivalent to
214.IR 255.255.255.0 .
215A "!" argument before the address specification inverts the sense of
216the address. The flag
217.B --src
218is a convenient alias for this option.
219.TP
220.BR "-d, --destination " "[!] \fIaddress\fP[/\fImask\fP]"
221Destination specification.
222See the description of the
223.B -s
224(source) flag for a detailed description of the syntax. The flag
225.B --dst
226is an alias for this option.
227.TP
228.BI "-j, --jump " "target"
229This specifies the target of the rule; ie. what to do if the packet
230matches it. The target can be a user-defined chain (not the one this
231rule is in), one of the special builtin targets which decide the fate
232of the packet immediately, or an extension (see
233.B EXTENSIONS
234below). If this
235option is omitted in a rule, then matching the rule will have no
236effect on the packet's fate, but the counters on the rule will be
237incremented.
238.TP
239.BR "-i, --in-interface " "[!] [\fIname\fP]"
240Optional name of an interface via which a packet is received (for
241packets entering the
242.BR INPUT ,
243.B FORWARD
244and
245.B PREROUTING
246chains). When the "!" argument is used before the interface name, the
247sense is inverted. If the interface name ends in a "+", then any
248interface which begins with this name will match. If this option is
249omitted, the string "+" is assumed, which will match with any
250interface name.
251.TP
252.BR "-o, --out-interface " "[!] [\fIname\fP]"
253Optional name of an interface via which a packet is going to
254be sent (for packets entering the
255.BR FORWARD ,
256.B OUTPUT
257and
258.B POSTROUTING
259chains). When the "!" argument is used before the interface name,
260the sense is inverted. If the interface name ends in a "+", then any
261interface which begins with this name will match. If this option is
262omitted, the string "+" is assumed, which will match with any
263interface name.
264.TP
265.B "[!] " "-f, --fragment"
266This means that the rule only refers to second and further fragments
267of fragmented packets. Since there is no way to tell the source or
268destination ports of such a packet (or ICMP type), such a packet will
269not match any rules which specify them. When the "!" argument
270precedes the "-f" flag, the sense is inverted.
271.SS "OTHER OPTIONS"
272The following additional options can be specified:
273.TP
274.B "-v, --verbose"
275Verbose output. This option makes the list command show the interface
276address, the rule options (if any), and the TOS masks. The packet and
277byte counters are also listed, with the suffix 'K', 'M' or 'G' for
2781000, 1,000,000 and 1,000,000,000 multipliers respectively (but see
279the
280.B -x
281flag to change this).
282For appending, insertion, deletion and replacement, this causes
283detailed information on the rule or rules to be printed.
284.TP
285.B "-n, --numeric"
286Numeric output.
287IP addresses and port numbers will be printed in numeric format.
288By default, the program will try to display them as host names,
289network names, or services (whenever applicable).
290.TP
291.B "-x, --exact"
292Expand numbers.
293Display the exact value of the packet and byte counters,
294instead of only the rounded number in K's (multiples of 1000)
295M's (multiples of 1000K) or G's (multiples of 1000M). This option is
296only relevent for the
297.B -L
298command.
299.TP
300.B "--line-numbers"
301When listing rules, add line numbers to the beginning of each rule,
302corresponding to that rule's position in the chain.
303.SH MATCH EXTENSIONS
304iptables can use extended packet matching modules. The following are
305included in the base package, and most of these can be preceeded by a
306.B !
307to invert the sense of the match.
308.SS tcp
309These extensions are loaded if `--protocol tcp' is specified, and no
310other match is specified. It provides the following options:
311.TP
312.BR "--source-port " "[!] [\fIport[:port]\fP] or [\fIport[-port]]\fP]"
313Source port or port range specification. This can either be a service
314name or a port number. An inclusive range can also be specified,
315using the format
316.IR port : port
317or
318.IR port - port .
319If the first port is omitted, "0" is assumed; if the last is omitted,
320"65535" is assumed.
321If the second port greater then the first they will be swapped.
322The flag
323.B --sport
324is an alias for this option.
325.TP
326.BR "--destination-port " "[!] [\fIport[:port]\fP] or [\fIport[-port]]\fP"
327Destination port or port range specification. The flag
328.B --dport
329is an alias for this option.
330.TP
331.BR "--tcp-flags " "[!] \fImask\fP \fIcomp\fP"
332Match when the TCP flags are as specified. The first argument is the
333flags which we should examine, written as a comma-separated list, and
334the second argument is a comma-separated list of flags which must be
335set. Flags are:
336.BR "SYN ACK FIN RST URG PSH ALL NONE" .
337Hence the command
338.br
339 ipchains -p tcp --tcp-flags SYN,ACK,FIN,RST SYN
340.br
341will only match packets with the SYN flag set, and the ACK, FIN and
342RST flags unset.
343.TP
344.B "[!] --syn"
345Only match TCP packets with the SYN bit set and the ACK and FIN bits
346cleared. Such packets are used to request TCP connection initiation;
347for example, blocking such packets coming in an interface will prevent
348incoming TCP connections, but outgoing TCP connections will be
349unaffected.
350It is equivalent to \fB--tcp-flags SYN,RST,ACK SYN\fP.
351If the "!" flag precedes the "--syn", the sense of the
352option is inverted.
353.TP
354.BR "--tcp-option " "[!] \fInumber\fP"
355Match if TCP option set.
356.SS udp
357These extensions are loaded if `--protocol udp' is specified, and no
358other match is specified. It provides the following options:
359.TP
360.BR "--source-port " "[!] [\fIport[:port]\fP] or [\fIport[-port]]\fP"
361Source port or port range specification.
362See the description of the
363.B --source-port
364option of the TCP extension for details.
365.TP
366.BR "--destination-port " "[!] [\fIport[:port]\fP] or [\fIport[-port]]\fP"
367Destination port or port range specification.
368See the description of the
369.B --destination-port
370option of the TCP extension for details.
371.SS icmp
372This extension is loaded if `--protocol icmp' is specified, and no
373other match is specified. It provides the following option:
374.TP
375.BR "--icmp-type " "[!] \fItypename\fP"
376This allows specification of the ICMP type, which can be a numeric
377ICMP type, or one of the ICMP type names shown by the command
378.br
379 iptables -p icmp -h
380.br
381.SS mac
382.TP
383.BR "--mac-source " "[!] \fIaddress\fP"
384Match source MAC address. It must be of the form XX:XX:XX:XX:XX:XX.
385Note that this only makes sense for packets entering the
386.BR PREROUTING ,
387or
388.B INPUT
389chains from an ethernet device.
390.SS limit
391This module matches at a limited rate using a token bucket filter: it
392can be used in combination with the LOG target to give limited
393logging. A rule using this extension will match until this limit is
394reached (unless the `!' flag is used).
395.TP
396.BI "--limit " "rate"
397Maximum average matching rate: specified as a number, with an optional
398`/second', `/minute', `/hour', or `/day' suffix; the default is
3993/hour.
400.TP
401.BI "--limit-burst " "number"
402The maximum initial number of packets to match: this number gets
403recharged by one every time the limit specified above is not reached,
404up to this number; the default is 5.
405.SS multiport
406This module matches a set of source or destination ports. Up to 15
407ports can be specified. It can only be used in conjunction with
408.B "-p tcp"
409or
410.BR "-p udp" .
411.TP
412.BR "--source-port" " [\fIport[,port]\fP]"
413Match if the source port is one of the given ports.
414.TP
415.BR "--destination-port" " [\fIport[,port]\fP]"
416Match if the destination port is one of the given ports.
417.TP
418.BR "--port" " [\fIport[,port]\fP]"
419Match if the both the source and destination ports are equal to each
420other and to one of the given ports.
421.SS mark
422This module matches the netfilter mark field associated with a packet
423(which can be set using the
424.B MARK
425target below).
426.TP
427.BI "--mark " "value[/mask]"
428Matches packets with the given unsigned mark value (if a mask is
429specified, this is logically ANDed with the mark before the
430comparison).
431.SS owner
432This module attempts to match various characteristics of the packet
433creator, for locally-generated packets. It is only valid in the
434OUTPUT chain, and even this some packets (such as ICMP ping responses)
435may have no owner, and hence never match.
436.TP
437.BI "--uid-owner" "userid"
438Matches if the packet was created by a process with the given
439effective user id.
440.TP
441.BI "--gid-owner" "groupid"
442Matches if the packet was created by a process with the given
443effective group id.
444.TP
445.BI "--pid-owner" "processid"
446Matches if the packet was created by a process with the given
447process id.
448.TP
449.BI "--sid-owner" "sessionid"
450Matches if the packet was created by a process in the given session
451group.
452.SS state
453This module, when combined with connection tracking, allows access to
454the connection tracking state for this packet.
455.TP
456.BI "--state" "state"
457Where state is a comma separated list of the connection states to
458match. Possible states are
459.B INVALID
460meaning that the packet is associated with no known connection,
461.B ESTABLISHED
462meaning that the packet is associated with a connection which has seen
463packets in both directions,
464.B NEW
465meaning that the packet has started a new connection, or otherwise
466associated with a connection which has not seen packets in both
467directions, and
468.B RELATED
469meaning that the packet is starting a new connection, but is
470associated with an existing connection, such as an FTP data transfer,
471or an ICMP error.
472.SS unclean
473This module takes no options, but attempts to match packets which seem
474malformed or unusual. This is regarded as experimental.
475.SS tos
476This module matches the 8 bits of Type of Service field in the IP
477header (ie. including the precedence bits).
478.TP
479.BI "--tos" "tos"
480The argument is either a standard name, (use
481.br
482 iptables -m tos -h
483.br
484to see the list), or a numeric value to match.
485.SH TARGET EXTENSIONS
486iptables can use extended target modules: the following are included
487in the standard distribution.
488.SS LOG
489Turn on kernel logging of matching packets. When this option is set
490for a rule, the Linux kernel will print some information on all
491matching packets (like most IP header fields) via
492.IR printk ().
493.TP
494.BI "--log-level " "level"
495Level of logging (numeric or see \fIsyslog.conf\fP(5)).
496.TP
497.BI "--log-prefix " "prefix"
498Prefix log messages with the specified prefix; up to 14 letters long,
499and useful for distinguishing messages in the logs.
500.TP
501.B --log-tcp-sequence
502Log TCP sequence numbers. This is a security risk if the log is
503readable by users.
504.TP
505.B --log-tcp-options
506Log options from the TCP packet header.
507.TP
508.B --log-ip-options
509Log options from the IP packet header.
510.SS MARK
511This is used to set the netfilter mark value associated with the
512packet. It is only valid in the
513.B mangle
514table.
515.TP
516.BI "--set-mark" "mark"
517.SS REJECT
518This is used to send back an error packet in response to the matched
519packet: otherwise it is equivalent to
520.BR DROP .
521This target is only valid in the
522.BR INPUT ,
523.B FORWARD
524and
525.B OUTPUT
526chains. Several options control the nature of the error packet
527returned:
528.TP
529.BI "--reject-with" "type"
530The type given can be
531.BR icmp-net-unreachable ,
532.BR icmp-host-unreachable ,
533.BR icmp-port-unreachable or
534.BR icmp-proto-unreachable
535which return the appropriate ICMP error message (net-unreachable is
536the default). The following special types are also allowed:
537.B tcp-reset
538is only valid if the rule also specifies
539.BR "-p tcp" ,
540and generates a TCP reset packet in response. This is generally not a
541good idea (modern stacks should deal with ICMPs on TCP connection
542initiation attempts).
543.B echo-reply
544can only be used for rules which specify an ICMP ping packet, and
545generates a ping reply.
546.SS TOS
547This is used to set the 8-bit Type of Service field in the IP header.
548It is only valid in the
549.B mangle
550table.
551.TP
552.BI "--set-tos" "tos"
553You can use a numeric TOS values, or use
554.br
555 iptables -j TOS -h
556.br
557to see the list of valid TOS names.
558.SS MIRROR
559This is an experimental demonstration target which inverts the source
560and destination fields in the IP header and retransmits the packet.
561It is only valid in the
562.BR INPUT ,
563.B FORWARD
564and
565.B OUTPUT
566chains.
567.SS SNAT
568This target is only valid in the
569.B nat
570table, in the
571.B POSTROUTING
572chain. It specifies that the source address of the packet should be
573modified (and all future packets in this connection will also be
574mangled), and rules should cease being examined. It takes one option:
575.TP
576.BI "--to-source" "<ipaddr>[-<ipaddr>][:port-port]"
577which can specify a single new source IP address, an inclusive range
578of IP addresses, and optionally, a port range (which is only valid if
579the rule also specifies
580.B "-p tcp"
581or
582.BR "-p udp" ).
583If no port range is specified, then source ports below 512 will be
584mapped to other ports below 512: those between 1024 will be mapped to
585ports below 1024, and other ports will be mapped to 1024 or above.
586Where possible, no port alteration will occur.
587.SS DNAT
588This target is only valid in the
589.B nat
590table, in the
591.B PREROUTING
592and
593.B OUTPUT
594chains. It specifies that the destination address of the packet
595should be modified (and all future packets in this connection will
596also be mangled), and rules should cease being examined. It takes one
597option:
598.TP
599.BI "--to-destination" "<ipaddr>[-<ipaddr>][:port-port]"
600which can specify a single new destination IP address, an inclusive
601range of IP addresses, and optionally, a port range (which is only
602valid if the rule also specifies
603.B "-p tcp"
604or
605.BR "-p udp" ).
606If no port range is specified, then the destination port will never be
607modified.
608.SS MASQUERADE
609This target is only valid in the
610.B nat
611table, in the
612.B POSTROUTING
613chain. It should only be used with dynamically assigned IP (dialup)
614connections: if you have a static IP address, you should use the SNAT
615target. Masquerading is equivalent to specifying a mapping to the IP
616address of the interface the packet is going out, but also has the
617effect that connections are
618.I forgotten
619when the interface goes down. This is the correct behaviour when the
620next dialup is unlikely to have the same interface address (and hence
621any established connections are lost anyway). It takes one option:
622.TP
623.BI "--to-ports" "<port>[-<port>]"
624This specifies a range of source ports to use, overriding the default
625.B SNAT
626source port-selection heuristics (see above). This is only valid with
627if the rule also specifies
628.B "-p tcp"
629or
630.BR "-p udp" ).
631.SS REDIRECT
632This target is only valid in the
633.B nat
634table, in the
635.B PREROUTING
636and
637.B OUTPUT
638chains. It alters the destination IP address to send the packet to
639the machine itself (locally-generated packets are mapped to the
640127.0.0.1 address).
641It takes one option:
642.TP
643.BI "--to-ports" "<port>[-<port>]"
644This specifies a destination port or range or ports to use: without
645this, the destination port is never altered. This is only valid with
646if the rule also specifies
647.B "-p tcp"
648or
649.BR "-p udp" ).
650.TP
651.SH DIAGNOSTICS
652Various error messages are printed to standard error. The exit code
653is 0 for correct functioning. Errors which appear to be caused by
654invalid or abused command line parameters cause an exit code of 2, and
655other errors cause an exit code of 1.
656.SH BUGS
657Check is not implemented (yet).
658.SH COMPATIBILITY WITH IPCHAINS
659This
660.B iptables
661is very similar to ipchains by Rusty Russell. The main difference is
662that the chains
663.B INPUT
664and
665.B OUTPUT
666are only traversed for packets coming into the local host and
667originating from the local host respectively. Hence every packet only
668passes through one of the three chains; previously a forwarded packet
669would pass through all three.
670.PP
671The other main difference is that
672.B -i
673refers to the input interface;
674.B -o
675refers to the output interface, and both are available for packets
676entering the
677.B FORWARD
678chain.
679.PP The various forms of NAT have been separated out;
680.B iptables
681is a pure packet filter when using the default `filter' table, with
682optional extension modules. This should simplify much of the previous
683confusion over the combination of IP masquerading and packet filtering
684seen previously. So the following options are handled differently:
685.br
686 -j MASQ
687.br
688 -M -S
689.br
690 -M -L
691.br
692There are several other changes in iptables.
693.SH SEE ALSO
694The iptables-HOWTO, which details more iptables usage, and the
695netfilter-hacking-HOWTO which details the internals.
696.SH AUTHOR
697Rusty Russell wrote iptables, in early consultation with Michael
698Neuling.
699.PP
700Marc Boucher wrote the owner match, the mark stuff, and ran around
701doing cool stuff everywhere.
702.PP
703James Morris wrote the TOS target, and tos match.
704.PP
705Jozsef Kadlecsik wrote the REJECT target.
706.PP
707The Netfilter Core Team is: Marc Boucher, Rusty Russell.
708.\" .. and did I mention that we are incredibly cool people?