1 .TH IPTABLES 8 "Mar 09, 2002" "" ""
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 \- administration tool for IPv4 packet filtering and NAT
28 .BR "iptables [-t table] -[AD] " "chain rule-specification [options]"
30 .BR "iptables [-t table] -I " "chain [rulenum] rule-specification [options]"
32 .BR "iptables [-t table] -R " "chain rulenum rule-specification [options]"
34 .BR "iptables [-t table] -D " "chain rulenum [options]"
36 .BR "iptables [-t table] -[LFZ] " "[chain] [options]"
38 .BR "iptables [-t table] -N " "chain"
40 .BR "iptables [-t table] -X " "[chain]"
42 .BR "iptables [-t table] -P " "chain target [options]"
44 .BR "iptables [-t table] -E " "old-chain-name new-chain-name"
47 is used to set up, maintain, and inspect the tables of IP packet
48 filter rules in the Linux kernel. Several different tables
49 may be defined. Each table contains a number of built-in
50 chains and may also contain user-defined chains.
52 Each chain is a list of rules which can match a set of packets. Each
53 rule specifies what to do with a packet that matches. This is called
54 a `target', which may be a jump to a user-defined chain in the same
58 A firewall rule specifies criteria for a packet, and a target. If the
59 packet does not match, the next rule in the chain is the examined; if
60 it does match, then the next rule is specified by the value of the
61 target, which can be the name of a user-defined chain or one of the
70 means to let the packet through.
72 means to drop the packet on the floor.
74 means to pass the packet to userspace (if supported by the kernel).
76 means stop traversing this chain and resume at the next rule in the
77 previous (calling) chain. If the end of a built-in chain is reached
78 or a rule in a built-in chain with target
80 is matched, the target specified by the chain policy determines the
83 There are currently three independent tables (which tables are present
84 at any time depends on the kernel configuration options and which
87 .BI "-t, --table " "table"
88 This option specifies the packet matching table which the command
89 should operate on. If the kernel is configured with automatic module
90 loading, an attempt will be made to load the appropriate module for
91 that table if it is not already there.
93 The tables are as follows:
97 This is the default table (if no -t option is passed). It contains
100 (for packets destined to local sockets),
102 (for packets being routed through the box), and
104 (for locally-generated packets).
107 This table is consulted when a packet that creates a new
108 connection is encountered. It consists of three built-ins:
110 (for altering packets as soon as they come in),
112 (for altering locally-generated packets before routing), and
114 (for altering packets as they are about to go out).
117 This table is used for specialized packet alteration. Until kernel
118 2.4.17 it had two built-in chains:
120 (for altering incoming packets before routing) and
122 (for altering locally-generated packets before routing).
123 Since kernel 2.4.18, three other built-in chains are also supported:
125 (for packets coming into the box itself),
127 (for altering packets being routed through the box), and
129 (for altering packets as they are about to go out).
132 This table is used mainly for configuring exemptions from connection
133 tracking in combination with the NOTRACK target. It registers at the netfilter
134 hooks with higher priority and is thus called before ip_conntrack, or any other
135 IP tables. It provides the following built-in chains:
137 (for packets arriving via any network interface)
139 (for packets generated by local processes)
142 The options that are recognized by
144 can be divided into several different groups.
146 These options specify the specific action to perform. Only one of them
147 can be specified on the command line unless otherwise specified
148 below. For all the long versions of the command and option names, you
149 need to use only enough letters to ensure that
151 can differentiate it from all other options.
153 .BI "-A, --append " "chain rule-specification"
154 Append one or more rules to the end of the selected chain.
155 When the source and/or destination names resolve to more than one
156 address, a rule will be added for each possible address combination.
158 .BI "-D, --delete " "chain rule-specification"
161 .BI "-D, --delete " "chain rulenum"
162 Delete one or more rules from the selected chain. There are two
163 versions of this command: the rule can be specified as a number in the
164 chain (starting at 1 for the first rule) or a rule to match.
166 .BR "-I, --insert " "\fIchain\fP [\fIrulenum\fP] \fIrule-specification\fP"
167 Insert one or more rules in the selected chain as the given rule
168 number. So, if the rule number is 1, the rule or rules are inserted
169 at the head of the chain. This is also the default if no rule number
172 .BI "-R, --replace " "chain rulenum rule-specification"
173 Replace a rule in the selected chain. If the source and/or
174 destination names resolve to multiple addresses, the command will
175 fail. Rules are numbered starting at 1.
177 .BR "-L, --list " "[\fIchain\fP]"
178 List all rules in the selected chain. If no chain is selected, all
179 chains are listed. As every other iptables command, it applies to the
180 specified table (filter is the default), so NAT rules get listed by
182 iptables -t nat -n -L
184 Please note that it is often used with the
186 option, in order to avoid long reverse DNS lookups.
187 It is legal to specify the
189 (zero) option as well, in which case the chain(s) will be atomically
190 listed and zeroed. The exact output is affected by the other
191 arguments given. The exact rules are suppressed until you use
196 .BR "-F, --flush " "[\fIchain\fP]"
197 Flush the selected chain (all the chains in the table if none is given).
198 This is equivalent to deleting all the rules one by one.
200 .BR "-Z, --zero " "[\fIchain\fP]"
201 Zero the packet and byte counters in all chains. It is legal to
204 (list) option as well, to see the counters immediately before they are
205 cleared. (See above.)
207 .BI "-N, --new-chain " "chain"
208 Create a new user-defined chain by the given name. There must be no
209 target of that name already.
211 .BR "-X, --delete-chain " "[\fIchain\fP]"
212 Delete the optional user-defined chain specified. There must be no references
213 to the chain. If there are, you must delete or replace the referring
214 rules before the chain can be deleted. If no argument is given, it
215 will attempt to delete every non-builtin chain in the table.
217 .BI "-P, --policy " "chain target"
218 Set the policy for the chain to the given target. See the section
220 for the legal targets. Only built-in (non-user-defined) chains can have
221 policies, and neither built-in nor user-defined chains can be policy
224 .BI "-E, --rename-chain " "old-chain new-chain"
225 Rename the user specified chain to the user supplied name. This is
226 cosmetic, and has no effect on the structure of the table.
230 Give a (currently very brief) description of the command syntax.
232 The following parameters make up a rule specification (as used in the
233 add, delete, insert, replace and append commands).
235 .BR "-p, --protocol " "[!] \fIprotocol\fP"
236 The protocol of the rule or of the packet to check.
237 The specified protocol can be one of
243 or it can be a numeric value, representing one of these protocols or a
244 different one. A protocol name from /etc/protocols is also allowed.
245 A "!" argument before the protocol inverts the
246 test. The number zero is equivalent to
250 will match with all protocols and is taken as default when this
253 .BR "-s, --source " "[!] \fIaddress\fP[/\fImask\fP]"
254 Source specification.
256 can be either a network name, a hostname (please note that specifying
257 any name to be resolved with a remote query such as DNS is a really bad idea),
258 a network IP address (with /mask), or a plain IP address.
261 can be either a network mask or a plain number,
262 specifying the number of 1's at the left side of the network mask.
267 A "!" argument before the address specification inverts the sense of
268 the address. The flag
270 is an alias for this option.
272 .BR "-d, --destination " "[!] \fIaddress\fP[/\fImask\fP]"
273 Destination specification.
274 See the description of the
276 (source) flag for a detailed description of the syntax. The flag
278 is an alias for this option.
280 .BI "-j, --jump " "target"
281 This specifies the target of the rule; i.e., what to do if the packet
282 matches it. The target can be a user-defined chain (other than the
283 one this rule is in), one of the special builtin targets which decide
284 the fate of the packet immediately, or an extension (see
287 option is omitted in a rule, then matching the rule will have no
288 effect on the packet's fate, but the counters on the rule will be
291 .BR "-i, --in-interface " "[!] \fIname\fP"
292 Name of an interface via which a packet was received (only for
298 chains). When the "!" argument is used before the interface name, the
299 sense is inverted. If the interface name ends in a "+", then any
300 interface which begins with this name will match. If this option is
301 omitted, any interface name will match.
303 .BR "-o, --out-interface " "[!] \fIname\fP"
304 Name of an interface via which a packet is going to be sent (for packets
310 chains). When the "!" argument is used before the interface name, the
311 sense is inverted. If the interface name ends in a "+", then any
312 interface which begins with this name will match. If this option is
313 omitted, any interface name will match.
315 .B "[!] " "-f, --fragment"
316 This means that the rule only refers to second and further fragments
317 of fragmented packets. Since there is no way to tell the source or
318 destination ports of such a packet (or ICMP type), such a packet will
319 not match any rules which specify them. When the "!" argument
320 precedes the "-f" flag, the rule will only match head fragments, or
321 unfragmented packets.
323 .BI "-c, --set-counters " "PKTS BYTES"
324 This enables the administrator to initialize the packet and byte
325 counters of a rule (during
331 The following additional options can be specified:
334 Verbose output. This option makes the list command show the interface
335 name, the rule options (if any), and the TOS masks. The packet and
336 byte counters are also listed, with the suffix 'K', 'M' or 'G' for
337 1000, 1,000,000 and 1,000,000,000 multipliers respectively (but see
340 flag to change this).
341 For appending, insertion, deletion and replacement, this causes
342 detailed information on the rule or rules to be printed.
346 IP addresses and port numbers will be printed in numeric format.
347 By default, the program will try to display them as host names,
348 network names, or services (whenever applicable).
352 Display the exact value of the packet and byte counters,
353 instead of only the rounded number in K's (multiples of 1000)
354 M's (multiples of 1000K) or G's (multiples of 1000M). This option is
355 only relevant for the
360 When listing rules, add line numbers to the beginning of each rule,
361 corresponding to that rule's position in the chain.
363 .B "--modprobe=command"
364 When adding or inserting rules into a chain, use
366 to load any necessary modules (targets, match extensions, etc).
368 iptables can use extended packet matching modules. These are loaded
369 in two ways: implicitly, when
373 is specified, or with the
377 options, followed by the matching module name; after these, various
378 extra command line options become available, depending on the specific
379 module. You can specify multiple extended match modules in one line,
384 options after the module has been specified to receive help specific
387 The following are included in the base package, and most of these can
390 to invert the sense of the match.
393 Account traffic for all hosts in defined network/netmask.
397 - long (one counter per protocol TCP/UDP/IMCP/Other) and short statistics
399 - one iptables rule for all hosts in network/netmask
401 - loading/saving counters (by reading/writting to procfs entries)
404 .BI "--aaddr " "network/netmask"
405 defines network/netmask for which make statistics.
407 .BI "--aname " "name"
408 defines name of list where statistics will be kept. If no is
409 specified DEFAULT will be used.
412 table will colect only short statistics (only total counters
413 without splitting it into protocols.
417 account traffic for/to 192.168.0.0/24 network into table mynetwork:
419 # iptables -A FORWARD -m account --aname mynetwork --aaddr 192.168.0.0/24
421 account traffic for/to WWW serwer for 192.168.0.0/24 network into table mywwwserver:
423 # iptables -A INPUT -p tcp --dport 80
424 -m account --aname mywwwserver --aaddr 192.168.0.0/24 --ashort
426 # iptables -A OUTPUT -p tcp --sport 80
427 -m account --aname mywwwserver --aaddr 192.168.0.0/24 --ashort
431 # cat /proc/net/ipt_account/mynetwork
432 # cat /proc/net/ipt_account/mywwwserver
436 # echo "ip = 192.168.0.1 packets_src = 0" > /proc/net/ipt_account/mywwserver
439 http://www.barbara.eu.org/~quaker/ipt_account/
441 This module matches packets based on their
443 Address types are used within the kernel networking stack and categorize
444 addresses into various groups. The exact definition of that group depends on the specific layer three protocol.
446 The following address types are possible:
449 an unspecified address (i.e. 0.0.0.0)
463 an unreachable address
473 .BI "--src-type " "type"
474 Matches if the source address is of given type
476 .BI "--dst-type " "type"
477 Matches if the destination address is of given type
479 This module matches the SPIs in AH header of IPSec packets.
481 .BR "--ahspi " "[!] \fIspi\fP[:\fIspi\fP]"
483 This is an experimental module. It matches on whether the
484 packet is part of a master connection or one of its children (or grandchildren,
485 etc). For instance, most packets are level 0. FTP data transfer is level 1.
487 .BR "--childlevel " "[!] \fIlevel\fP"
489 Allows you to add comments (up to 256 characters) to any rule.
491 .BI "--comment " "comment"
494 iptables -A INPUT -s 192.168.0.0/16 -m comment --comment "A privatized IP block"
496 This matches if a specific /proc filename is '0' or '1'.
498 .BI "--condition " "[!] filename"
499 Match on boolean value stored in /proc/net/ipt_condition/filename file
501 Match by how many bytes or packets a connection (or one of the two
502 flows constituting the connection) have tranferred so far, or by
503 average bytes per packet.
505 The counters are 64bit and are thus not expected to overflow ;)
507 The primary use is to detect long-lived downloads and mark them to be
508 scheduled using a lower priority band in traffic control.
510 The transfered bytes per connection can also be viewed through
511 /proc/net/ip_conntrack and accessed via ctnetlink
513 [\fB!\fR]\fB --connbytes \fIfrom\fB:\fR[\fIto\fR]
514 match packets from a connection whose packets/bytes/average packet
515 size is more than FROM and less than TO bytes/packets. if TO is
516 omitted only FROM check is done. "!" is used to match packets not
517 falling in the range.
519 \fB--connbytes-dir\fR [\fBoriginal\fR|\fBreply\fR|\fBboth\fR]
520 which packets to consider
522 \fB--connbytes-mode\fR [\fBpackets\fR|\fBbytes\fR|\fBavgpkt\fR]
523 whether to check the amount of packets, number of bytes transferred or
524 the average size (in bytes) of all packets received so far. Note that
525 when "both" is used together with "avgpkt", and data is going (mainly)
526 only in one direction (for example HTTP), the average packet size will
527 be about half of the actual data packets.
530 iptables .. -m connbytes --connbytes 10000:100000 --connbytes-dir both --connbytes-mode bytes ...
532 Allows you to restrict the number of parallel TCP connections to a
533 server per client IP address (or address block).
535 [\fB!\fR] \fB--connlimit-above \fIn\fR
536 match if the number of existing tcp connections is (not) above n
538 .BI "--connlimit-mask " "bits"
539 group hosts using mask
543 # allow 2 telnet connections per client host
544 iptables -p tcp --syn --dport 23 -m connlimit --connlimit-above 2 -j REJECT
546 # you can also match the other way around:
547 iptables -p tcp --syn --dport 23 -m connlimit ! --connlimit-above 2 -j ACCEPT
549 # limit the nr of parallel http requests to 16 per class C sized \
550 network (24 bit netmask)
551 iptables -p tcp --syn --dport 80 -m connlimit --connlimit-above 16
552 --connlimit-mask 24 -j REJECT
554 This module matches the netfilter mark field associated with a connection
555 (which can be set using the
559 .BI "--mark " "value[/mask]"
560 Matches packets in connections with the given mark value (if a mask is
561 specified, this is logically ANDed with the mark before the
564 This module matches the current transfer rate in a connection.
566 .BI "--connrate " "[!] [\fIfrom\fP]:[\fIto\fP]"
567 Match against the current connection transfer rate being within 'from'
568 and 'to' bytes per second. When the "!" argument is used before the
569 range, the sense of the match is inverted.
571 This module, when combined with connection tracking, allows access to
572 more connection tracking information than the "state" match.
573 (this module is present only if iptables was compiled under a kernel
574 supporting this feature)
576 .BI "--ctstate " "state"
577 Where state is a comma separated list of the connection states to
578 match. Possible states are
580 meaning that the packet is associated with no known connection,
582 meaning that the packet is associated with a connection which has seen
583 packets in both directions,
585 meaning that the packet has started a new connection, or otherwise
586 associated with a connection which has not seen packets in both
589 meaning that the packet is starting a new connection, but is
590 associated with an existing connection, such as an FTP data transfer,
593 A virtual state, matching if the original source address differs from
594 the reply destination.
596 A virtual state, matching if the original destination differs from the
599 .BI "--ctproto " "proto"
600 Protocol to match (by number or name)
602 .BI "--ctorigsrc " "[!] \fIaddress\fP[/\fImask\fP]"
603 Match against original source address
605 .BI "--ctorigdst " "[!] \fIaddress\fP[/\fImask\fP]"
606 Match against original destination address
608 .BI "--ctreplsrc " "[!] \fIaddress\fP[/\fImask\fP]"
609 Match against reply source address
611 .BI "--ctrepldst " "[!] \fIaddress\fB[/\fImask\fP]"
612 Match against reply destination address
614 .BI "--ctstatus " "[\fINONE|EXPECTED|SEEN_REPLY|ASSURED\fP][,...]"
615 Match against internal conntrack states
617 .BI "--ctexpire " "\fItime\fP[\fI:time\fP]"
618 Match remaining lifetime in seconds against given value
619 or range of values (inclusive)
621 This module matches the 6 bit DSCP field within the TOS field in the
622 IP header. DSCP has superseded TOS within the IETF.
624 .BI "--dscp " "value"
625 Match against a numeric (decimal or hex) value [0-32].
627 .BI "--dscp-class " "\fIDiffServ Class\fP"
628 Match the DiffServ class. This value may be any of the
629 BE, EF, AFxx or CSx classes. It will then be converted
630 into it's according numeric value.
632 This module allows you to limit the packet per second (pps) rate on a per
633 destination IP or per destination port base. As opposed to the `limit' match,
634 every destination ip / destination port has it's own limit.
636 .BI "--dstlimit " "avg"
637 Maximum average match rate (packets per second unless followed by /sec /minute /hour /day postfixes).
639 .BI "--dstlimit-mode " "mode"
640 The limiting hashmode. Is the specified limit per
641 .B dstip, dstip-dstport
645 .B srcipdstip-dstport
648 .BI "--dstlimit-name " "name"
649 Name for /proc/net/ipt_dstlimit/* file entry
651 .BI "[" "--dstlimit-burst " "burst" "]"
652 Number of packets to match in a burst. Default: 5
654 .BI "[" "--dstlimit-htable-size " "size" "]"
655 Number of buckets in the hashtable
657 .BI "[" "--dstlimit-htable-max " "max" "]"
658 Maximum number of entries in the hashtable
660 .BI "[" "--dstlimit-htable-gcinterval " "interval" "]"
661 Interval between garbage collection runs of the hashtable (in miliseconds).
662 Default is 1000 (1 second).
664 .BI "[" "--dstlimit-htable-expire " "time"
665 After which time are idle entries expired from hashtable (in miliseconds)?
666 Default is 10000 (10 seconds).
668 This allows you to match the ECN bits of the IPv4 and TCP header. ECN is the Explicit Congestion Notification mechanism as specified in RFC3168
671 This matches if the TCP ECN CWR (Congestion Window Received) bit is set.
674 This matches if the TCP ECN ECE (ECN Echo) bit is set.
676 .BI "--ecn-ip-ect " "num"
677 This matches a particular IPv4 ECT (ECN-Capable Transport). You have to specify
678 a number between `0' and `3'.
680 This module matches the SPIs in ESP header of IPSec packets.
682 .BR "--espspi " "[!] \fIspi\fP[:\fIspi\fP]"
684 This module matches a rate limit based on a fuzzy logic controller [FLC]
686 .BI "--lower-limit "number"
687 Specifies the lower limit (in packets per second).
689 .BI "--upper-limit " "number"
690 Specifies the upper limit (in packets per second).
692 This patch adds a new match called 'hashlimit'.
693 The idea is to have something like 'limit', but either per
694 destination-ip or per (destip,destport) tuple.
696 It gives you the ability to express
698 '1000 packets per second for every host in 192.168.0.0/16'
700 '100 packets per second for every service of 192.168.1.1'
702 with a single iptables rule.
704 .BI "--hashlimit " "rate"
705 A rate just like the limit match
707 .BI "--hashlimit-burst " "num"
708 Burst value, just like limit match
710 .BI "--hashlimit-mode " "destip | destip-destport"
711 Limit per IP or per port
713 .BI "--hashlimit-name " "foo"
714 The name for the /proc/net/ipt_hashlimit/foo entry
716 .BI "--hashlimit-htable-size " "num"
717 The number of buckets of the hash table
719 .BI "--hashlimit-htable-max " "num"
720 Maximum entries in the hash
722 .BI "--hashlimit-htable-expire " "num"
723 After how many miliseconds do hash entries expire
725 .BI "--hashlimit-htable-gcinterval " "num"
726 How many miliseconds between garbage collection intervals
728 This module matches packets related to a specific conntrack-helper.
730 .BI "--helper " "string"
731 Matches packets related to the specified conntrack-helper.
734 string can be "ftp" for packets related to a ftp-session on default port.
735 For other ports append -portnr to the value, ie. "ftp-2121".
737 Same rules apply for other conntrack-helpers.
740 This extension is loaded if `--protocol icmp' is specified. It
741 provides the following option:
743 .BR "--icmp-type " "[!] \fItypename\fP"
744 This allows specification of the ICMP type, which can be a numeric
745 ICMP type, or one of the ICMP type names shown by the command
750 This matches on a given arbitrary range of IPv4 addresses
752 .BI "[!]" "--src-range " "ip-ip"
753 Match source IP in the specified range.
755 .BI "[!]" "--dst-range " "ip-ip"
756 Match destination IP in the specified range.
758 Match on IPv4 header options like source routing, record route,
759 timestamp and router-alert.
762 To match packets with the flag strict source routing.
765 To match packets with the flag loose source routing.
768 To match packets with no flag for source routing.
770 .B "\fR[\fB!\fR]\fB --rr"
771 To match packets with the RR flag.
773 .B "\fR[\fB!\fR]\fB --ts"
774 To match packets with the TS flag.
776 .B "\fR[\fB!\fR]\fB --ra"
777 To match packets with the router-alert option.
779 .B "\fR[\fB!\fR]\fB --any-opt"
780 To match a packet with at least one IP option, or no IP option
781 at all if ! is chosen.
785 $ iptables -A input -m ipv4options --rr -j DROP
786 will drop packets with the record-route flag.
788 $ iptables -A input -m ipv4options --ts -j DROP
789 will drop packets with the timestamp flag.
791 This module matches the length of a packet against a specific value
794 .BR "--length " "\fIlength\fP[:\fIlength\fP]"
796 This module matches at a limited rate using a token bucket filter.
797 A rule using this extension will match until this limit is reached
798 (unless the `!' flag is used). It can be used in combination with the
800 target to give limited logging, for example.
802 .BI "--limit " "rate"
803 Maximum average matching rate: specified as a number, with an optional
804 `/second', `/minute', `/hour', or `/day' suffix; the default is
807 .BI "--limit-burst " "number"
808 Maximum initial number of packets to match: this number gets
809 recharged by one every time the limit specified above is not reached,
810 up to this number; the default is 5.
813 .BR "--mac-source " "[!] \fIaddress\fP"
814 Match source MAC address. It must be of the form XX:XX:XX:XX:XX:XX.
815 Note that this only makes sense for packets coming from an Ethernet device
823 This module matches the netfilter mark field associated with a packet
824 (which can be set using the
828 .BR "--mark " "\fIvalue\fP[/\fImask\fP]"
829 Matches packets with the given unsigned mark value (if a mask is
830 specified, this is logically ANDed with the mask before the
833 This module matches a set of source or destination ports. Up to 15
834 ports can be specified. It can only be used in conjunction with
839 .BR "--source-ports " "\fIport\fP[,\fIport\fP[,\fIport\fP...]]"
840 Match if the source port is one of the given ports. The flag
842 is a convenient alias for this option.
844 .BR "--destination-ports " "\fIport\fP[,\fIport\fP[,\fIport\fP...]]"
845 Match if the destination port is one of the given ports. The flag
847 is a convenient alias for this option.
849 .BR "--ports " "\fIport\fP[,\fIport\fP[,\fIport\fP...]]"
850 Match if the both the source and destination ports are equal to each
851 other and to one of the given ports.
853 This module matches a set of source or destination ports. Up to 15
854 ports can be specified. A port range (port:port) counts as two
855 ports. It can only be used in conjunction with
860 .BR "--source-ports " "\fI[!] port\fP[,\fIport\fP[,\fIport:port\fP...]]"
861 Match if the source port is one of the given ports. The flag
863 is a convenient alias for this option.
865 .BR "--destination-ports " "\fI[!] port\fP[,\fIport\fP[,\fIport:port\fP...]]"
866 Match if the destination port is one of the given ports. The flag
868 is a convenient alias for this option.
870 .BR "--ports " "\fI[!] port\fP[,\fIport\fP[,\fIport:port\fP...]]"
871 Match if either the source or destination ports are equal to one of
874 This module matches every `n'th packet
876 .BI "--every " "value"
877 Match every `value' packet
879 .BI "[" "--counter " "num" "]"
880 Use internal counter number `num'. Default is `0'.
882 .BI "[" "--start " "num" "]"
883 Initialize the counter at the number `num' insetad of `0'. Most between `0'
886 .BI "[" "--packet " "num" "]"
887 Match on `num' packet. Most be between `0' and `value'-1.
889 The idea of passive OS fingerprint matching exists for quite a long time,
890 but was created as extension fo OpenBSD pf only some weeks ago.
891 Original idea was lurked in some OpenBSD mailing list (thanks
892 grange@open...) and than adopted for Linux netfilter in form of this code.
894 Original fingerprint table was created by Michal Zalewski <lcamtuf@coredump.cx>.
896 This module compares some data(WS, MSS, options and it's order, ttl,
897 df and others) from first SYN packet (actually from packets with SYN
898 bit set) with dynamically loaded OS fingerprints.
901 If present, OSF will log determined genres even if they don't match
903 0 - log all determined entries,
906 In syslog you find something like this:
908 ipt_osf: Windows [2000:SP3:Windows XP Pro SP1, 2000 SP3]: 11.22.33.55:4024 -> 11.22.33.44:139
910 ipt_osf: Unknown: 16384:106:1:48:020405B401010402 44.33.22.11:1239 -> 11.22.33.44:80
913 if present, OSF will use some smartness to determine remote OS.
914 OSF will use initial TTL only if source of connection is in our local network.
917 If present, OSF will log all events also through netlink NETLINK_NFLOG groupt 1.
919 .BI "--genre " "[!] string"
920 Match a OS genre by passive fingerprinting
924 #iptables -I INPUT -j ACCEPT -p tcp -m osf --genre Linux --log 1 --smart
926 NOTE: -p tcp is obviously required as it is a TCP match.
928 Fingerprints can be loaded and read through /proc/sys/net/ipv4/osf file.
929 One can flush all fingerprints with following command:
931 echo -en FLUSH > /proc/sys/net/ipv4/osf
933 Only one fingerprint per open/write/close.
935 Fingerprints can be downloaded from http://www.openbsd.org/cgi-bin/cvsweb/src/etc/pf.os
937 This module attempts to match various characteristics of the packet
938 creator, for locally-generated packets. It is only valid in the
940 chain, and even this some packets (such as ICMP ping responses) may
941 have no owner, and hence never match.
943 .BI "--uid-owner " "userid"
944 Matches if the packet was created by a process with the given
947 .BI "--gid-owner " "groupid"
948 Matches if the packet was created by a process with the given
951 .BI "--pid-owner " "processid"
952 Matches if the packet was created by a process with the given
955 .BI "--sid-owner " "sessionid"
956 Matches if the packet was created by a process in the given session
959 .BI "--cmd-owner " "name"
960 Matches if the packet was created by a process with the given command name.
961 (this option is present only if iptables was compiled under a kernel
962 supporting this feature)
964 .B NOTE: pid, sid and command matching are broken on SMP
966 This module matches on the bridge port input and output devices enslaved
967 to a bridge device. This module is a part of the infrastructure that enables
968 a transparent bridging IP firewall and is only useful for kernel versions
969 above version 2.5.44.
972 Name of a bridge port via which a packet is received (only for
978 chains). If the interface name ends in a "+", then any
979 interface which begins with this name will match. If the packet didn't arrive
980 through a bridge device, this packet won't match this option, unless '!' is used.
982 .B --physdev-out name
983 Name of a bridge port via which a packet is going to be sent (for packets
989 chains). If the interface name ends in a "+", then any
990 interface which begins with this name will match. Note that in the
991 .BR nat " and " mangle
993 chains one cannot match on the bridge output port, however one can in the
995 chain. If the packet won't leave by a bridge device or it is yet unknown what
996 the output device will be, then the packet won't match this option, unless
1000 Matches if the packet has entered through a bridge interface.
1003 Matches if the packet will leave through a bridge interface.
1005 .B --physdev-is-bridged
1006 Matches if the packet is being bridged and therefore is not being routed.
1007 This is only useful in the FORWARD and POSTROUTING chains.
1009 This module matches the link-layer packet type.
1011 .BI "--pkt-type " "[\fIunicast\fP|\fIbroadcast\fP|\fImulticast\fP]"
1013 Attempt to detect TCP and UDP port scans. This match was derived from
1014 Solar Designer's scanlogd.
1016 .BI "--psd-weight-threshold " "threshold"
1017 Total weight of the latest TCP/UDP packets with different
1018 destination ports coming from the same host to be treated as port
1021 .BI "--psd-delay-threshold " "delay"
1022 Delay (in hundredths of second) for the packets with different
1023 destination ports coming from the same host to be treated as
1024 possible port scan subsequence.
1026 .BI "--psd-lo-ports-weight " "weight"
1027 Weight of the packet with privileged (<=1024) destination port.
1029 .BI "--psd-hi-ports-weight " "weight"
1030 Weight of the packet with non-priviliged destination port.
1032 Implements network quotas by decrementing a byte counter with each
1035 .BI "--quota " "bytes"
1038 KNOWN BUGS: this does not work on SMP systems.
1040 This module randomly matches a certain percentage of all packets.
1042 .BI "--average " "percent"
1043 Matches the given percentage. If omitted, a probability of 50% is set.
1045 This matches the routing realm. Routing realms are used in complex routing
1046 setups involving dynamic routing protocols like BGP.
1048 .BI "--realm " "[!]" "value[/mask]"
1049 Matches a given realm number (and optionally mask).
1051 Allows you to dynamically create a list of IP addresses and then match
1052 against that list in a few different ways.
1054 For example, you can create a `badguy' list out of people attempting
1055 to connect to port 139 on your firewall and then DROP all future
1056 packets from them without considering them.
1058 .BI "--name " "name"
1059 Specify the list to use for the commands. If no name is given then 'DEFAULT'
1062 [\fB!\fR] \fB--set\fR
1063 This will add the source address of the packet to the list. If the
1064 source address is already in the list, this will update the existing
1065 entry. This will always return success (or failure if `!' is passed
1068 [\fB!\fR] \fB--rcheck\fR
1069 Check if the source address of the packet is currently in
1072 [\fB!\fR] \fB--update\fR
1073 Like \fB--rcheck\fR, except it will update the "last seen" timestamp if it
1076 [\fB!\fR] \fB--remove\fR
1077 Check if the source address of the packet is currently in the list and
1078 if so that address will be removed from the list and the rule will
1079 return true. If the address is not found, false is returned.
1081 [\fB!\fR] \fB--seconds \fIseconds\fR
1082 This option must be used in conjunction with one of \fB--rcheck\fR or
1083 \fB--update\fR. When used, this will narrow the match to only happen
1084 when the address is in the list and was seen within the last given
1087 [\fB!\fR] \fB--hitcount \fIhits\fR
1088 This option must be used in conjunction with one of \fB--rcheck\fR or
1089 \fB--update\fR. When used, this will narrow the match to only happen
1090 when the address is in the list and packets had been received greater
1091 than or equal to the given value. This option may be used along with
1092 \fB--seconds\fR to create an even narrower match requiring a certain
1093 number of hits within a specific time frame.
1096 This option must be used in conjunction with one of \fB--rcheck\fR or
1097 \fB--update\fR. When used, this will narrow the match to only happen
1098 when the address is in the list and the TTL of the current packet
1099 matches that of the packet which hit the \fB--set\fR rule. This may be
1100 useful if you have problems with people faking their source address in
1101 order to DoS you via this module by disallowing others access to your
1102 site by sending bogus packets to you.
1106 # iptables -A FORWARD -m recent --name badguy --rcheck --seconds 60 -j DROP
1108 # iptables -A FORWARD -p tcp -i eth0 --dport 139 -m recent --name badguy --set -j DROP
1110 Official website (http://snowman.net/projects/ipt_recent/) also has
1111 some examples of usage.
1113 /proc/net/ipt_recent/* are the current lists of addresses and information
1114 about each entry of each list.
1116 Each file in /proc/net/ipt_recent/ can be read from to see the current list
1117 or written two using the following commands to modify the list:
1119 echo xx.xx.xx.xx > /proc/net/ipt_recent/DEFAULT
1120 to Add to the DEFAULT list
1122 echo -xx.xx.xx.xx > /proc/net/ipt_recent/DEFAULT
1123 to Remove from the DEFAULT list
1125 echo clear > /proc/net/ipt_recent/DEFAULT
1126 to empty the DEFAULT list.
1128 The module itself accepts parameters, defaults shown:
1130 .BI "ip_list_tot=" "100"
1131 Number of addresses remembered per table
1133 .BI "ip_pkt_list_tot=" "20"
1134 Number of packets per address remembered
1136 .BI "ip_list_hash_size=" "0"
1137 Hash table size. 0 means to calculate it based on ip_list_tot, default: 512
1139 .BI "ip_list_perms=" "0644"
1140 Permissions for /proc/net/ipt_recent/* files
1143 Set to 1 to get lots of debugging info
1146 \fB--source-port\fR,\fB--sport \fR[\fB!\fR] \fIport\fR[\fB:\fIport\fR]
1148 \fB--destination-port\fR,\fB--dport \fR[\fB!\fR] \fIport\fR[\fB:\fIport\fR]
1150 \fB--chunk-types\fR [\fB!\fR] \fBall\fR|\fBany\fR|\fBonly \fIchunktype\fR[\fB:\fIflags\fR] [...]
1151 The flag letter in upper case indicates that the flag is to match if set,
1152 in the lower case indicates to match if unset.
1154 Chunk types: DATA INIT INIT_ACK SACK HEARTBEAT HEARTBEAT_ACK ABORT SHUTDOWN SHUTDOWN_ACK ERROR COOKIE_ECHO COOKIE_ACK ECN_ECNE ECN_CWR SHUTDOWN_COMPLETE ASCONF ASCONF_ACK
1156 chunk type available flags
1162 SHUTDOWN_COMPLETE T t
1164 (lowercase means flag should be "off", uppercase means "on")
1168 iptables -A INPUT -p sctp --dport 80 -j DROP
1170 iptables -A INPUT -p sctp --chunk-types any DATA,INIT -j DROP
1172 iptables -A INPUT -p sctp --chunk-types any DATA:Be -j ACCEPT
1174 This modules macthes IP sets which can be defined by ipset(8).
1176 .BR "--set " "setname flag[,flag...]"
1181 and there can be no more than six of them. Hence the command
1183 iptables -A FORWARD -m set --set test src,dst
1185 will match packets, for which (depending on the type of the set) the source
1186 address or port number of the packet can be found in the specified set. If
1187 there is a binding belonging to the mached set element or there is a default
1188 binding for the given set, then the rule will match the packet only if
1189 additionally (depending on the type of the set) the destination address or
1190 port number of the packet can be found in the set according to the binding.
1192 This module, when combined with connection tracking, allows access to
1193 the connection tracking state for this packet.
1195 .BI "--state " "state"
1196 Where state is a comma separated list of the connection states to
1197 match. Possible states are
1199 meaning that the packet could not be identified for some reason which
1200 includes running out of memory and ICMP errors which don't correspond to any
1203 meaning that the packet is associated with a connection which has seen
1204 packets in both directions,
1206 meaning that the packet has started a new connection, or otherwise
1207 associated with a connection which has not seen packets in both
1210 meaning that the packet is starting a new connection, but is
1211 associated with an existing connection, such as an FTP data transfer,
1214 These extensions are loaded if `--protocol tcp' is specified. It
1215 provides the following options:
1217 .BR "--source-port " "[!] \fIport\fP[:\fIport\fP]"
1218 Source port or port range specification. This can either be a service
1219 name or a port number. An inclusive range can also be specified,
1222 If the first port is omitted, "0" is assumed; if the last is omitted,
1224 If the second port greater then the first they will be swapped.
1227 is a convenient alias for this option.
1229 .BR "--destination-port " "[!] \fIport\fP[:\fIport\fP]"
1230 Destination port or port range specification. The flag
1232 is a convenient alias for this option.
1234 .BR "--tcp-flags " "[!] \fImask\fP \fIcomp\fP"
1235 Match when the TCP flags are as specified. The first argument is the
1236 flags which we should examine, written as a comma-separated list, and
1237 the second argument is a comma-separated list of flags which must be
1239 .BR "SYN ACK FIN RST URG PSH ALL NONE" .
1242 iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST SYN
1244 will only match packets with the SYN flag set, and the ACK, FIN and
1248 Only match TCP packets with the SYN bit set and the ACK,RST and FIN bits
1249 cleared. Such packets are used to request TCP connection initiation;
1250 for example, blocking such packets coming in an interface will prevent
1251 incoming TCP connections, but outgoing TCP connections will be
1253 It is equivalent to \fB--tcp-flags SYN,RST,ACK,FIN SYN\fP.
1254 If the "!" flag precedes the "--syn", the sense of the
1257 .BR "--tcp-option " "[!] \fInumber\fP"
1258 Match if TCP option set.
1260 .BR "--mss " "\fIvalue\fP[:\fIvalue\fP]"
1261 Match TCP SYN or SYN/ACK packets with the specified MSS value (or range),
1262 which control the maximum packet size for that connection.
1264 This matches the TCP MSS (maximum segment size) field of the TCP header. You can only use this on TCP SYN or SYN/ACK packets, since the MSS is only negotiated during the TCP handshake at connection startup time.
1266 .BI "[!] "--mss " "value[:value]"
1267 Match a given TCP MSS value or range.
1269 This matches if the packet arrival time/date is within a given range. All options are facultative.
1271 .BI " --timestart " "value"
1272 Match only if it is after `value' (Inclusive, format: HH:MM ; default 00:00).
1274 .BI "--timestop " "value"
1275 Match only if it is before `value' (Inclusive, format: HH:MM ; default 23:59).
1277 .BI "--days " "listofdays"
1278 Match only if today is one of the given days. (format: Mon,Tue,Wed,Thu,Fri,Sat,Sun ; default everyday)
1280 .BI "--datestart " "date"
1281 Match only if it is after `date' (Inclusive, format: YYYY[:MM[:DD[:hh[:mm[:ss]]]]] ; h,m,s start from 0 ; default to 1970)
1283 .BI "--datestop " "date"
1284 Match only if it is before `date' (Inclusive, format: YYYY[:MM[:DD[:hh[:mm[:ss]]]]] ; h,m,s start from 0 ; default to 2037)
1286 This module matches the 8 bits of Type of Service field in the IP
1287 header (ie. including the precedence bits).
1290 The argument is either a standard name, (use
1294 to see the list), or a numeric value to match.
1296 This module matches the time to live field in the IP header.
1298 .BI "--ttl-eq " "ttl"
1299 Matches the given TTL value.
1301 .BI "--ttl-gt " "ttl"
1302 Matches if TTL is greater than the given TTL value.
1304 .BI "--ttl-lt " "ttl"
1305 Matches if TTL is less than the given TTL value.
1307 U32 allows you to extract quantities of up to 4 bytes from a packet,
1308 AND them with specified masks, shift them by specified amounts and
1309 test whether the results are in any of a set of specified ranges.
1310 The specification of what to extract is general enough to skip over
1311 headers with lengths stored in the packet, as in IP or TCP header
1314 Details and examples are in the kernel module source.
1316 These extensions are loaded if `--protocol udp' is specified. It
1317 provides the following options:
1319 .BR "--source-port " "[!] \fIport\fP[:\fIport\fP]"
1320 Source port or port range specification.
1321 See the description of the
1323 option of the TCP extension for details.
1325 .BR "--destination-port " "[!] \fIport\fP[:\fIport\fP]"
1326 Destination port or port range specification.
1327 See the description of the
1328 .B --destination-port
1329 option of the TCP extension for details.
1331 This module takes no options, but attempts to match packets which seem
1332 malformed or unusual. This is regarded as experimental.
1333 .SH TARGET EXTENSIONS
1334 iptables can use extended target modules: the following are included
1335 in the standard distribution.
1338 This allows you to DNAT connections in a round-robin way over a given range of destination addresses.
1340 .BI "--to-destination " "ipaddr-ipaddr"
1341 Address range to round-robin over.
1343 This module allows you to set the skb->priority value (and thus classify the packet into a specific CBQ class).
1345 .BI "--set-class " "MAJOR:MINOR"
1346 Set the major and minor class value.
1348 This module allows you to configure a simple cluster of nodes that share
1349 a certain IP and MAC address without an explicit load balancer in front of
1350 them. Connections are statically distributed between the nodes in this
1354 Create a new ClusterIP. You always have to set this on the first rule
1355 for a given ClusterIP.
1357 .BI "--hashmode " "mode"
1358 Specify the hashing mode. Has to be one of
1359 .B sourceip, sourceip-sourceport, sourceip-sourceport-destport
1361 .BI "--clustermac " "mac"
1362 Specify the ClusterIP MAC address. Has to be a link-layer multicast address
1364 .BI "--total-nodes " "num"
1365 Number of total nodes within this cluster.
1367 .BI "--local-node " "num"
1368 Local node number within this cluster.
1370 .BI "--hash-init " "rnd"
1371 Specify the random seed used for hash initialization.
1373 This module sets the netfilter mark value associated with a connection
1375 .B --set-mark mark[/mask]
1376 Set connection mark. If a mask is specified then only those bits set in the
1379 .B --save-mark [--mask mask]
1380 Copy the netfilter packet mark value to the connection mark. If a mask
1381 is specified then only those bits are copied.
1383 .B --restore-mark [--mask mask]
1384 Copy the connection mark value to the packet. If a mask is specified
1385 then only those bits are copied. This is only valid in the
1389 This target is only valid in the
1395 chains, and user-defined chains which are only called from those
1396 chains. It specifies that the destination address of the packet
1397 should be modified (and all future packets in this connection will
1398 also be mangled), and rules should cease being examined. It takes one
1401 .BR "--to-destination " "\fIipaddr\fP[-\fIipaddr\fP][:\fIport\fP-\fIport\fP]"
1402 which can specify a single new destination IP address, an inclusive
1403 range of IP addresses, and optionally, a port range (which is only
1404 valid if the rule also specifies
1408 If no port range is specified, then the destination port will never be
1412 You can add several --to-destination options. If you specify more
1413 than one destination address, either via an address range or multiple
1414 --to-destination options, a simple round-robin (one after another in
1415 cycle) load balancing takes place between these adresses.
1417 This target allows to alter the value of the DSCP bits within the TOS
1418 header of the IPv4 packet. As this manipulates a packet, it can only
1419 be used in the mangle table.
1421 .BI "--set-dscp " "value"
1422 Set the DSCP field to a numerical value (can be decimal or hex)
1424 .BI "--set-dscp-class " "class"
1425 Set the DSCP field to a DiffServ class.
1427 This target allows to selectively work around known ECN blackholes.
1428 It can only be used in the mangle table.
1430 .BI "--ecn-tcp-remove"
1431 Remove all ECN bits from the TCP header. Of course, it can only be used
1435 Allows you to mark a received packet basing on its IP address. This
1436 can replace many mangle/mark entries with only one, if you use
1437 firewall based classifier.
1439 This target is to be used inside the mangle table, in the PREROUTING,
1440 POSTROUTING or FORWARD hooks.
1442 .BI "--addr " "src/dst"
1443 Use source or destination IP address.
1445 .BI "--and-mask " "mask"
1446 Perform bitwise `and' on the IP address and this mask.
1448 .BI "--or-mask " "mask"
1449 Perform bitwise `or' on the IP address and this mask.
1451 The order of IP address bytes is reversed to meet "human order of bytes":
1452 192.168.0.1 is 0xc0a80001. At first the `and' operation is performed, then
1457 We create a queue for each user, the queue number is adequate
1458 to the IP address of the user, e.g.: all packets going to/from 192.168.5.2
1459 are directed to 1:0502 queue, 192.168.5.12 -> 1:050c etc.
1461 We have one classifier rule:
1463 tc filter add dev eth3 parent 1:0 protocol ip fw
1465 Earlier we had many rules just like below:
1467 iptables -t mangle -A POSTROUTING -o eth3 -d 192.168.5.2 -j MARK
1470 iptables -t mangle -A POSTROUTING -o eth3 -d 192.168.5.3 -j MARK
1473 Using IPMARK target we can replace all the mangle/mark rules with only one:
1475 iptables -t mangle -A POSTROUTING -o eth3 -j IPMARK --addr=dst
1476 --and-mask=0xffff --or-mask=0x10000
1478 On the routers with hundreds of users there should be significant load
1479 decrease (e.g. twice).
1481 Strip all the IP options from a packet.
1483 The target doesn't take any option, and therefore is extremly easy to use :
1485 # iptables -t mangle -A PREROUTING -j IPV4OPTSSTRIP
1487 Turn on kernel logging of matching packets. When this option is set
1488 for a rule, the Linux kernel will print some information on all
1489 matching packets (like most IP header fields) via the kernel log
1490 (where it can be read with
1494 This is a "non-terminating target", i.e. rule traversal continues at
1495 the next rule. So if you want to LOG the packets you refuse, use two
1496 separate rules with the same matching criteria, first using target LOG
1497 then DROP (or REJECT).
1499 .BI "--log-level " "level"
1500 Level of logging (numeric or see \fIsyslog.conf\fP(5)).
1502 .BI "--log-prefix " "prefix"
1503 Prefix log messages with the specified prefix; up to 29 letters long,
1504 and useful for distinguishing messages in the logs.
1506 .B --log-tcp-sequence
1507 Log TCP sequence numbers. This is a security risk if the log is
1510 .B --log-tcp-options
1511 Log options from the TCP packet header.
1514 Log options from the IP packet header.
1517 Log the userid of the process which generated the packet.
1519 This is used to set the netfilter mark value associated with the
1520 packet. It is only valid in the
1522 table. It can for example be used in conjunction with iproute2.
1524 .BI "--set-mark " "mark"
1526 This target is only valid in the
1530 chain. It should only be used with dynamically assigned IP (dialup)
1531 connections: if you have a static IP address, you should use the SNAT
1532 target. Masquerading is equivalent to specifying a mapping to the IP
1533 address of the interface the packet is going out, but also has the
1534 effect that connections are
1536 when the interface goes down. This is the correct behavior when the
1537 next dialup is unlikely to have the same interface address (and hence
1538 any established connections are lost anyway). It takes one option:
1540 .BR "--to-ports " "\fIport\fP[-\fIport\fP]"
1541 This specifies a range of source ports to use, overriding the default
1543 source port-selection heuristics (see above). This is only valid
1544 if the rule also specifies
1549 This is an experimental demonstration target which inverts the source
1550 and destination fields in the IP header and retransmits the packet.
1551 It is only valid in the
1556 chains, and user-defined chains which are only called from those
1557 chains. Note that the outgoing packets are
1559 seen by any packet filtering chains, connection tracking or NAT, to
1560 avoid loops and other problems.
1562 This target allows you to statically map a whole network of addresses onto
1563 another network of addresses. It can only be used from rules in the
1567 .BI "--to " "address[/mask]"
1568 Network address to map to. The resulting address will be constructed in the
1569 following way: All 'one' bits in the mask are filled in from the new `address'.
1570 All bits that are zero in the mask are filled in from the original address.
1572 This target disables connection tracking for all packets matching that rule.
1574 It can only be used in the
1578 This target is only valid in the
1584 chains, and user-defined chains which are only called from those
1585 chains. It redirects the packet to the machine itself by changing the
1586 destination IP to the primary address of the incoming interface
1587 (locally-generated packets are mapped to the 127.0.0.1 address). It
1590 .BR "--to-ports " "\fIport\fP[-\fIport\fP]"
1591 This specifies a destination port or range of ports to use: without
1592 this, the destination port is never altered. This is only valid
1593 if the rule also specifies
1598 This is used to send back an error packet in response to the matched
1599 packet: otherwise it is equivalent to
1601 so it is a terminating TARGET, ending rule traversal.
1602 This target is only valid in the
1607 chains, and user-defined chains which are only called from those
1608 chains. The following option controls the nature of the error packet
1611 .BI "--reject-with " "type"
1612 The type given can be
1614 .B " icmp-net-unreachable"
1615 .B " icmp-host-unreachable"
1616 .B " icmp-port-unreachable"
1617 .B " icmp-proto-unreachable"
1618 .B " icmp-net-prohibited"
1619 .B " icmp-host-prohibited or"
1620 .B " icmp-admin-prohibited (*)"
1622 which return the appropriate ICMP error message (\fBport-unreachable\fP is
1623 the default). The option
1625 can be used on rules which only match the TCP protocol: this causes a
1626 TCP RST packet to be sent back. This is mainly useful for blocking
1628 (113/tcp) probes which frequently occur when sending mail to broken mail
1629 hosts (which won't accept your mail otherwise).
1631 (*) Using icmp-admin-prohibited with kernels that do not support it will result in a plain DROP instead of REJECT
1633 This is used to explicitly override the core network stack's routing decision.
1637 .BI "--oif " "ifname"
1638 Route the packet through `ifname' network interface
1640 .BI "--iif " "ifname"
1641 Change the packet's incoming interface to `ifname'
1643 .BI "--gw " "IP_address"
1644 Route the packet via this gateway
1647 Behave like a non-terminating target and continue traversing the rules. Not valid in combination with `--iif' or `--tee'
1650 Make a copy of the packet, and route that copy to the given destination. For the original, uncopied packet, behave like a non-terminating target and continue traversing the rules. Not valid in combination with `--iif' or `--continue'
1652 Similar to SNAT/DNAT depending on chain: it takes a range of addresses
1653 (`--to 1.2.3.4-1.2.3.7') and gives a client the same
1654 source-/destination-address for each connection.
1656 .BI "--to " "<ipaddr>-<ipaddr>"
1657 Addresses to map source to. May be specified more than once for
1661 Don't use the destination-ip in the calculations when selecting the
1664 This modules adds and/or deletes entries from IP sets which can be defined
1667 .BR "--add-set " "setname flag[,flag...]"
1668 add the address(es)/port(s) of the packet to the sets
1670 .BR "--del-set " "setname flag[,flag...]"
1671 delete the address(es)/port(s) of the packet from the sets,
1676 and there can be no more than six of them.
1678 The bindings to follow must previously be defined in order to use
1679 multilevel adding/deleting by the SET target.
1681 This target is only valid in the
1685 chain. It specifies that the source address of the packet should be
1686 modified (and all future packets in this connection will also be
1687 mangled), and rules should cease being examined. It takes one type
1690 .BR "--to-source " "\fIipaddr\fP[-\fIipaddr\fP][:\fIport\fP-\fIport\fP]"
1691 which can specify a single new source IP address, an inclusive range
1692 of IP addresses, and optionally, a port range (which is only valid if
1693 the rule also specifies
1697 If no port range is specified, then source ports below 512 will be
1698 mapped to other ports below 512: those between 512 and 1023 inclusive
1699 will be mapped to ports below 1024, and other ports will be mapped to
1700 1024 or above. Where possible, no port alteration will occur.
1703 You can add several --to-source options. If you specify more
1704 than one source address, either via an address range or multiple
1705 --to-source options, a simple round-robin (one after another in
1706 cycle) takes place between these adresses.
1708 Captures and holds incoming TCP connections using no local
1709 per-connection resources. Connections are accepted, but immediately
1710 switched to the persist state (0 byte window), in which the remote
1711 side stops sending data and asks to continue every 60-240 seconds.
1712 Attempts to close the connection are ignored, forcing the remote side
1713 to time out the connection in 12-24 minutes.
1715 This offers similar functionality to LaBrea
1716 <http://www.hackbusters.net/LaBrea/> but doesn't require dedicated
1717 hardware or IPs. Any TCP port that you would normally DROP or REJECT
1718 can instead become a tarpit.
1720 To tarpit connections to TCP port 80 destined for the current machine:
1722 iptables -A INPUT -p tcp -m tcp --dport 80 -j TARPIT
1724 To significantly slow down Code Red/Nimda-style scans of unused address
1725 space, forward unused ip addresses to a Linux box not acting as a router
1726 (e.g. "ip route 10.0.0.0 255.0.0.0 ip.of.linux.box" on a Cisco), enable IP
1727 forwarding on the Linux box, and add:
1729 iptables -A FORWARD -p tcp -j TARPIT
1731 iptables -A FORWARD -j DROP
1734 If you use the conntrack module while you are using TARPIT, you should
1735 also use the NOTRACK target, or the kernel will unnecessarily allocate
1736 resources for each TARPITted connection. To TARPIT incoming
1737 connections to the standard IRC port while using conntrack, you could:
1739 iptables -t raw -A PREROUTING -p tcp --dport 6667 -j NOTRACK
1741 iptables -A INPUT -p tcp --dport 6667 -j TARPIT
1743 This target allows to alter the MSS value of TCP SYN packets, to control
1744 the maximum size for that connection (usually limiting it to your
1745 outgoing interface's MTU minus 40). Of course, it can only be used
1749 This target is used to overcome criminally braindead ISPs or servers
1750 which block ICMP Fragmentation Needed packets. The symptoms of this
1751 problem are that everything works fine from your Linux
1752 firewall/router, but machines behind it can never exchange large
1758 Web browsers connect, then hang with no data received.
1761 Small mail works fine, but large emails hang.
1764 ssh works fine, but scp hangs after initial handshaking.
1767 Workaround: activate this option and add a rule to your firewall
1770 iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN \\
1771 -j TCPMSS --clamp-mss-to-pmtu
1774 .BI "--set-mss " "value"
1775 Explicitly set MSS option to specified value.
1777 .B "--clamp-mss-to-pmtu"
1778 Automatically clamp MSS value to (path_MTU - 40).
1780 These options are mutually exclusive.
1782 This is used to set the 8-bit Type of Service field in the IP header.
1783 It is only valid in the
1787 .BI "--set-tos " "tos"
1788 You can use a numeric TOS values, or use
1792 to see the list of valid TOS names.
1794 This target has no options. It just turns on
1796 for all packets that match this rule.
1798 This is used to modify the IPv4 TTL header field. The TTL field determines
1799 how many hops (routers) a packet can traverse until it's time to live is
1802 Setting or incrementing the TTL field can potentially be very dangerous,
1803 so it should be avoided at any cost.
1805 .B Don't ever set or increment the value on packets that leave your local network!
1809 .BI "--ttl-set " "value"
1810 Set the TTL value to `value'.
1812 .BI "--ttl-dec " "value"
1813 Decrement the TTL value `value' times.
1815 .BI "--ttl-inc " "value"
1816 Increment the TTL value `value' times.
1818 This target provides userspace logging of matching packets. When this
1819 target is set for a rule, the Linux kernel will multicast this packet
1822 socket. One or more userspace processes may then subscribe to various
1823 multicast groups and receive the packets.
1824 Like LOG, this is a "non-terminating target", i.e. rule traversal
1825 continues at the next rule.
1827 .BI "--ulog-nlgroup " "nlgroup"
1828 This specifies the netlink group (1-32) to which the packet is sent.
1831 .BI "--ulog-prefix " "prefix"
1832 Prefix log messages with the specified prefix; up to 32 characters
1833 long, and useful for distinguishing messages in the logs.
1835 .BI "--ulog-cprange " "size"
1836 Number of bytes to be copied to userspace. A value of 0 always copies
1837 the entire packet, regardless of its size. Default is 0.
1839 .BI "--ulog-qthreshold " "size"
1840 Number of packet to queue inside kernel. Setting this value to, e.g. 10
1841 accumulates ten packets inside the kernel and transmits them as one
1842 netlink multipart message to userspace. Default is 1 (for backwards
1846 Encrypt TCP and UDP traffic using a simple XOR encryption
1848 .BI "--key " "string"
1854 Various error messages are printed to standard error. The exit code
1855 is 0 for correct functioning. Errors which appear to be caused by
1856 invalid or abused command line parameters cause an exit code of 2, and
1857 other errors cause an exit code of 1.
1859 Bugs? What's this? ;-)
1860 Well, you might want to have a look at http://bugzilla.netfilter.org/
1861 .SH COMPATIBILITY WITH IPCHAINS
1864 is very similar to ipchains by Rusty Russell. The main difference is
1869 are only traversed for packets coming into the local host and
1870 originating from the local host respectively. Hence every packet only
1871 passes through one of the three chains (except loopback traffic, which
1872 involves both INPUT and OUTPUT chains); previously a forwarded packet
1873 would pass through all three.
1875 The other main difference is that
1877 refers to the input interface;
1879 refers to the output interface, and both are available for packets
1883 .PP The various forms of NAT have been separated out;
1885 is a pure packet filter when using the default `filter' table, with
1886 optional extension modules. This should simplify much of the previous
1887 confusion over the combination of IP masquerading and packet filtering
1888 seen previously. So the following options are handled differently:
1894 There are several other changes in iptables.
1896 .BR iptables-save (8),
1897 .BR iptables-restore (8),
1899 .BR ip6tables-save (8),
1900 .BR ip6tables-restore (8).
1902 The packet-filtering-HOWTO details iptables usage for
1903 packet filtering, the NAT-HOWTO details NAT,
1904 the netfilter-extensions-HOWTO details the extensions that are
1905 not in the standard distribution,
1906 and the netfilter-hacking-HOWTO details the netfilter internals.
1909 .BR "http://www.netfilter.org/" .
1911 Rusty Russell wrote iptables, in early consultation with Michael
1914 Marc Boucher made Rusty abandon ipnatctl by lobbying for a generic packet
1915 selection framework in iptables, then wrote the mangle table, the owner match,
1916 the mark stuff, and ran around doing cool stuff everywhere.
1918 James Morris wrote the TOS target, and tos match.
1920 Jozsef Kadlecsik wrote the REJECT target.
1922 Harald Welte wrote the ULOG target, TTL, DSCP, ECN matches and targets.
1924 The Netfilter Core Team is: Marc Boucher, Martin Josefsson, Jozsef Kadlecsik,
1925 Patrick McHardy, James Morris, Harald Welte and Rusty Russell.
1927 Man page written by Herve Eychenne <rv@wallfire.org>.
1928 .\" .. and did I mention that we are incredibly cool people?
1930 .\" .. witty, charming, powerful ..
1931 .\" .. and most of all, modest ..