Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 1 | .TH IPTABLES 8 "Mar 09, 2002" "" "" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 2 | .\" |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 3 | .\" Man page written by Herve Eychenne <rv@wallfire.org> (May 1999) |
| 4 | .\" It is based on ipchains page. |
Hervé Eychenne | cea2ca3 | 2002-05-27 11:16:09 +0000 | [diff] [blame] | 5 | .\" TODO: add a word for protocol helpers (FTP, IRC, SNMP-ALG) |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 6 | .\" |
| 7 | .\" ipchains page by Paul ``Rusty'' Russell March 1997 |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 8 | .\" Based on the original ipfwadm man page by Jos Vos <jos@xos.nl> |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 9 | .\" |
| 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. |
| 14 | .\" |
| 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. |
| 19 | .\" |
| 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. |
| 23 | .\" |
| 24 | .\" |
| 25 | .SH NAME |
Hervé Eychenne | cea2ca3 | 2002-05-27 11:16:09 +0000 | [diff] [blame] | 26 | iptables \- administration tool for IPv4 packet filtering and NAT |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 27 | .SH SYNOPSIS |
Hervé Eychenne | e644cb0 | 2002-06-22 18:23:48 +0000 | [diff] [blame] | 28 | .BR "iptables [-t table] -[ADC] " "chain rule-specification [options]" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 29 | .br |
Hervé Eychenne | e644cb0 | 2002-06-22 18:23:48 +0000 | [diff] [blame] | 30 | .BR "iptables [-t table] -I " "chain [rulenum] rule-specification [options]" |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 31 | .br |
Hervé Eychenne | e644cb0 | 2002-06-22 18:23:48 +0000 | [diff] [blame] | 32 | .BR "iptables [-t table] -R " "chain rulenum rule-specification [options]" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 33 | .br |
Hervé Eychenne | e644cb0 | 2002-06-22 18:23:48 +0000 | [diff] [blame] | 34 | .BR "iptables [-t table] -D " "chain rulenum [options]" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 35 | .br |
Hervé Eychenne | e644cb0 | 2002-06-22 18:23:48 +0000 | [diff] [blame] | 36 | .BR "iptables [-t table] -[LFZ] " "[chain] [options]" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 37 | .br |
Hervé Eychenne | e644cb0 | 2002-06-22 18:23:48 +0000 | [diff] [blame] | 38 | .BR "iptables [-t table] -N " "chain" |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 39 | .br |
Hervé Eychenne | e644cb0 | 2002-06-22 18:23:48 +0000 | [diff] [blame] | 40 | .BR "iptables [-t table] -X " "[chain]" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 41 | .br |
Hervé Eychenne | e644cb0 | 2002-06-22 18:23:48 +0000 | [diff] [blame] | 42 | .BR "iptables [-t table] -P " "chain target [options]" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 43 | .br |
Hervé Eychenne | e644cb0 | 2002-06-22 18:23:48 +0000 | [diff] [blame] | 44 | .BR "iptables [-t table] -E " "old-chain-name new-chain-name" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 45 | .SH DESCRIPTION |
| 46 | .B Iptables |
| 47 | is used to set up, maintain, and inspect the tables of IP packet |
Harald Welte | 0112abb | 2001-02-19 21:48:13 +0000 | [diff] [blame] | 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. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 51 | |
Harald Welte | 0112abb | 2001-02-19 21:48:13 +0000 | [diff] [blame] | 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 |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 54 | a `target', which may be a jump to a user-defined chain in the same |
| 55 | table. |
| 56 | |
| 57 | .SH TARGETS |
| 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 |
Harald Welte | 0112abb | 2001-02-19 21:48:13 +0000 | [diff] [blame] | 61 | target, which can be the name of a user-defined chain or one of the |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 62 | special values |
| 63 | .IR ACCEPT , |
| 64 | .IR DROP , |
| 65 | .IR QUEUE , |
| 66 | or |
| 67 | .IR RETURN . |
| 68 | .PP |
| 69 | .I ACCEPT |
| 70 | means to let the packet through. |
| 71 | .I DROP |
| 72 | means to drop the packet on the floor. |
| 73 | .I QUEUE |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 74 | means to pass the packet to userspace (if supported by the kernel). |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 75 | .I RETURN |
Harald Welte | 0112abb | 2001-02-19 21:48:13 +0000 | [diff] [blame] | 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 |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 78 | or a rule in a built-in chain with target |
| 79 | .I RETURN |
| 80 | is matched, the target specified by the chain policy determines the |
| 81 | fate of the packet. |
| 82 | .SH TABLES |
Hervé Eychenne | e644cb0 | 2002-06-22 18:23:48 +0000 | [diff] [blame] | 83 | There are currently three independent tables (which tables are present |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 84 | at any time depends on the kernel configuration options and which |
| 85 | modules are present). |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 86 | .TP |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 87 | .BI "-t, --table " "table" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 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. |
| 92 | |
| 93 | The tables are as follows: |
Harald Welte | 87d4be4 | 2001-07-05 06:26:37 +0000 | [diff] [blame] | 94 | .TP |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 95 | .B "filter" |
Hervé Eychenne | e644cb0 | 2002-06-22 18:23:48 +0000 | [diff] [blame] | 96 | This is the default table (if no -t option is passed). It contains |
| 97 | the built-in chains |
Hervé Eychenne | cea2ca3 | 2002-05-27 11:16:09 +0000 | [diff] [blame] | 98 | .B INPUT |
| 99 | (for packets coming into the box itself), |
| 100 | .B FORWARD |
| 101 | (for packets being routed through the box), and |
| 102 | .B OUTPUT |
| 103 | (for locally-generated packets). |
Harald Welte | 87d4be4 | 2001-07-05 06:26:37 +0000 | [diff] [blame] | 104 | .TP |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 105 | .B "nat" |
Harald Welte | 0112abb | 2001-02-19 21:48:13 +0000 | [diff] [blame] | 106 | This table is consulted when a packet that creates a new |
Hervé Eychenne | cea2ca3 | 2002-05-27 11:16:09 +0000 | [diff] [blame] | 107 | connection is encountered. It consists of three built-ins: |
| 108 | .B PREROUTING |
| 109 | (for altering packets as soon as they come in), |
| 110 | .B OUTPUT |
| 111 | (for altering locally-generated packets before routing), and |
| 112 | .B POSTROUTING |
| 113 | (for altering packets as they are about to go out). |
Harald Welte | 87d4be4 | 2001-07-05 06:26:37 +0000 | [diff] [blame] | 114 | .TP |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 115 | .B "mangle" |
| 116 | This table is used for specialized packet alteration. Until kernel |
Hervé Eychenne | cea2ca3 | 2002-05-27 11:16:09 +0000 | [diff] [blame] | 117 | 2.4.17 it had two built-in chains: |
| 118 | .B PREROUTING |
| 119 | (for altering incoming packets before routing) and |
| 120 | .B OUTPUT |
| 121 | (for altering locally-generated packets before routing). |
| 122 | Since kernel 2.4.18, three other built-in chains are also supported: |
| 123 | .B INPUT |
| 124 | (for packets coming into the box itself), |
| 125 | .B FORWARD |
| 126 | (for altering packets being routed through the box), and |
| 127 | .B POSTROUTING |
| 128 | (for altering packets as they are about to go out). |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 129 | .SH OPTIONS |
| 130 | The options that are recognized by |
| 131 | .B iptables |
| 132 | can be divided into several different groups. |
| 133 | .SS COMMANDS |
Harald Welte | 0112abb | 2001-02-19 21:48:13 +0000 | [diff] [blame] | 134 | These options specify the specific action to perform. Only one of them |
| 135 | can be specified on the command line unless otherwise specified |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 136 | below. For all the long versions of the command and option names, you |
Harald Welte | 0112abb | 2001-02-19 21:48:13 +0000 | [diff] [blame] | 137 | need to use only enough letters to ensure that |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 138 | .B iptables |
| 139 | can differentiate it from all other options. |
| 140 | .TP |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 141 | .BI "-A, --append " "chain rule-specification" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 142 | Append one or more rules to the end of the selected chain. |
| 143 | When the source and/or destination names resolve to more than one |
| 144 | address, a rule will be added for each possible address combination. |
| 145 | .TP |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 146 | .BI "-D, --delete " "chain rule-specification" |
| 147 | .ns |
| 148 | .TP |
| 149 | .BI "-D, --delete " "chain rulenum" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 150 | Delete one or more rules from the selected chain. There are two |
| 151 | versions of this command: the rule can be specified as a number in the |
| 152 | chain (starting at 1 for the first rule) or a rule to match. |
| 153 | .TP |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 154 | .BR "-I, --insert " "\fIchain\fP [\fIrulenum\fP] \fIrule-specification\fP" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 155 | Insert one or more rules in the selected chain as the given rule |
| 156 | number. So, if the rule number is 1, the rule or rules are inserted |
| 157 | at the head of the chain. This is also the default if no rule number |
| 158 | is specified. |
| 159 | .TP |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 160 | .BI "-R, --replace " "chain rulenum rule-specification" |
| 161 | Replace a rule in the selected chain. If the source and/or |
| 162 | destination names resolve to multiple addresses, the command will |
| 163 | fail. Rules are numbered starting at 1. |
| 164 | .TP |
| 165 | .BR "-L, --list " "[\fIchain\fP]" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 166 | List all rules in the selected chain. If no chain is selected, all |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 167 | chains are listed. As every other iptables command, it applies to the |
| 168 | specified table (filter is the default), so NAT rules get listed by |
| 169 | .br |
| 170 | iptables -t nat -n -L |
| 171 | .br |
| 172 | Please note that it is often used with the |
| 173 | .B -n |
| 174 | option, in order to avoid long reverse DNS lookups. |
| 175 | It is legal to specify the |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 176 | .B -Z |
| 177 | (zero) option as well, in which case the chain(s) will be atomically |
Harald Welte | 0112abb | 2001-02-19 21:48:13 +0000 | [diff] [blame] | 178 | listed and zeroed. The exact output is affected by the other |
Harald Welte | bfc3369 | 2002-08-07 09:52:22 +0000 | [diff] [blame] | 179 | arguments given. The exact rules are suppressed until you use |
| 180 | .br |
| 181 | iptables -L -v |
| 182 | .br |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 183 | .TP |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 184 | .BR "-F, --flush " "[\fIchain\fP]" |
| 185 | Flush the selected chain (all the chains in the table if none is given). |
| 186 | This is equivalent to deleting all the rules one by one. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 187 | .TP |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 188 | .BR "-Z, --zero " "[\fIchain\fP]" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 189 | Zero the packet and byte counters in all chains. It is legal to |
| 190 | specify the |
| 191 | .B "-L, --list" |
| 192 | (list) option as well, to see the counters immediately before they are |
Harald Welte | 0112abb | 2001-02-19 21:48:13 +0000 | [diff] [blame] | 193 | cleared. (See above.) |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 194 | .TP |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 195 | .BI "-N, --new-chain " "chain" |
Harald Welte | 0112abb | 2001-02-19 21:48:13 +0000 | [diff] [blame] | 196 | Create a new user-defined chain by the given name. There must be no |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 197 | target of that name already. |
| 198 | .TP |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 199 | .BR "-X, --delete-chain " "[\fIchain\fP]" |
| 200 | Delete the optional user-defined chain specified. There must be no references |
Harald Welte | 0112abb | 2001-02-19 21:48:13 +0000 | [diff] [blame] | 201 | to the chain. If there are, you must delete or replace the referring |
| 202 | rules before the chain can be deleted. If no argument is given, it |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 203 | will attempt to delete every non-builtin chain in the table. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 204 | .TP |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 205 | .BI "-P, --policy " "chain target" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 206 | Set the policy for the chain to the given target. See the section |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 207 | .B TARGETS |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 208 | for the legal targets. Only built-in (non-user-defined) chains can have |
| 209 | policies, and neither built-in nor user-defined chains can be policy |
| 210 | targets. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 211 | .TP |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 212 | .BI "-E, --rename-chain " "old-chain new-chain" |
Harald Welte | 0112abb | 2001-02-19 21:48:13 +0000 | [diff] [blame] | 213 | Rename the user specified chain to the user supplied name. This is |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 214 | cosmetic, and has no effect on the structure of the table. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 215 | .TP |
| 216 | .B -h |
| 217 | Help. |
| 218 | Give a (currently very brief) description of the command syntax. |
| 219 | .SS PARAMETERS |
| 220 | The following parameters make up a rule specification (as used in the |
Harald Welte | 0112abb | 2001-02-19 21:48:13 +0000 | [diff] [blame] | 221 | add, delete, insert, replace and append commands). |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 222 | .TP |
Rusty Russell | 2e0a321 | 2000-04-19 11:23:18 +0000 | [diff] [blame] | 223 | .BR "-p, --protocol " "[!] \fIprotocol\fP" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 224 | The protocol of the rule or of the packet to check. |
| 225 | The specified protocol can be one of |
| 226 | .IR tcp , |
| 227 | .IR udp , |
| 228 | .IR icmp , |
| 229 | or |
| 230 | .IR all , |
| 231 | or it can be a numeric value, representing one of these protocols or a |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 232 | different one. A protocol name from /etc/protocols is also allowed. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 233 | A "!" argument before the protocol inverts the |
| 234 | test. The number zero is equivalent to |
| 235 | .IR all . |
| 236 | Protocol |
| 237 | .I all |
| 238 | will match with all protocols and is taken as default when this |
| 239 | option is omitted. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 240 | .TP |
| 241 | .BR "-s, --source " "[!] \fIaddress\fP[/\fImask\fP]" |
| 242 | Source specification. |
| 243 | .I Address |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 244 | can be either a network name, a hostname (please note that specifying |
| 245 | any name to be resolved with a remote query such as DNS is a really bad idea), |
| 246 | a network IP address (with /mask), or a plain IP address. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 247 | The |
| 248 | .I mask |
| 249 | can be either a network mask or a plain number, |
| 250 | specifying the number of 1's at the left side of the network mask. |
| 251 | Thus, a mask of |
| 252 | .I 24 |
| 253 | is equivalent to |
| 254 | .IR 255.255.255.0 . |
| 255 | A "!" argument before the address specification inverts the sense of |
| 256 | the address. The flag |
| 257 | .B --src |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 258 | is an alias for this option. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 259 | .TP |
| 260 | .BR "-d, --destination " "[!] \fIaddress\fP[/\fImask\fP]" |
| 261 | Destination specification. |
| 262 | See the description of the |
| 263 | .B -s |
| 264 | (source) flag for a detailed description of the syntax. The flag |
| 265 | .B --dst |
| 266 | is an alias for this option. |
| 267 | .TP |
| 268 | .BI "-j, --jump " "target" |
Harald Welte | 0112abb | 2001-02-19 21:48:13 +0000 | [diff] [blame] | 269 | This specifies the target of the rule; i.e., what to do if the packet |
| 270 | matches it. The target can be a user-defined chain (other than the |
| 271 | one this rule is in), one of the special builtin targets which decide |
| 272 | the fate of the packet immediately, or an extension (see |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 273 | .B EXTENSIONS |
| 274 | below). If this |
| 275 | option is omitted in a rule, then matching the rule will have no |
| 276 | effect on the packet's fate, but the counters on the rule will be |
| 277 | incremented. |
| 278 | .TP |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 279 | .BR "-i, --in-interface " "[!] \fIname\fP" |
| 280 | Name of an interface via which a packet is going to be received (only for |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 281 | packets entering the |
| 282 | .BR INPUT , |
| 283 | .B FORWARD |
| 284 | and |
| 285 | .B PREROUTING |
| 286 | chains). When the "!" argument is used before the interface name, the |
| 287 | sense is inverted. If the interface name ends in a "+", then any |
| 288 | interface which begins with this name will match. If this option is |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 289 | omitted, any interface name will match. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 290 | .TP |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 291 | .BR "-o, --out-interface " "[!] \fIname\fP" |
| 292 | Name of an interface via which a packet is going to be sent (for packets |
| 293 | entering the |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 294 | .BR FORWARD , |
| 295 | .B OUTPUT |
| 296 | and |
| 297 | .B POSTROUTING |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 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 |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 300 | interface which begins with this name will match. If this option is |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 301 | omitted, any interface name will match. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 302 | .TP |
| 303 | .B "[!] " "-f, --fragment" |
| 304 | This means that the rule only refers to second and further fragments |
| 305 | of fragmented packets. Since there is no way to tell the source or |
| 306 | destination ports of such a packet (or ICMP type), such a packet will |
| 307 | not match any rules which specify them. When the "!" argument |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 308 | precedes the "-f" flag, the rule will only match head fragments, or |
| 309 | unfragmented packets. |
Harald Welte | ccd49e5 | 2001-01-23 22:54:34 +0000 | [diff] [blame] | 310 | .TP |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 311 | .BI "-c, --set-counters " "PKTS BYTES" |
Fabrice MARIE | b0d8460 | 2002-06-14 07:39:58 +0000 | [diff] [blame] | 312 | This enables the administrator to initialize the packet and byte |
Harald Welte | ccd49e5 | 2001-01-23 22:54:34 +0000 | [diff] [blame] | 313 | counters of a rule (during |
| 314 | .B INSERT, |
| 315 | .B APPEND, |
| 316 | .B REPLACE |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 317 | operations). |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 318 | .SS "OTHER OPTIONS" |
| 319 | The following additional options can be specified: |
| 320 | .TP |
| 321 | .B "-v, --verbose" |
| 322 | Verbose output. This option makes the list command show the interface |
Harald Welte | bfc3369 | 2002-08-07 09:52:22 +0000 | [diff] [blame] | 323 | name, the rule options (if any), and the TOS masks. The packet and |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 324 | byte counters are also listed, with the suffix 'K', 'M' or 'G' for |
| 325 | 1000, 1,000,000 and 1,000,000,000 multipliers respectively (but see |
| 326 | the |
| 327 | .B -x |
| 328 | flag to change this). |
| 329 | For appending, insertion, deletion and replacement, this causes |
| 330 | detailed information on the rule or rules to be printed. |
| 331 | .TP |
| 332 | .B "-n, --numeric" |
| 333 | Numeric output. |
| 334 | IP addresses and port numbers will be printed in numeric format. |
| 335 | By default, the program will try to display them as host names, |
| 336 | network names, or services (whenever applicable). |
| 337 | .TP |
| 338 | .B "-x, --exact" |
| 339 | Expand numbers. |
| 340 | Display the exact value of the packet and byte counters, |
| 341 | instead of only the rounded number in K's (multiples of 1000) |
| 342 | M's (multiples of 1000K) or G's (multiples of 1000M). This option is |
Marc Boucher | f127a19 | 2000-03-20 08:32:15 +0000 | [diff] [blame] | 343 | only relevant for the |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 344 | .B -L |
| 345 | command. |
| 346 | .TP |
| 347 | .B "--line-numbers" |
| 348 | When listing rules, add line numbers to the beginning of each rule, |
| 349 | corresponding to that rule's position in the chain. |
Chapman Brad | 45493a8 | 2001-02-23 09:08:13 +0000 | [diff] [blame] | 350 | .TP |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 351 | .B "--modprobe=command" |
Chapman Brad | 45493a8 | 2001-02-23 09:08:13 +0000 | [diff] [blame] | 352 | When adding or inserting rules into a chain, use |
| 353 | .B command |
| 354 | to load any necessary modules (targets, match extensions, etc). |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 355 | .SH MATCH EXTENSIONS |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 356 | iptables can use extended packet matching modules. These are loaded |
| 357 | in two ways: implicitly, when |
| 358 | .B -p |
| 359 | or |
| 360 | .B --protocol |
| 361 | is specified, or with the |
| 362 | .B -m |
| 363 | or |
| 364 | .B --match |
| 365 | options, followed by the matching module name; after these, various |
| 366 | extra command line options become available, depending on the specific |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 367 | module. You can specify multiple extended match modules in one line, |
| 368 | and you can use the |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 369 | .B -h |
| 370 | or |
| 371 | .B --help |
| 372 | options after the module has been specified to receive help specific |
| 373 | to that module. |
| 374 | |
| 375 | The following are included in the base package, and most of these can |
| 376 | be preceded by a |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 377 | .B ! |
| 378 | to invert the sense of the match. |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 379 | .SS ah |
| 380 | This module matches the SPIs in AH header of IPSec packets. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 381 | .TP |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 382 | .BR "--ahspi " "[!] \fIspi\fP[:\fIspi\fP]" |
Harald Welte | bfc3369 | 2002-08-07 09:52:22 +0000 | [diff] [blame] | 383 | .SS conntrack |
| 384 | This module, when combined with connection tracking, allows access to |
| 385 | more connection tracking information than the "state" match. |
| 386 | (this module is present only if iptables was compiled under a kernel |
| 387 | supporting this feature) |
| 388 | .TP |
| 389 | .BI "--ctstate " "state" |
| 390 | Where state is a comma separated list of the connection states to |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 391 | match. Possible states are |
Harald Welte | bfc3369 | 2002-08-07 09:52:22 +0000 | [diff] [blame] | 392 | .B INVALID |
| 393 | meaning that the packet is associated with no known connection, |
| 394 | .B ESTABLISHED |
| 395 | meaning that the packet is associated with a connection which has seen |
| 396 | packets in both directions, |
| 397 | .B NEW |
| 398 | meaning that the packet has started a new connection, or otherwise |
| 399 | associated with a connection which has not seen packets in both |
| 400 | directions, and |
| 401 | .B RELATED |
| 402 | meaning that the packet is starting a new connection, but is |
| 403 | associated with an existing connection, such as an FTP data transfer, |
| 404 | or an ICMP error. |
| 405 | .B SNAT |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 406 | A virtual state, matching if the original source address differs from |
Harald Welte | bfc3369 | 2002-08-07 09:52:22 +0000 | [diff] [blame] | 407 | the reply destination. |
| 408 | .B DNAT |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 409 | A virtual state, matching if the original destination differs from the |
Harald Welte | bfc3369 | 2002-08-07 09:52:22 +0000 | [diff] [blame] | 410 | reply source. |
| 411 | .TP |
| 412 | .BI "--ctproto " "proto" |
| 413 | Protocol to match (by number or name) |
| 414 | .TP |
| 415 | .BI "--ctorigsrc " "[!] \fIaddress\fP[/\fImask\fP]" |
| 416 | Match against original source address |
| 417 | .TP |
| 418 | .BI "--ctorigdst " "[!] \fIaddress\fP[/\fImask\fP]" |
| 419 | Match against original destination address |
| 420 | .TP |
| 421 | .BI "--ctreplsrc " "[!] \fIaddress\fP[/\fImask\fP]" |
| 422 | Match against reply source address |
| 423 | .TP |
| 424 | .BI "--ctrepldst " "[!] \fIaddress\fB[/\fImask\fP]" |
| 425 | Match against reply destination address |
| 426 | .TP |
| 427 | .BI "--ctstatus " "[\fINONE|EXPECTED|SEEN_REPLY|ASSURED\fP][,...]" |
| 428 | Match against internal conntrack states |
| 429 | .TP |
| 430 | .BI "--ctexpire " "\fItime\fP[\fI:time\fP]" |
| 431 | Match remaining lifetime in seconds against given value |
| 432 | or range of values (inclusive) |
| 433 | .SS dscp |
| 434 | This module matches the 6 bit DSCP field within the TOS field in the |
| 435 | IP header. DSCP has superseded TOS within the IETF. |
| 436 | .TP |
| 437 | .BI "--dscp " "value" |
| 438 | Match against a numeric (decimal or hex) value [0-32]. |
| 439 | .TP |
| 440 | .BI "--dscp-class " "\fIDiffServ Class\fP" |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 441 | Match the DiffServ class. This value may be any of the |
Harald Welte | bfc3369 | 2002-08-07 09:52:22 +0000 | [diff] [blame] | 442 | BE, EF, AFxx or CSx classes. It will then be converted |
| 443 | into it's according numeric value. |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 444 | .SS esp |
| 445 | This module matches the SPIs in ESP header of IPSec packets. |
| 446 | .TP |
| 447 | .BR "--espspi " "[!] \fIspi\fP[:\fIspi\fP]" |
Hervé Eychenne | 9230c11 | 2003-03-03 22:23:22 +0000 | [diff] [blame] | 448 | .SS helper |
| 449 | This module matches packets related to a specific conntrack-helper. |
| 450 | .TP |
| 451 | .BI "--helper " "string" |
| 452 | Matches packets related to the specified conntrack-helper. |
| 453 | .TP |
| 454 | string can be "ftp" for packets related to a ftp-session on default port. |
| 455 | For other ports append -portnr to the value, ie. "ftp-2121". |
| 456 | .br |
| 457 | Same rules apply for other conntrack-helpers. |
| 458 | .br |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 459 | .SS icmp |
| 460 | This extension is loaded if `--protocol icmp' is specified. It |
| 461 | provides the following option: |
| 462 | .TP |
| 463 | .BR "--icmp-type " "[!] \fItypename\fP" |
| 464 | This allows specification of the ICMP type, which can be a numeric |
| 465 | ICMP type, or one of the ICMP type names shown by the command |
| 466 | .br |
| 467 | iptables -p icmp -h |
| 468 | .br |
| 469 | .SS length |
| 470 | This module matches the length of a packet against a specific value |
| 471 | or range of values. |
| 472 | .TP |
| 473 | .BR "--length " "\fIlength\fP[:\fIlength\fP]" |
| 474 | .SS limit |
| 475 | This module matches at a limited rate using a token bucket filter. |
| 476 | A rule using this extension will match until this limit is reached |
| 477 | (unless the `!' flag is used). It can be used in combination with the |
| 478 | .B LOG |
| 479 | target to give limited logging, for example. |
| 480 | .TP |
| 481 | .BI "--limit " "rate" |
| 482 | Maximum average matching rate: specified as a number, with an optional |
| 483 | `/second', `/minute', `/hour', or `/day' suffix; the default is |
| 484 | 3/hour. |
| 485 | .TP |
| 486 | .BI "--limit-burst " "number" |
| 487 | Maximum initial number of packets to match: this number gets |
| 488 | recharged by one every time the limit specified above is not reached, |
| 489 | up to this number; the default is 5. |
| 490 | .SS mac |
| 491 | .TP |
| 492 | .BR "--mac-source " "[!] \fIaddress\fP" |
| 493 | Match source MAC address. It must be of the form XX:XX:XX:XX:XX:XX. |
| 494 | Note that this only makes sense for packets coming from an Ethernet device |
| 495 | and entering the |
| 496 | .BR PREROUTING , |
| 497 | .B FORWARD |
| 498 | or |
| 499 | .B INPUT |
| 500 | chains. |
| 501 | .SS mark |
| 502 | This module matches the netfilter mark field associated with a packet |
| 503 | (which can be set using the |
| 504 | .B MARK |
| 505 | target below). |
| 506 | .TP |
| 507 | .BR "--mark " "\fIvalue\fP[/\fImask\fP]" |
| 508 | Matches packets with the given unsigned mark value (if a mask is |
| 509 | specified, this is logically ANDed with the mask before the |
| 510 | comparison). |
| 511 | .SS multiport |
| 512 | This module matches a set of source or destination ports. Up to 15 |
| 513 | ports can be specified. It can only be used in conjunction with |
| 514 | .B "-p tcp" |
| 515 | or |
| 516 | .BR "-p udp" . |
| 517 | .TP |
| 518 | .BR "--source-ports " "\fIport\fP[,\fIport\fP[,\fIport\fP...]]" |
| 519 | Match if the source port is one of the given ports. The flag |
| 520 | .B --sports |
| 521 | is a convenient alias for this option. |
| 522 | .TP |
| 523 | .BR "--destination-ports " "\fIport\fP[,\fIport\fP[,\fIport\fP...]]" |
| 524 | Match if the destination port is one of the given ports. The flag |
| 525 | .B --dports |
| 526 | is a convenient alias for this option. |
| 527 | .TP |
| 528 | .BR "--ports " "\fIport\fP[,\fIport\fP[,\fIport\fP...]]" |
| 529 | Match if the both the source and destination ports are equal to each |
| 530 | other and to one of the given ports. |
| 531 | .SS owner |
| 532 | This module attempts to match various characteristics of the packet |
| 533 | creator, for locally-generated packets. It is only valid in the |
| 534 | .B OUTPUT |
| 535 | chain, and even this some packets (such as ICMP ping responses) may |
| 536 | have no owner, and hence never match. |
| 537 | .TP |
| 538 | .BI "--uid-owner " "userid" |
| 539 | Matches if the packet was created by a process with the given |
| 540 | effective user id. |
| 541 | .TP |
| 542 | .BI "--gid-owner " "groupid" |
| 543 | Matches if the packet was created by a process with the given |
| 544 | effective group id. |
| 545 | .TP |
| 546 | .BI "--pid-owner " "processid" |
| 547 | Matches if the packet was created by a process with the given |
| 548 | process id. |
| 549 | .TP |
| 550 | .BI "--sid-owner " "sessionid" |
| 551 | Matches if the packet was created by a process in the given session |
| 552 | group. |
| 553 | .TP |
| 554 | .BI "--cmd-owner " "name" |
| 555 | Matches if the packet was created by a process with the given command name. |
| 556 | (this option is present only if iptables was compiled under a kernel |
| 557 | supporting this feature) |
| 558 | .SS physdev |
| 559 | This module matches on the bridge port input and output devices enslaved |
| 560 | to a bridge device. This is only useful if the input device or output device |
| 561 | is a bridge device. This module is a part of the infrastructure that enables |
| 562 | a transparent bridging IP firewall and is only useful for kernel versions |
| 563 | above version 2.5.44. |
| 564 | .TP |
| 565 | .B --physdev-in name |
| 566 | Name of a bridge port via which a packet is received (only for |
| 567 | packets entering the |
| 568 | .BR INPUT , |
| 569 | .B FORWARD |
| 570 | and |
| 571 | .B PREROUTING |
| 572 | chains). If the interface name ends in a "+", then any |
| 573 | interface which begins with this name will match. |
| 574 | .TP |
| 575 | .B --physdev-out name |
| 576 | Name of a bridge port via which a packet is going to be sent (for packets |
| 577 | entering the |
| 578 | .BR FORWARD , |
| 579 | .B OUTPUT |
| 580 | and |
| 581 | .B POSTROUTING |
| 582 | chains). If the interface name ends in a "+", then any |
| 583 | interface which begins with this name will match. Note that in the |
| 584 | .BR nat " and " mangle |
| 585 | .B OUTPUT |
| 586 | chains one cannot match on the bridge output port, however one can in the |
| 587 | .B "filter OUTPUT" |
| 588 | chain. |
Harald Welte | bfc3369 | 2002-08-07 09:52:22 +0000 | [diff] [blame] | 589 | .SS pkttype |
| 590 | This module matches the link-layer packet type. |
| 591 | .TP |
| 592 | .BI "--pkt-type " "[\fIunicast\fP|\fIbroadcast\fP|\fImulticast\fP]" |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 593 | .SS state |
| 594 | This module, when combined with connection tracking, allows access to |
| 595 | the connection tracking state for this packet. |
| 596 | .TP |
| 597 | .BI "--state " "state" |
| 598 | Where state is a comma separated list of the connection states to |
| 599 | match. Possible states are |
| 600 | .B INVALID |
| 601 | meaning that the packet is associated with no known connection, |
| 602 | .B ESTABLISHED |
| 603 | meaning that the packet is associated with a connection which has seen |
| 604 | packets in both directions, |
| 605 | .B NEW |
| 606 | meaning that the packet has started a new connection, or otherwise |
| 607 | associated with a connection which has not seen packets in both |
| 608 | directions, and |
| 609 | .B RELATED |
| 610 | meaning that the packet is starting a new connection, but is |
| 611 | associated with an existing connection, such as an FTP data transfer, |
| 612 | or an ICMP error. |
| 613 | .SS tcp |
| 614 | These extensions are loaded if `--protocol tcp' is specified. It |
| 615 | provides the following options: |
| 616 | .TP |
| 617 | .BR "--source-port " "[!] \fIport\fP[:\fIport\fP]" |
| 618 | Source port or port range specification. This can either be a service |
| 619 | name or a port number. An inclusive range can also be specified, |
| 620 | using the format |
| 621 | .IR port : port . |
| 622 | If the first port is omitted, "0" is assumed; if the last is omitted, |
| 623 | "65535" is assumed. |
| 624 | If the second port greater then the first they will be swapped. |
| 625 | The flag |
| 626 | .B --sport |
| 627 | is a convenient alias for this option. |
| 628 | .TP |
| 629 | .BR "--destination-port " "[!] \fIport\fP[:\fIport\fP]" |
| 630 | Destination port or port range specification. The flag |
| 631 | .B --dport |
| 632 | is a convenient alias for this option. |
| 633 | .TP |
| 634 | .BR "--tcp-flags " "[!] \fImask\fP \fIcomp\fP" |
| 635 | Match when the TCP flags are as specified. The first argument is the |
| 636 | flags which we should examine, written as a comma-separated list, and |
| 637 | the second argument is a comma-separated list of flags which must be |
| 638 | set. Flags are: |
| 639 | .BR "SYN ACK FIN RST URG PSH ALL NONE" . |
| 640 | Hence the command |
| 641 | .br |
| 642 | iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST SYN |
| 643 | .br |
| 644 | will only match packets with the SYN flag set, and the ACK, FIN and |
| 645 | RST flags unset. |
| 646 | .TP |
| 647 | .B "[!] --syn" |
| 648 | Only match TCP packets with the SYN bit set and the ACK and RST bits |
| 649 | cleared. Such packets are used to request TCP connection initiation; |
| 650 | for example, blocking such packets coming in an interface will prevent |
| 651 | incoming TCP connections, but outgoing TCP connections will be |
| 652 | unaffected. |
| 653 | It is equivalent to \fB--tcp-flags SYN,RST,ACK SYN\fP. |
| 654 | If the "!" flag precedes the "--syn", the sense of the |
| 655 | option is inverted. |
| 656 | .TP |
| 657 | .BR "--tcp-option " "[!] \fInumber\fP" |
| 658 | Match if TCP option set. |
| 659 | .TP |
| 660 | .BR "--mss " "\fIvalue\fP[:\fIvalue\fP]" |
| 661 | Match TCP SYN or SYN/ACK packets with the specified MSS value (or range), |
| 662 | which control the maximum packet size for that connection. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 663 | .SS tos |
| 664 | This module matches the 8 bits of Type of Service field in the IP |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 665 | header (ie. including the precedence bits). |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 666 | .TP |
Bert Hubert | 20ecf7a | 2000-03-24 01:56:37 +0000 | [diff] [blame] | 667 | .BI "--tos " "tos" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 668 | The argument is either a standard name, (use |
| 669 | .br |
| 670 | iptables -m tos -h |
| 671 | .br |
| 672 | to see the list), or a numeric value to match. |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 673 | .SS ttl |
| 674 | This module matches the time to live field in the IP header. |
| 675 | .TP |
| 676 | .BI "--ttl " "ttl" |
| 677 | Matches the given TTL value. |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 678 | .SS udp |
| 679 | These extensions are loaded if `--protocol udp' is specified. It |
| 680 | provides the following options: |
| 681 | .TP |
| 682 | .BR "--source-port " "[!] \fIport\fP[:\fIport\fP]" |
| 683 | Source port or port range specification. |
| 684 | See the description of the |
| 685 | .B --source-port |
| 686 | option of the TCP extension for details. |
| 687 | .TP |
| 688 | .BR "--destination-port " "[!] \fIport\fP[:\fIport\fP]" |
| 689 | Destination port or port range specification. |
| 690 | See the description of the |
| 691 | .B --destination-port |
| 692 | option of the TCP extension for details. |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 693 | .SS unclean |
| 694 | This module takes no options, but attempts to match packets which seem |
| 695 | malformed or unusual. This is regarded as experimental. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 696 | .SH TARGET EXTENSIONS |
| 697 | iptables can use extended target modules: the following are included |
| 698 | in the standard distribution. |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 699 | .SS DNAT |
| 700 | This target is only valid in the |
| 701 | .B nat |
| 702 | table, in the |
| 703 | .B PREROUTING |
| 704 | and |
| 705 | .B OUTPUT |
| 706 | chains, and user-defined chains which are only called from those |
| 707 | chains. It specifies that the destination address of the packet |
| 708 | should be modified (and all future packets in this connection will |
| 709 | also be mangled), and rules should cease being examined. It takes one |
| 710 | type of option: |
| 711 | .TP |
| 712 | .BR "--to-destination " "\fIipaddr\fP[-\fIipaddr\fP][:\fIport\fP-\fIport\fP]" |
| 713 | which can specify a single new destination IP address, an inclusive |
| 714 | range of IP addresses, and optionally, a port range (which is only |
| 715 | valid if the rule also specifies |
| 716 | .B "-p tcp" |
| 717 | or |
| 718 | .BR "-p udp" ). |
| 719 | If no port range is specified, then the destination port will never be |
| 720 | modified. |
| 721 | .TP |
| 722 | You can add several --to-destination options. If you specify more |
| 723 | than one destination address, either via an address range or multiple |
| 724 | --to-destination options, a simple round-robin (one after another in |
| 725 | cycle) load balancing takes place between these adresses. |
| 726 | .SS DSCP |
| 727 | This target allows to alter the value of the DSCP bits within the TOS |
| 728 | header of the IPv4 packet. As this manipulates a packet, it can only |
| 729 | be used in the mangle table. |
| 730 | .TP |
| 731 | .BI "--set-dscp " "value" |
| 732 | Set the DSCP field to a numerical value (can be decimal or hex) |
| 733 | .TP |
| 734 | .BI "--set-dscp-class " "class" |
| 735 | Set the DSCP field to a DiffServ class. |
| 736 | .SS ECN |
| 737 | This target allows to selectively work around known ECN blackholes. |
| 738 | It can only be used in the mangle table. |
| 739 | .TP |
| 740 | .BI "--ecn-tcp-remove" |
| 741 | Remove all ECN bits from the TCP header. Of course, it can only be used |
| 742 | in conjunction with |
| 743 | .BR "-p tcp" . |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 744 | .SS LOG |
| 745 | Turn on kernel logging of matching packets. When this option is set |
| 746 | for a rule, the Linux kernel will print some information on all |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 747 | matching packets (like most IP header fields) via the kernel log |
| 748 | (where it can be read with |
| 749 | .I dmesg |
| 750 | or |
| 751 | .IR syslogd (8)). |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 752 | This is a "non-terminating target", i.e. rule traversal continues at |
| 753 | the next rule. So if you want to LOG the packets you refuse, use two |
Hervé Eychenne | e644cb0 | 2002-06-22 18:23:48 +0000 | [diff] [blame] | 754 | separate rules with the same matching criteria, first using target LOG |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 755 | then DROP (or REJECT). |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 756 | .TP |
| 757 | .BI "--log-level " "level" |
| 758 | Level of logging (numeric or see \fIsyslog.conf\fP(5)). |
| 759 | .TP |
| 760 | .BI "--log-prefix " "prefix" |
Rusty Russell | f81427e | 2000-09-13 04:20:38 +0000 | [diff] [blame] | 761 | Prefix log messages with the specified prefix; up to 29 letters long, |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 762 | and useful for distinguishing messages in the logs. |
| 763 | .TP |
| 764 | .B --log-tcp-sequence |
| 765 | Log TCP sequence numbers. This is a security risk if the log is |
| 766 | readable by users. |
| 767 | .TP |
| 768 | .B --log-tcp-options |
| 769 | Log options from the TCP packet header. |
| 770 | .TP |
| 771 | .B --log-ip-options |
| 772 | Log options from the IP packet header. |
| 773 | .SS MARK |
| 774 | This is used to set the netfilter mark value associated with the |
| 775 | packet. It is only valid in the |
| 776 | .B mangle |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 777 | table. It can for example be used in conjunction with iproute2. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 778 | .TP |
Bert Hubert | 20ecf7a | 2000-03-24 01:56:37 +0000 | [diff] [blame] | 779 | .BI "--set-mark " "mark" |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 780 | .SS MASQUERADE |
| 781 | This target is only valid in the |
| 782 | .B nat |
| 783 | table, in the |
| 784 | .B POSTROUTING |
| 785 | chain. It should only be used with dynamically assigned IP (dialup) |
| 786 | connections: if you have a static IP address, you should use the SNAT |
| 787 | target. Masquerading is equivalent to specifying a mapping to the IP |
| 788 | address of the interface the packet is going out, but also has the |
| 789 | effect that connections are |
| 790 | .I forgotten |
| 791 | when the interface goes down. This is the correct behavior when the |
| 792 | next dialup is unlikely to have the same interface address (and hence |
| 793 | any established connections are lost anyway). It takes one option: |
| 794 | .TP |
| 795 | .BR "--to-ports " "\fIport\fP[-\fIport\fP]" |
| 796 | This specifies a range of source ports to use, overriding the default |
| 797 | .B SNAT |
| 798 | source port-selection heuristics (see above). This is only valid |
| 799 | if the rule also specifies |
| 800 | .B "-p tcp" |
| 801 | or |
| 802 | .BR "-p udp" . |
| 803 | .SS MIRROR |
| 804 | This is an experimental demonstration target which inverts the source |
| 805 | and destination fields in the IP header and retransmits the packet. |
| 806 | It is only valid in the |
| 807 | .BR INPUT , |
| 808 | .B FORWARD |
| 809 | and |
| 810 | .B PREROUTING |
| 811 | chains, and user-defined chains which are only called from those |
| 812 | chains. Note that the outgoing packets are |
| 813 | .B NOT |
| 814 | seen by any packet filtering chains, connection tracking or NAT, to |
| 815 | avoid loops and other problems. |
| 816 | .SS REDIRECT |
| 817 | This target is only valid in the |
| 818 | .B nat |
| 819 | table, in the |
| 820 | .B PREROUTING |
| 821 | and |
| 822 | .B OUTPUT |
| 823 | chains, and user-defined chains which are only called from those |
| 824 | chains. It alters the destination IP address to send the packet to |
| 825 | the machine itself (locally-generated packets are mapped to the |
| 826 | 127.0.0.1 address). It takes one option: |
| 827 | .TP |
| 828 | .BR "--to-ports " "\fIport\fP[-\fIport\fP]" |
| 829 | This specifies a destination port or range of ports to use: without |
| 830 | this, the destination port is never altered. This is only valid |
| 831 | if the rule also specifies |
| 832 | .B "-p tcp" |
| 833 | or |
| 834 | .BR "-p udp" . |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 835 | .SS REJECT |
| 836 | This is used to send back an error packet in response to the matched |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 837 | packet: otherwise it is equivalent to |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 838 | .B DROP |
| 839 | so it is a terminating TARGET, ending rule traversal. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 840 | This target is only valid in the |
| 841 | .BR INPUT , |
| 842 | .B FORWARD |
| 843 | and |
| 844 | .B OUTPUT |
Rusty Russell | 9cadb43 | 2000-05-10 00:18:06 +0000 | [diff] [blame] | 845 | chains, and user-defined chains which are only called from those |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 846 | chains. The following option controls the nature of the error packet |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 847 | returned: |
| 848 | .TP |
Bert Hubert | 20ecf7a | 2000-03-24 01:56:37 +0000 | [diff] [blame] | 849 | .BI "--reject-with " "type" |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 850 | The type given can be |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 851 | .BR icmp-net-unreachable , |
| 852 | .BR icmp-host-unreachable , |
Rusty Russell | 14f390f | 2000-07-30 01:10:04 +0000 | [diff] [blame] | 853 | .BR icmp-port-unreachable , |
| 854 | .BR icmp-proto-unreachable , |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 855 | .BR "icmp-net-prohibited or" |
Rusty Russell | 14f390f | 2000-07-30 01:10:04 +0000 | [diff] [blame] | 856 | .BR icmp-host-prohibited , |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 857 | which return the appropriate ICMP error message (\fBport-unreachable\fP is |
| 858 | the default). The option |
Rusty Russell | 14f390f | 2000-07-30 01:10:04 +0000 | [diff] [blame] | 859 | .B tcp-reset |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 860 | can be used on rules which only match the TCP protocol: this causes a |
| 861 | TCP RST packet to be sent back. This is mainly useful for blocking |
| 862 | .I ident |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 863 | (113/tcp) probes which frequently occur when sending mail to broken mail |
| 864 | hosts (which won't accept your mail otherwise). |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 865 | .SS SNAT |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 866 | This target is only valid in the |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 867 | .B nat |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 868 | table, in the |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 869 | .B POSTROUTING |
| 870 | chain. It specifies that the source address of the packet should be |
| 871 | modified (and all future packets in this connection will also be |
Hervé Eychenne | e644cb0 | 2002-06-22 18:23:48 +0000 | [diff] [blame] | 872 | mangled), and rules should cease being examined. It takes one type |
| 873 | of option: |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 874 | .TP |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 875 | .BR "--to-source " "\fIipaddr\fP[-\fIipaddr\fP][:\fIport\fP-\fIport\fP]" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 876 | which can specify a single new source IP address, an inclusive range |
| 877 | of IP addresses, and optionally, a port range (which is only valid if |
| 878 | the rule also specifies |
| 879 | .B "-p tcp" |
| 880 | or |
| 881 | .BR "-p udp" ). |
| 882 | If no port range is specified, then source ports below 512 will be |
Harald Welte | 0112abb | 2001-02-19 21:48:13 +0000 | [diff] [blame] | 883 | mapped to other ports below 512: those between 512 and 1023 inclusive |
| 884 | will be mapped to ports below 1024, and other ports will be mapped to |
| 885 | 1024 or above. Where possible, no port alteration will occur. |
Hervé Eychenne | e644cb0 | 2002-06-22 18:23:48 +0000 | [diff] [blame] | 886 | .TP |
| 887 | You can add several --to-source options. If you specify more |
| 888 | than one source address, either via an address range or multiple |
| 889 | --to-source options, a simple round-robin (one after another in |
| 890 | cycle) takes place between these adresses. |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 891 | .SS TCPMSS |
| 892 | This target allows to alter the MSS value of TCP SYN packets, to control |
| 893 | the maximum size for that connection (usually limiting it to your |
Hervé Eychenne | cea2ca3 | 2002-05-27 11:16:09 +0000 | [diff] [blame] | 894 | outgoing interface's MTU minus 40). Of course, it can only be used |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 895 | in conjunction with |
| 896 | .BR "-p tcp" . |
| 897 | .br |
| 898 | This target is used to overcome criminally braindead ISPs or servers |
| 899 | which block ICMP Fragmentation Needed packets. The symptoms of this |
| 900 | problem are that everything works fine from your Linux |
| 901 | firewall/router, but machines behind it can never exchange large |
| 902 | packets: |
| 903 | .br |
| 904 | 1) Web browsers connect, then hang with no data received. |
| 905 | .br |
| 906 | 2) Small mail works fine, but large emails hang. |
| 907 | .br |
| 908 | 3) ssh works fine, but scp hangs after initial handshaking. |
| 909 | .br |
| 910 | Workaround: activate this option and add a rule to your firewall |
| 911 | configuration like: |
| 912 | .br |
| 913 | iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN \\ |
| 914 | .br |
| 915 | -j TCPMSS --clamp-mss-to-pmtu |
| 916 | .TP |
| 917 | .BI "--set-mss " "value" |
| 918 | Explicitly set MSS option to specified value. |
| 919 | .TP |
| 920 | .B "--clamp-mss-to-pmtu" |
| 921 | Automatically clamp MSS value to (path_MTU - 40). |
| 922 | .TP |
| 923 | These options are mutually exclusive. |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 924 | .SS TOS |
| 925 | This is used to set the 8-bit Type of Service field in the IP header. |
| 926 | It is only valid in the |
| 927 | .B mangle |
| 928 | table. |
Harald Welte | bfc3369 | 2002-08-07 09:52:22 +0000 | [diff] [blame] | 929 | .TP |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 930 | .BI "--set-tos " "tos" |
| 931 | You can use a numeric TOS values, or use |
| 932 | .br |
| 933 | iptables -j TOS -h |
| 934 | .br |
| 935 | to see the list of valid TOS names. |
| 936 | .SS ULOG |
| 937 | This target provides userspace logging of matching packets. When this |
| 938 | target is set for a rule, the Linux kernel will multicast this packet |
| 939 | through a |
| 940 | .IR netlink |
| 941 | socket. One or more userspace processes may then subscribe to various |
| 942 | multicast groups and receive the packets. |
| 943 | Like LOG, this is a "non-terminating target", i.e. rule traversal |
| 944 | continues at the next rule. |
Harald Welte | bfc3369 | 2002-08-07 09:52:22 +0000 | [diff] [blame] | 945 | .TP |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 946 | .BI "--ulog-nlgroup " "nlgroup" |
| 947 | This specifies the netlink group (1-32) to which the packet is sent. |
| 948 | Default value is 1. |
Harald Welte | bfc3369 | 2002-08-07 09:52:22 +0000 | [diff] [blame] | 949 | .TP |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 950 | .BI "--ulog-prefix " "prefix" |
| 951 | Prefix log messages with the specified prefix; up to 32 characters |
| 952 | long, and useful for distinguishing messages in the logs. |
| 953 | .TP |
| 954 | .BI "--ulog-cprange " "size" |
| 955 | Number of bytes to be copied to userspace. A value of 0 always copies |
| 956 | the entire packet, regardless of its size. Default is 0. |
| 957 | .TP |
| 958 | .BI "--ulog-qthreshold " "size" |
| 959 | Number of packet to queue inside kernel. Setting this value to, e.g. 10 |
| 960 | accumulates ten packets inside the kernel and transmits them as one |
| 961 | netlink multipart message to userspace. Default is 1 (for backwards |
| 962 | compatibility). |
Harald Welte | bfc3369 | 2002-08-07 09:52:22 +0000 | [diff] [blame] | 963 | .br |
Rusty Russell | 86573e5 | 2000-10-11 06:01:13 +0000 | [diff] [blame] | 964 | .SH DIAGNOSTICS |
| 965 | Various error messages are printed to standard error. The exit code |
| 966 | is 0 for correct functioning. Errors which appear to be caused by |
| 967 | invalid or abused command line parameters cause an exit code of 2, and |
| 968 | other errors cause an exit code of 1. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 969 | .SH BUGS |
Hervé Eychenne | cea2ca3 | 2002-05-27 11:16:09 +0000 | [diff] [blame] | 970 | Bugs? What's this? ;-) |
Hervé Eychenne | e644cb0 | 2002-06-22 18:23:48 +0000 | [diff] [blame] | 971 | Well... the counters are not reliable on sparc64. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 972 | .SH COMPATIBILITY WITH IPCHAINS |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 973 | This |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 974 | .B iptables |
| 975 | is very similar to ipchains by Rusty Russell. The main difference is |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 976 | that the chains |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 977 | .B INPUT |
| 978 | and |
| 979 | .B OUTPUT |
| 980 | are only traversed for packets coming into the local host and |
| 981 | originating from the local host respectively. Hence every packet only |
| 982 | passes through one of the three chains; previously a forwarded packet |
| 983 | would pass through all three. |
| 984 | .PP |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 985 | The other main difference is that |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 986 | .B -i |
| 987 | refers to the input interface; |
| 988 | .B -o |
| 989 | refers to the output interface, and both are available for packets |
| 990 | entering the |
| 991 | .B FORWARD |
| 992 | chain. |
| 993 | .PP The various forms of NAT have been separated out; |
| 994 | .B iptables |
| 995 | is a pure packet filter when using the default `filter' table, with |
| 996 | optional extension modules. This should simplify much of the previous |
| 997 | confusion over the combination of IP masquerading and packet filtering |
| 998 | seen previously. So the following options are handled differently: |
| 999 | .br |
| 1000 | -j MASQ |
| 1001 | .br |
| 1002 | -M -S |
| 1003 | .br |
| 1004 | -M -L |
| 1005 | .br |
| 1006 | There are several other changes in iptables. |
| 1007 | .SH SEE ALSO |
Hervé Eychenne | cea2ca3 | 2002-05-27 11:16:09 +0000 | [diff] [blame] | 1008 | .BR iptables-save (8), |
| 1009 | .BR iptables-restore (8), |
| 1010 | .BR ip6tables (8), |
| 1011 | .BR ip6tables-save (8), |
Harald Welte | 282d669 | 2003-02-14 07:34:09 +0000 | [diff] [blame] | 1012 | .BR ip6tables-restore (8). |
Hervé Eychenne | cea2ca3 | 2002-05-27 11:16:09 +0000 | [diff] [blame] | 1013 | .P |
| 1014 | The packet-filtering-HOWTO details iptables usage for |
| 1015 | packet filtering, the NAT-HOWTO details NAT, |
| 1016 | the netfilter-extensions-HOWTO details the extensions that are |
| 1017 | not in the standard distribution, |
| 1018 | and the netfilter-hacking-HOWTO details the netfilter internals. |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 1019 | .br |
| 1020 | See |
| 1021 | .BR "http://www.netfilter.org/" . |
Marc Boucher | f127a19 | 2000-03-20 08:32:15 +0000 | [diff] [blame] | 1022 | .SH AUTHORS |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1023 | Rusty Russell wrote iptables, in early consultation with Michael |
| 1024 | Neuling. |
| 1025 | .PP |
Marc Boucher | f127a19 | 2000-03-20 08:32:15 +0000 | [diff] [blame] | 1026 | Marc Boucher made Rusty abandon ipnatctl by lobbying for a generic packet |
| 1027 | selection framework in iptables, then wrote the mangle table, the owner match, |
| 1028 | the mark stuff, and ran around doing cool stuff everywhere. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1029 | .PP |
| 1030 | James Morris wrote the TOS target, and tos match. |
| 1031 | .PP |
| 1032 | Jozsef Kadlecsik wrote the REJECT target. |
| 1033 | .PP |
Harald Welte | bfc3369 | 2002-08-07 09:52:22 +0000 | [diff] [blame] | 1034 | Harald Welte wrote the ULOG target, TTL, DSCP, ECN matches and targets. |
Rusty Russell | 5245182 | 2000-08-27 07:47:46 +0000 | [diff] [blame] | 1035 | .PP |
James Morris | edfce4e | 2001-12-07 10:23:22 +0000 | [diff] [blame] | 1036 | The Netfilter Core Team is: Marc Boucher, Jozsef Kadlecsik, James Morris, |
| 1037 | Harald Welte and Rusty Russell. |
Hervé Eychenne | 9e51806 | 2002-03-14 09:25:40 +0000 | [diff] [blame] | 1038 | .PP |
| 1039 | Man page written by Herve Eychenne <rv@wallfire.org>. |
Hervé Eychenne | cea2ca3 | 2002-05-27 11:16:09 +0000 | [diff] [blame] | 1040 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 1041 | .\" .. and did I mention that we are incredibly cool people? |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 1042 | .\" .. sexy, too .. |
Rusty Russell | 86573e5 | 2000-10-11 06:01:13 +0000 | [diff] [blame] | 1043 | .\" .. witty, charming, powerful .. |
James Morris | 060ae4c | 2000-10-29 01:29:57 +0000 | [diff] [blame] | 1044 | .\" .. and most of all, modest .. |