1 .TH IPTABLES 8 "" "@PACKAGE_STRING@" "@PACKAGE_STRING@"
3 .\" Man page written by Herve Eychenne <rv@wallfire.org> (May 1999)
4 .\" It is based on ipchains page.
5 .\" TODO: add a word for protocol helpers (FTP, IRC, SNMP-ALG)
7 .\" ipchains page by Paul ``Rusty'' Russell March 1997
8 .\" Based on the original ipfwadm man page by Jos Vos <jos@xos.nl>
10 .\" This program is free software; you can redistribute it and/or modify
11 .\" it under the terms of the GNU General Public License as published by
12 .\" the Free Software Foundation; either version 2 of the License, or
13 .\" (at your option) any later version.
15 .\" This program is distributed in the hope that it will be useful,
16 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
17 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 .\" GNU General Public License for more details.
20 .\" You should have received a copy of the GNU General Public License
21 .\" along with this program; if not, write to the Free Software
22 .\" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 iptables/ip6tables \(em administration tool for IPv4/IPv6 packet filtering and NAT
28 \fBiptables\fP [\fB\-t\fP \fItable\fP] {\fB\-A\fP|\fB\-C\fP|\fB\-D\fP|\fB-V\fP}
29 \fIchain\fP \fIrule-specification\fP
31 \fBip6tables\fP [\fB\-t\fP \fItable\fP] {\fB\-A\fP|\fB\-C\fP|\fB\-D\fP|\fB-V\fP}
32 \fIchain rule-specification\fP
34 \fBiptables\fP [\fB\-t\fP \fItable\fP] \fB\-I\fP \fIchain\fP [\fIrulenum\fP] \fIrule-specification\fP
36 \fBiptables\fP [\fB\-t\fP \fItable\fP] \fB\-R\fP \fIchain rulenum rule-specification\fP
38 \fBiptables\fP [\fB\-t\fP \fItable\fP] \fB\-D\fP \fIchain rulenum\fP
40 \fBiptables\fP [\fB\-t\fP \fItable\fP] \fB\-S\fP [\fIchain\fP [\fIrulenum\fP]]
42 \fBiptables\fP [\fB\-t\fP \fItable\fP] {\fB\-F\fP|\fB\-L\fP|\fB\-Z\fP} [\fIchain\fP [\fIrulenum\fP]] [\fIoptions...\fP]
44 \fBiptables\fP [\fB\-t\fP \fItable\fP] \fB\-N\fP \fIchain\fP
46 \fBiptables\fP [\fB\-t\fP \fItable\fP] \fB\-X\fP [\fIchain\fP]
48 \fBiptables\fP [\fB\-t\fP \fItable\fP] \fB\-P\fP \fIchain policy\fP
50 \fBiptables\fP [\fB\-t\fP \fItable\fP] \fB\-E\fP \fIold-chain-name new-chain-name\fP
52 rule-specification := [matches...] [target]
54 match := \fB\-m\fP \fImatchname\fP [per-match-options]
56 target := \fB\-j\fP \fItargetname\fP [per-target-options]
58 \fBIptables\fP and \fBip6tables\fP are used to set up, maintain, and inspect the
59 tables of IPv4 and IPv6 packet
60 filter rules in the Linux kernel. Several different tables
61 may be defined. Each table contains a number of built-in
62 chains and may also contain user-defined chains.
64 Each chain is a list of rules which can match a set of packets. Each
65 rule specifies what to do with a packet that matches. This is called
66 a `target', which may be a jump to a user-defined chain in the same
69 A firewall rule specifies criteria for a packet and a target. If the
70 packet does not match, the next rule in the chain is examined; if
71 it does match, then the next rule is specified by the value of the
72 target, which can be the name of a user-defined chain, one of the targets
73 described in \fBiptables\-extensions\fP(8), or one of the
74 special values \fBACCEPT\fP, \fBDROP\fP or \fBRETURN\fP.
76 \fBACCEPT\fP means to let the packet through.
77 \fBDROP\fP means to drop the packet on the floor.
78 \fBRETURN\fP means stop traversing this chain and resume at the next
80 previous (calling) chain. If the end of a built-in chain is reached
81 or a rule in a built-in chain with target \fBRETURN\fP
82 is matched, the target specified by the chain policy determines the
85 There are currently five independent tables (which tables are present
86 at any time depends on the kernel configuration options and which
89 \fB\-t\fP, \fB\-\-table\fP \fItable\fP
90 This option specifies the packet matching table which the command
91 should operate on. If the kernel is configured with automatic module
92 loading, an attempt will be made to load the appropriate module for
93 that table if it is not already there.
95 The tables are as follows:
99 This is the default table (if no \-t option is passed). It contains
100 the built-in chains \fBINPUT\fP (for packets destined to local sockets),
101 \fBFORWARD\fP (for packets being routed through the box), and
102 \fBOUTPUT\fP (for locally-generated packets).
105 This table is consulted when a packet that creates a new
106 connection is encountered. It consists of four built-ins: \fBPREROUTING\fP
107 (for altering packets as soon as they come in), \fBINPUT\fP (for altering
108 packets destined for local sockets), \fBOUTPUT\fP
109 (for altering locally-generated packets before routing), and \fBPOSTROUTING\fP
110 (for altering packets as they are about to go out).
111 IPv6 NAT support is available since kernel 3.7.
114 This table is used for specialized packet alteration. Until kernel
115 2.4.17 it had two built-in chains: \fBPREROUTING\fP
116 (for altering incoming packets before routing) and \fBOUTPUT\fP
117 (for altering locally-generated packets before routing).
118 Since kernel 2.4.18, three other built-in chains are also supported:
119 \fBINPUT\fP (for packets coming into the box itself), \fBFORWARD\fP
120 (for altering packets being routed through the box), and \fBPOSTROUTING\fP
121 (for altering packets as they are about to go out).
124 This table is used mainly for configuring exemptions from connection
125 tracking in combination with the NOTRACK target. It registers at the netfilter
126 hooks with higher priority and is thus called before ip_conntrack, or any other
127 IP tables. It provides the following built-in chains: \fBPREROUTING\fP
128 (for packets arriving via any network interface) and \fBOUTPUT\fP
129 (for packets generated by local processes).
132 This table is used for Mandatory Access Control (MAC) networking rules, such
133 as those enabled by the \fBSECMARK\fP and \fBCONNSECMARK\fP targets.
134 Mandatory Access Control is implemented by Linux Security Modules such as
135 SELinux. The security table is called after the filter table, allowing any
136 Discretionary Access Control (DAC) rules in the filter table to take effect
137 before MAC rules. This table provides the following built-in chains:
138 \fBINPUT\fP (for packets coming into the box itself),
139 \fBOUTPUT\fP (for altering locally-generated packets before routing), and
140 \fBFORWARD\fP (for altering packets being routed through the box).
143 The options that are recognized by
144 \fBiptables\fP and \fBip6tables\fP can be divided into several different groups.
146 These options specify the desired action to perform. Only one of them
147 can be specified on the command line unless otherwise stated
148 below. For long versions of the command and option names, you
149 need to use only enough letters to ensure that
150 \fBiptables\fP can differentiate it from all other options.
152 \fB\-A\fP, \fB\-\-append\fP \fIchain rule-specification\fP
153 Append one or more rules to the end of the selected chain.
154 When the source and/or destination names resolve to more than one
155 address, a rule will be added for each possible address combination.
157 \fB\-C\fP, \fB\-\-check\fP \fIchain rule-specification\fP
158 Check whether a rule matching the specification does exist in the
159 selected chain. This command uses the same logic as \fB\-D\fP to
160 find a matching entry, but does not alter the existing iptables
161 configuration and uses its exit code to indicate success or failure.
163 \fB\-D\fP, \fB\-\-delete\fP \fIchain rule-specification\fP
166 \fB\-D\fP, \fB\-\-delete\fP \fIchain rulenum\fP
167 Delete one or more rules from the selected chain. There are two
168 versions of this command: the rule can be specified as a number in the
169 chain (starting at 1 for the first rule) or a rule to match.
171 \fB\-I\fP, \fB\-\-insert\fP \fIchain\fP [\fIrulenum\fP] \fIrule-specification\fP
172 Insert one or more rules in the selected chain as the given rule
173 number. So, if the rule number is 1, the rule or rules are inserted
174 at the head of the chain. This is also the default if no rule number
177 \fB\-R\fP, \fB\-\-replace\fP \fIchain rulenum rule-specification\fP
178 Replace a rule in the selected chain. If the source and/or
179 destination names resolve to multiple addresses, the command will
180 fail. Rules are numbered starting at 1.
182 \fB\-L\fP, \fB\-\-list\fP [\fIchain\fP]
183 List all rules in the selected chain. If no chain is selected, all
184 chains are listed. Like every other iptables command, it applies to the
185 specified table (filter is the default), so NAT rules get listed by
187 iptables \-t nat \-n \-L
189 Please note that it is often used with the \fB\-n\fP
190 option, in order to avoid long reverse DNS lookups.
191 It is legal to specify the \fB\-Z\fP
192 (zero) option as well, in which case the chain(s) will be atomically
193 listed and zeroed. The exact output is affected by the other
194 arguments given. The exact rules are suppressed until you use
199 \fBiptables\-save\fP(8).
201 \fB\-S\fP, \fB\-\-list\-rules\fP [\fIchain\fP]
202 Print all rules in the selected chain. If no chain is selected, all
203 chains are printed like iptables-save. Like every other iptables command,
204 it applies to the specified table (filter is the default).
206 \fB\-F\fP, \fB\-\-flush\fP [\fIchain\fP]
207 Flush the selected chain (all the chains in the table if none is given).
208 This is equivalent to deleting all the rules one by one.
210 \fB\-Z\fP, \fB\-\-zero\fP [\fIchain\fP [\fIrulenum\fP]]
211 Zero the packet and byte counters in all chains, or only the given chain,
212 or only the given rule in a chain. It is legal to
214 \fB\-L\fP, \fB\-\-list\fP
215 (list) option as well, to see the counters immediately before they are
216 cleared. (See above.)
218 \fB\-N\fP, \fB\-\-new\-chain\fP \fIchain\fP
219 Create a new user-defined chain by the given name. There must be no
220 target of that name already.
222 \fB\-X\fP, \fB\-\-delete\-chain\fP [\fIchain\fP]
223 Delete the chain specified. There must be no references
224 to the chain. If there are, you must delete or replace the referring rules
225 before the chain can be deleted. The chain must be empty, i.e. not contain
226 any rules. If no argument is given, it will delete all empty chains in the
227 table. Empty builtin chains can only be deleted with \fBiptables-nft\fP.
229 \fB\-P\fP, \fB\-\-policy\fP \fIchain target\fP
230 Set the policy for the built-in (non-user-defined) chain to the given target.
231 The policy target must be either \fBACCEPT\fP or \fBDROP\fP.
233 \fB\-E\fP, \fB\-\-rename\-chain\fP \fIold\-chain new\-chain\fP
234 Rename the user specified chain to the user supplied name. This is
235 cosmetic, and has no effect on the structure of the table.
239 Give a (currently very brief) description of the command syntax.
241 The following parameters make up a rule specification (as used in the
242 add, delete, insert, replace and append commands).
244 \fB\-4\fP, \fB\-\-ipv4\fP
245 This option has no effect in iptables and iptables-restore.
246 If a rule using the \fB\-4\fP option is inserted with (and only with)
247 \fBip6tables\-restore\fP, it will be silently ignored. Any other uses will throw an
248 error. This option allows IPv4 and IPv6 rules in a single rule file
249 for use with both iptables-restore and ip6tables-restore.
251 \fB\-6\fP, \fB\-\-ipv6\fP
252 If a rule using the \fB\-6\fP option is inserted with (and only with)
253 \fBiptables\-restore\fP, it will be silently ignored. Any other uses will throw an
254 error. This option allows IPv4 and IPv6 rules in a single rule file
255 for use with both iptables-restore and ip6tables-restore.
256 This option has no effect in ip6tables and ip6tables-restore.
258 [\fB!\fP] \fB\-p\fP, \fB\-\-protocol\fP \fIprotocol\fP
259 The protocol of the rule or of the packet to check.
260 The specified protocol can be one of \fBtcp\fP, \fBudp\fP, \fBudplite\fP,
261 \fBicmp\fP, \fBicmpv6\fP, \fBesp\fP, \fBah\fP, \fBsctp\fP, \fBmh\fP or the special keyword "\fBall\fP",
262 or it can be a numeric value, representing one of these protocols or a
263 different one. A protocol name from \fI/etc/protocols\fP is also allowed.
264 A "!" argument before the protocol inverts the
265 test. The number zero is equivalent to \fBall\fP. "\fBall\fP"
266 will match with all protocols and is taken as default when this
268 Note that, in ip6tables, IPv6 extension headers except \fBesp\fP are not allowed.
269 \fBesp\fP and \fBipv6\-nonext\fP
270 can be used with Kernel version 2.6.11 or later.
271 The number zero is equivalent to \fBall\fP, which means that you cannot
272 test the protocol field for the value 0 directly. To match on a HBH header,
273 even if it were the last, you cannot use \fB\-p 0\fP, but always need
276 [\fB!\fP] \fB\-s\fP, \fB\-\-source\fP \fIaddress\fP[\fB/\fP\fImask\fP][\fB,\fP\fI...\fP]
277 Source specification. \fIAddress\fP
278 can be either a network name, a hostname, a network IP address (with
279 \fB/\fP\fImask\fP), or a plain IP address. Hostnames will
280 be resolved once only, before the rule is submitted to the kernel.
281 Please note that specifying any name to be resolved with a remote query such as
282 DNS is a really bad idea.
284 can be either an ipv4 network mask (for iptables) or a plain number,
285 specifying the number of 1's at the left side of the network mask.
286 Thus, an iptables mask of \fI24\fP is equivalent to \fI255.255.255.0\fP.
287 A "!" argument before the address specification inverts the sense of
288 the address. The flag \fB\-\-src\fP is an alias for this option.
289 Multiple addresses can be specified, but this will \fBexpand to multiple
290 rules\fP (when adding with \-A), or will cause multiple rules to be
293 [\fB!\fP] \fB\-d\fP, \fB\-\-destination\fP \fIaddress\fP[\fB/\fP\fImask\fP][\fB,\fP\fI...\fP]
294 Destination specification.
295 See the description of the \fB\-s\fP
296 (source) flag for a detailed description of the syntax. The flag
297 \fB\-\-dst\fP is an alias for this option.
299 \fB\-m\fP, \fB\-\-match\fP \fImatch\fP
300 Specifies a match to use, that is, an extension module that tests for a
301 specific property. The set of matches make up the condition under which a
302 target is invoked. Matches are evaluated first to last as specified on the
303 command line and work in short-circuit fashion, i.e. if one extension yields
304 false, evaluation will stop.
306 \fB\-j\fP, \fB\-\-jump\fP \fItarget\fP
307 This specifies the target of the rule; i.e., what to do if the packet
308 matches it. The target can be a user-defined chain (other than the
309 one this rule is in), one of the special builtin targets which decide
310 the fate of the packet immediately, or an extension (see \fBMATCH AND TARGET
311 EXTENSIONS\fP below). If this
312 option is omitted in a rule (and \fB\-g\fP
313 is not used), then matching the rule will have no
314 effect on the packet's fate, but the counters on the rule will be
317 \fB\-g\fP, \fB\-\-goto\fP \fIchain\fP
318 This specifies that the processing should continue in a user
319 specified chain. Unlike with the \-\-jump option, \fBRETURN\fP will not continue
320 processing in this chain but instead in the chain that called us via
323 [\fB!\fP] \fB\-i\fP, \fB\-\-in\-interface\fP \fIname\fP
324 Name of an interface via which a packet was received (only for
325 packets entering the \fBINPUT\fP, \fBFORWARD\fP and \fBPREROUTING\fP
326 chains). When the "!" argument is used before the interface name, the
327 sense is inverted. If the interface name ends in a "+", then any
328 interface which begins with this name will match. If this option is
329 omitted, any interface name will match.
331 [\fB!\fP] \fB\-o\fP, \fB\-\-out\-interface\fP \fIname\fP
332 Name of an interface via which a packet is going to be sent (for packets
333 entering the \fBFORWARD\fP, \fBOUTPUT\fP and \fBPOSTROUTING\fP
334 chains). When the "!" argument is used before the interface name, the
335 sense is inverted. If the interface name ends in a "+", then any
336 interface which begins with this name will match. If this option is
337 omitted, any interface name will match.
339 [\fB!\fP] \fB\-f\fP, \fB\-\-fragment\fP
340 This means that the rule only refers to second and further IPv4 fragments
341 of fragmented packets. Since there is no way to tell the source or
342 destination ports of such a packet (or ICMP type), such a packet will
343 not match any rules which specify them. When the "!" argument
344 precedes the "\-f" flag, the rule will only match head fragments, or
345 unfragmented packets. This option is IPv4 specific, it is not available
348 \fB\-c\fP, \fB\-\-set\-counters\fP \fIpackets bytes\fP
349 This enables the administrator to initialize the packet and byte
350 counters of a rule (during \fBINSERT\fP, \fBAPPEND\fP, \fBREPLACE\fP
353 The following additional options can be specified:
355 \fB\-v\fP, \fB\-\-verbose\fP
356 Verbose output. This option makes the list command show the interface
357 name, the rule options (if any), and the TOS masks. The packet and
358 byte counters are also listed, with the suffix 'K', 'M' or 'G' for
359 1000, 1,000,000 and 1,000,000,000 multipliers respectively (but see
360 the \fB\-x\fP flag to change this).
361 For appending, insertion, deletion and replacement, this causes
362 detailed information on the rule or rules to be printed. \fB\-v\fP may be
363 specified multiple times to possibly emit more detailed debug statements:
364 Specified twice, \fBiptables-legacy\fP will dump table info and entries in
365 libiptc, \fBiptables-nft\fP dumps rules in netlink (VM code) presentation.
366 Specified three times, \fBiptables-nft\fP will also dump any netlink messages
369 \fB\-V\fP, \fB\-\-version\fP
370 Show program version and the kernel API used.
372 \fB\-w\fP, \fB\-\-wait\fP [\fIseconds\fP]
373 Wait for the xtables lock.
374 To prevent multiple instances of the program from running concurrently,
375 an attempt will be made to obtain an exclusive lock at launch. By default,
376 the program will exit if the lock cannot be obtained. This option will
377 make the program wait (indefinitely or for optional \fIseconds\fP) until
378 the exclusive lock can be obtained.
380 \fB\-n\fP, \fB\-\-numeric\fP
382 IP addresses and port numbers will be printed in numeric format.
383 By default, the program will try to display them as host names,
384 network names, or services (whenever applicable).
386 \fB\-x\fP, \fB\-\-exact\fP
388 Display the exact value of the packet and byte counters,
389 instead of only the rounded number in K's (multiples of 1000),
390 M's (multiples of 1000K) or G's (multiples of 1000M). This option is
391 only relevant for the \fB\-L\fP command.
393 \fB\-\-line\-numbers\fP
394 When listing rules, add line numbers to the beginning of each rule,
395 corresponding to that rule's position in the chain.
397 \fB\-\-modprobe=\fP\fIcommand\fP
398 When adding or inserting rules into a chain, use \fIcommand\fP
399 to load any necessary modules (targets, match extensions, etc).
402 iptables uses the \fI@XT_LOCK_NAME@\fP file to take an exclusive lock at
405 The \fBXTABLES_LOCKFILE\fP environment variable can be used to override
408 .SH MATCH AND TARGET EXTENSIONS
410 iptables can use extended packet matching and target modules.
411 A list of these is available in the \fBiptables\-extensions\fP(8) manpage.
413 Various error messages are printed to standard error. The exit code is 0 for
414 correct functioning. Errors which appear to be caused by invalid or abused
415 command line parameters cause an exit code of 2. Errors which indicate an
416 incompatibility between kernel and user space cause an exit code of 3. Errors
417 which indicate a resource problem, such as a busy lock, failing memory
418 allocation or error messages from kernel cause an exit code of 4. Finally,
419 other errors cause an exit code of 1.
421 Bugs? What's this? ;-)
422 Well, you might want to have a look at https://bugzilla.netfilter.org/
423 \fBiptables\fP will exit immediately with an error code of 111 if it finds
424 that it was called as a setuid-to-root program.
425 iptables cannot be used safely in this manner because it trusts
426 the shared libraries (matches, targets) loaded at run time, the search
427 path can be set using environment variables.
428 .SH COMPATIBILITY WITH IPCHAINS
430 is very similar to ipchains by Rusty Russell. The main difference is
431 that the chains \fBINPUT\fP and \fBOUTPUT\fP
432 are only traversed for packets coming into the local host and
433 originating from the local host respectively. Hence every packet only
434 passes through one of the three chains (except loopback traffic, which
435 involves both INPUT and OUTPUT chains); previously a forwarded packet
436 would pass through all three.
438 The other main difference is that \fB\-i\fP refers to the input interface;
439 \fB\-o\fP refers to the output interface, and both are available for packets
440 entering the \fBFORWARD\fP chain.
442 The various forms of NAT have been separated out; \fBiptables\fP
443 is a pure packet filter when using the default `filter' table, with
444 optional extension modules. This should avoid much of the
445 confusion over the combination of IP masquerading and packet filtering
446 seen previously. So the following options are handled differently:
452 There are several other changes in iptables.
454 \fBiptables\-apply\fP(8),
455 \fBiptables\-save\fP(8),
456 \fBiptables\-restore\fP(8),
457 \fBiptables\-extensions\fP(8),
459 The packet-filtering-HOWTO details iptables usage for
460 packet filtering, the NAT-HOWTO details NAT,
461 the netfilter-extensions-HOWTO details the extensions that are
462 not in the standard distribution,
463 and the netfilter-hacking-HOWTO details the netfilter internals.
466 .BR "https://www.netfilter.org/" .
468 Rusty Russell originally wrote iptables, in early consultation with Michael
471 Marc Boucher made Rusty abandon ipnatctl by lobbying for a generic packet
472 selection framework in iptables, then wrote the mangle table, the owner match,
473 the mark stuff, and ran around doing cool stuff everywhere.
475 James Morris wrote the TOS target, and tos match.
477 Jozsef Kadlecsik wrote the REJECT target.
479 Harald Welte wrote the ULOG and NFQUEUE target, the new libiptc, as well as the TTL, DSCP, ECN matches and targets.
481 The Netfilter Core Team is: Jozsef Kadlecsik, Pablo Neira Ayuso,
482 Eric Leblond, Florian Westphal and Arturo Borrero Gonzalez.
483 Emeritus Core Team members are: Marc
484 Boucher, Martin Josefsson, Yasuyuki Kozakai, James Morris, Harald Welte and
487 Man page originally written by Herve Eychenne <rv@wallfire.org>.
488 .\" .. and did I mention that we are incredibly cool people?
490 .\" .. witty, charming, powerful ..
491 .\" .. and most of all, modest ..
494 This manual page applies to iptables/ip6tables @PACKAGE_VERSION@.