Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 1 | .TH IPTABLES 8 "Aug 11, 2000" "" "" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 2 | .\" |
| 3 | .\" Man page written by Herve Eychenne <eychenne@info.enserb.u-bordeaux.fr> |
| 4 | .\" It is based on ipchains man page. |
| 5 | .\" |
| 6 | .\" ipchains page by Paul ``Rusty'' Russell March 1997 |
| 7 | .\" Based on the original ipfwadm man page by Jos Vos <jos@xos.nl> (see README) |
| 8 | .\" |
| 9 | .\" This program is free software; you can redistribute it and/or modify |
| 10 | .\" it under the terms of the GNU General Public License as published by |
| 11 | .\" the Free Software Foundation; either version 2 of the License, or |
| 12 | .\" (at your option) any later version. |
| 13 | .\" |
| 14 | .\" This program is distributed in the hope that it will be useful, |
| 15 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | .\" GNU General Public License for more details. |
| 18 | .\" |
| 19 | .\" You should have received a copy of the GNU General Public License |
| 20 | .\" along with this program; if not, write to the Free Software |
| 21 | .\" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 | .\" |
| 23 | .\" |
| 24 | .SH NAME |
| 25 | iptables \- IP packet filter administration |
| 26 | .SH SYNOPSIS |
| 27 | .BR "iptables -[ADC] " "chain rule-specification [options]" |
| 28 | .br |
| 29 | .BR "iptables -[RI] " "chain rulenum rule-specification [options]" |
| 30 | .br |
| 31 | .BR "iptables -D " "chain rulenum [options]" |
| 32 | .br |
| 33 | .BR "iptables -[LFZ] " "[chain] [options]" |
| 34 | .br |
| 35 | .BR "iptables -[NX] " "chain" |
| 36 | .br |
| 37 | .BR "iptables -P " "chain target [options]" |
| 38 | .br |
| 39 | .BR "iptables -E " "old-chain-name new-chain-name" |
| 40 | .SH DESCRIPTION |
| 41 | .B Iptables |
| 42 | is used to set up, maintain, and inspect the tables of IP packet |
| 43 | filter rules in the Linux kernel. There are several different tables |
| 44 | which may be defined, and each table contains a number of built-in |
| 45 | chains, and may contain user-defined chains. |
| 46 | |
| 47 | Each chain is a list of rules which can match a set of packets: each |
| 48 | rule specifies what to do with a packet which matches. This is called |
| 49 | a `target', which may be a jump to a user-defined chain in the same |
| 50 | table. |
| 51 | |
| 52 | .SH TARGETS |
| 53 | A firewall rule specifies criteria for a packet, and a target. If the |
| 54 | packet does not match, the next rule in the chain is the examined; if |
| 55 | it does match, then the next rule is specified by the value of the |
| 56 | target, which can be the name of a user-defined chain, or one of the |
| 57 | special values |
| 58 | .IR ACCEPT , |
| 59 | .IR DROP , |
| 60 | .IR QUEUE , |
| 61 | or |
| 62 | .IR RETURN . |
| 63 | .PP |
| 64 | .I ACCEPT |
| 65 | means to let the packet through. |
| 66 | .I DROP |
| 67 | means to drop the packet on the floor. |
| 68 | .I QUEUE |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 69 | means to pass the packet to userspace (if supported by the kernel). |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 70 | .I RETURN |
| 71 | means stop traversing this chain, and resume at the next rule in the |
| 72 | previous (calling) chain. If the end of a built-in chain is reached, |
| 73 | or a rule in a built-in chain with target |
| 74 | .I RETURN |
| 75 | is matched, the target specified by the chain policy determines the |
| 76 | fate of the packet. |
| 77 | .SH TABLES |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 78 | There are current three independent tables (which tables are present |
| 79 | at any time depends on the kernel configuration options and which |
| 80 | modules are present). |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 81 | .TP |
| 82 | .B "-t, --table" |
| 83 | This option specifies the packet matching table which the command |
| 84 | should operate on. If the kernel is configured with automatic module |
| 85 | loading, an attempt will be made to load the appropriate module for |
| 86 | that table if it is not already there. |
| 87 | |
| 88 | The tables are as follows: |
| 89 | .BR "filter" |
| 90 | This is the default table, and contains the built-in chains INPUT (for |
| 91 | packets coming into the box itself), FORWARD (for packets being routed |
| 92 | through the box), and OUTPUT (for locally-generated packets). |
| 93 | .BR "nat" |
| 94 | This table is consulted when a packet which is creates a new |
| 95 | connection is encountered. It consists of three built-ins: PREROUTING |
| 96 | (for altering packets as soon as they come in), OUTPUT (for altering |
| 97 | locally-generated packets before routing), and POSTROUTING (for |
| 98 | altering packets as they are about to go out). |
| 99 | .BR "mangle" |
| 100 | This table is used for specialized packet alteration. It has two |
| 101 | built-in chains: PREROUTING (for altering incoming packets before |
| 102 | routing) and OUTPUT (for altering locally-generated packets before |
| 103 | routing). |
| 104 | .SH OPTIONS |
| 105 | The options that are recognized by |
| 106 | .B iptables |
| 107 | can be divided into several different groups. |
| 108 | .SS COMMANDS |
| 109 | These options specify the specific action to perform; only one of them |
| 110 | can be specified on the command line, unless otherwise specified |
| 111 | below. For all the long versions of the command and option names, you |
| 112 | only need to use enough letters to ensure that |
| 113 | .B iptables |
| 114 | can differentiate it from all other options. |
| 115 | .TP |
| 116 | .BR "-A, --append" |
| 117 | Append one or more rules to the end of the selected chain. |
| 118 | When the source and/or destination names resolve to more than one |
| 119 | address, a rule will be added for each possible address combination. |
| 120 | .TP |
| 121 | .BR "-D, --delete" |
| 122 | Delete one or more rules from the selected chain. There are two |
| 123 | versions of this command: the rule can be specified as a number in the |
| 124 | chain (starting at 1 for the first rule) or a rule to match. |
| 125 | .TP |
| 126 | .B "-R, --replace" |
| 127 | Replace a rule in the selected chain. If the source and/or |
| 128 | destination names resolve to multiple addresses, the command will |
| 129 | fail. Rules are numbered starting at 1. |
| 130 | .TP |
| 131 | .B "-I, --insert" |
| 132 | Insert one or more rules in the selected chain as the given rule |
| 133 | number. So, if the rule number is 1, the rule or rules are inserted |
| 134 | at the head of the chain. This is also the default if no rule number |
| 135 | is specified. |
| 136 | .TP |
| 137 | .B "-L, --list" |
| 138 | List all rules in the selected chain. If no chain is selected, all |
| 139 | chains are listed. It is legal to specify the |
| 140 | .B -Z |
| 141 | (zero) option as well, in which case the chain(s) will be atomically |
| 142 | listed and zeroed. The exact output is effected by the other |
| 143 | arguments given. |
| 144 | .TP |
| 145 | .B "-F, --flush" |
| 146 | Flush the selected chain. This is equivalent to deleting all the |
| 147 | rules one by one. |
| 148 | .TP |
| 149 | .B "-Z, --zero" |
| 150 | Zero the packet and byte counters in all chains. It is legal to |
| 151 | specify the |
| 152 | .B "-L, --list" |
| 153 | (list) option as well, to see the counters immediately before they are |
| 154 | cleared; see above. |
| 155 | .TP |
| 156 | .B "-N, --new-chain" |
| 157 | Create a new user-defined chain of the given name. There must be no |
| 158 | target of that name already. |
| 159 | .TP |
| 160 | .B "-X, --delete-chain" |
| 161 | Delete the specified user-defined chain. There must be no references |
| 162 | to the chain (if there are you must delete or replace the referring |
| 163 | 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] | 164 | will attempt to delete every non-builtin chain in the table. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 165 | .TP |
| 166 | .B "-P, --policy" |
| 167 | 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] | 168 | .B TARGETS |
Rusty Russell | 86573e5 | 2000-10-11 06:01:13 +0000 | [diff] [blame] | 169 | for the legal targets. Only non-user-defined chains can have policies, |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 170 | and neither built-in nor user-defined chains can be policy targets. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 171 | .TP |
| 172 | .B "-E, --rename-chain" |
| 173 | Rename the user specified chain to the user supplied name; this is |
| 174 | cosmetic, and has no effect on the structure of the table. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 175 | .TP |
| 176 | .B -h |
| 177 | Help. |
| 178 | Give a (currently very brief) description of the command syntax. |
| 179 | .SS PARAMETERS |
| 180 | The following parameters make up a rule specification (as used in the |
| 181 | add, delete, replace, append and check commands). |
| 182 | .TP |
Rusty Russell | 2e0a321 | 2000-04-19 11:23:18 +0000 | [diff] [blame] | 183 | .BR "-p, --protocol " "[!] \fIprotocol\fP" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 184 | The protocol of the rule or of the packet to check. |
| 185 | The specified protocol can be one of |
| 186 | .IR tcp , |
| 187 | .IR udp , |
| 188 | .IR icmp , |
| 189 | or |
| 190 | .IR all , |
| 191 | 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] | 192 | different one. A protocol name from /etc/protocols is also allowed. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 193 | A "!" argument before the protocol inverts the |
| 194 | test. The number zero is equivalent to |
| 195 | .IR all . |
| 196 | Protocol |
| 197 | .I all |
| 198 | will match with all protocols and is taken as default when this |
| 199 | option is omitted. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 200 | .TP |
| 201 | .BR "-s, --source " "[!] \fIaddress\fP[/\fImask\fP]" |
| 202 | Source specification. |
| 203 | .I Address |
| 204 | can be either a hostname, a network name, or a plain IP address. |
| 205 | The |
| 206 | .I mask |
| 207 | can be either a network mask or a plain number, |
| 208 | specifying the number of 1's at the left side of the network mask. |
| 209 | Thus, a mask of |
| 210 | .I 24 |
| 211 | is equivalent to |
| 212 | .IR 255.255.255.0 . |
| 213 | A "!" argument before the address specification inverts the sense of |
| 214 | the address. The flag |
| 215 | .B --src |
| 216 | is a convenient alias for this option. |
| 217 | .TP |
| 218 | .BR "-d, --destination " "[!] \fIaddress\fP[/\fImask\fP]" |
| 219 | Destination specification. |
| 220 | See the description of the |
| 221 | .B -s |
| 222 | (source) flag for a detailed description of the syntax. The flag |
| 223 | .B --dst |
| 224 | is an alias for this option. |
| 225 | .TP |
| 226 | .BI "-j, --jump " "target" |
| 227 | This specifies the target of the rule; ie. what to do if the packet |
| 228 | matches it. The target can be a user-defined chain (not the one this |
| 229 | rule is in), one of the special builtin targets which decide the fate |
| 230 | of the packet immediately, or an extension (see |
| 231 | .B EXTENSIONS |
| 232 | below). If this |
| 233 | option is omitted in a rule, then matching the rule will have no |
| 234 | effect on the packet's fate, but the counters on the rule will be |
| 235 | incremented. |
| 236 | .TP |
| 237 | .BR "-i, --in-interface " "[!] [\fIname\fP]" |
| 238 | Optional name of an interface via which a packet is received (for |
| 239 | packets entering the |
| 240 | .BR INPUT , |
| 241 | .B FORWARD |
| 242 | and |
| 243 | .B PREROUTING |
| 244 | chains). When the "!" argument is used before the interface name, the |
| 245 | sense is inverted. If the interface name ends in a "+", then any |
| 246 | interface which begins with this name will match. If this option is |
| 247 | omitted, the string "+" is assumed, which will match with any |
| 248 | interface name. |
| 249 | .TP |
| 250 | .BR "-o, --out-interface " "[!] [\fIname\fP]" |
| 251 | Optional name of an interface via which a packet is going to |
| 252 | be sent (for packets entering the |
| 253 | .BR FORWARD , |
| 254 | .B OUTPUT |
| 255 | and |
| 256 | .B POSTROUTING |
| 257 | chains). When the "!" argument is used before the interface name, |
| 258 | the sense is inverted. If the interface name ends in a "+", then any |
| 259 | interface which begins with this name will match. If this option is |
| 260 | omitted, the string "+" is assumed, which will match with any |
| 261 | interface name. |
| 262 | .TP |
| 263 | .B "[!] " "-f, --fragment" |
| 264 | This means that the rule only refers to second and further fragments |
| 265 | of fragmented packets. Since there is no way to tell the source or |
| 266 | destination ports of such a packet (or ICMP type), such a packet will |
| 267 | not match any rules which specify them. When the "!" argument |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 268 | precedes the "-f" flag, the rule will only match head fragments, or |
| 269 | unfragmented packets. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 270 | .SS "OTHER OPTIONS" |
| 271 | The following additional options can be specified: |
| 272 | .TP |
| 273 | .B "-v, --verbose" |
| 274 | Verbose output. This option makes the list command show the interface |
| 275 | address, the rule options (if any), and the TOS masks. The packet and |
| 276 | byte counters are also listed, with the suffix 'K', 'M' or 'G' for |
| 277 | 1000, 1,000,000 and 1,000,000,000 multipliers respectively (but see |
| 278 | the |
| 279 | .B -x |
| 280 | flag to change this). |
| 281 | For appending, insertion, deletion and replacement, this causes |
| 282 | detailed information on the rule or rules to be printed. |
| 283 | .TP |
| 284 | .B "-n, --numeric" |
| 285 | Numeric output. |
| 286 | IP addresses and port numbers will be printed in numeric format. |
| 287 | By default, the program will try to display them as host names, |
| 288 | network names, or services (whenever applicable). |
| 289 | .TP |
| 290 | .B "-x, --exact" |
| 291 | Expand numbers. |
| 292 | Display the exact value of the packet and byte counters, |
| 293 | instead of only the rounded number in K's (multiples of 1000) |
| 294 | 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] | 295 | only relevant for the |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 296 | .B -L |
| 297 | command. |
| 298 | .TP |
| 299 | .B "--line-numbers" |
| 300 | When listing rules, add line numbers to the beginning of each rule, |
| 301 | corresponding to that rule's position in the chain. |
| 302 | .SH MATCH EXTENSIONS |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 303 | iptables can use extended packet matching modules. These are loaded |
| 304 | in two ways: implicitly, when |
| 305 | .B -p |
| 306 | or |
| 307 | .B --protocol |
| 308 | is specified, or with the |
| 309 | .B -m |
| 310 | or |
| 311 | .B --match |
| 312 | options, followed by the matching module name; after these, various |
| 313 | extra command line options become available, depending on the specific |
| 314 | module. You can specify multiple extended match modules in one line, and you can use the |
| 315 | .B -h |
| 316 | or |
| 317 | .B --help |
| 318 | options after the module has been specified to receive help specific |
| 319 | to that module. |
| 320 | |
| 321 | The following are included in the base package, and most of these can |
| 322 | be preceded by a |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 323 | .B ! |
| 324 | to invert the sense of the match. |
| 325 | .SS tcp |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 326 | These extensions are loaded if `--protocol tcp' is specified. It |
| 327 | provides the following options: |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 328 | .TP |
James Morris | 59e90fd | 2000-06-23 16:44:47 +0000 | [diff] [blame] | 329 | .BR "--source-port " "[!] [\fIport[:port]\fP]" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 330 | Source port or port range specification. This can either be a service |
| 331 | name or a port number. An inclusive range can also be specified, |
| 332 | using the format |
James Morris | 59e90fd | 2000-06-23 16:44:47 +0000 | [diff] [blame] | 333 | .IR port : port . |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 334 | If the first port is omitted, "0" is assumed; if the last is omitted, |
| 335 | "65535" is assumed. |
| 336 | If the second port greater then the first they will be swapped. |
| 337 | The flag |
| 338 | .B --sport |
| 339 | is an alias for this option. |
| 340 | .TP |
James Morris | 59e90fd | 2000-06-23 16:44:47 +0000 | [diff] [blame] | 341 | .BR "--destination-port " "[!] [\fIport[:port]\fP]" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 342 | Destination port or port range specification. The flag |
| 343 | .B --dport |
| 344 | is an alias for this option. |
| 345 | .TP |
| 346 | .BR "--tcp-flags " "[!] \fImask\fP \fIcomp\fP" |
| 347 | Match when the TCP flags are as specified. The first argument is the |
| 348 | flags which we should examine, written as a comma-separated list, and |
| 349 | the second argument is a comma-separated list of flags which must be |
| 350 | set. Flags are: |
| 351 | .BR "SYN ACK FIN RST URG PSH ALL NONE" . |
| 352 | Hence the command |
| 353 | .br |
Marc Boucher | f127a19 | 2000-03-20 08:32:15 +0000 | [diff] [blame] | 354 | iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST SYN |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 355 | .br |
| 356 | will only match packets with the SYN flag set, and the ACK, FIN and |
| 357 | RST flags unset. |
| 358 | .TP |
| 359 | .B "[!] --syn" |
| 360 | Only match TCP packets with the SYN bit set and the ACK and FIN bits |
| 361 | cleared. Such packets are used to request TCP connection initiation; |
| 362 | for example, blocking such packets coming in an interface will prevent |
| 363 | incoming TCP connections, but outgoing TCP connections will be |
| 364 | unaffected. |
| 365 | It is equivalent to \fB--tcp-flags SYN,RST,ACK SYN\fP. |
| 366 | If the "!" flag precedes the "--syn", the sense of the |
| 367 | option is inverted. |
| 368 | .TP |
| 369 | .BR "--tcp-option " "[!] \fInumber\fP" |
| 370 | Match if TCP option set. |
| 371 | .SS udp |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 372 | These extensions are loaded if `--protocol udp' is specified. It |
| 373 | provides the following options: |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 374 | .TP |
James Morris | 59e90fd | 2000-06-23 16:44:47 +0000 | [diff] [blame] | 375 | .BR "--source-port " "[!] [\fIport[:port]\fP]" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 376 | Source port or port range specification. |
| 377 | See the description of the |
| 378 | .B --source-port |
| 379 | option of the TCP extension for details. |
| 380 | .TP |
James Morris | 59e90fd | 2000-06-23 16:44:47 +0000 | [diff] [blame] | 381 | .BR "--destination-port " "[!] [\fIport[:port]\fP]" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 382 | Destination port or port range specification. |
| 383 | See the description of the |
| 384 | .B --destination-port |
| 385 | option of the TCP extension for details. |
| 386 | .SS icmp |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 387 | This extension is loaded if `--protocol icmp' is specified. It |
| 388 | provides the following option: |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 389 | .TP |
| 390 | .BR "--icmp-type " "[!] \fItypename\fP" |
| 391 | This allows specification of the ICMP type, which can be a numeric |
| 392 | ICMP type, or one of the ICMP type names shown by the command |
| 393 | .br |
| 394 | iptables -p icmp -h |
| 395 | .br |
| 396 | .SS mac |
| 397 | .TP |
| 398 | .BR "--mac-source " "[!] \fIaddress\fP" |
| 399 | Match source MAC address. It must be of the form XX:XX:XX:XX:XX:XX. |
| 400 | Note that this only makes sense for packets entering the |
| 401 | .BR PREROUTING , |
Rusty Russell | 4b3c03d | 2000-07-03 10:11:55 +0000 | [diff] [blame] | 402 | .B FORWARD |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 403 | or |
| 404 | .B INPUT |
Rusty Russell | 4b3c03d | 2000-07-03 10:11:55 +0000 | [diff] [blame] | 405 | chains for packets coming from an ethernet device. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 406 | .SS limit |
| 407 | This module matches at a limited rate using a token bucket filter: it |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 408 | can be used in combination with the |
| 409 | .B LOG |
| 410 | target to give limited logging. A rule using this extension will |
| 411 | match until this limit is reached (unless the `!' flag is used). |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 412 | .TP |
| 413 | .BI "--limit " "rate" |
| 414 | Maximum average matching rate: specified as a number, with an optional |
| 415 | `/second', `/minute', `/hour', or `/day' suffix; the default is |
| 416 | 3/hour. |
| 417 | .TP |
| 418 | .BI "--limit-burst " "number" |
| 419 | The maximum initial number of packets to match: this number gets |
| 420 | recharged by one every time the limit specified above is not reached, |
| 421 | up to this number; the default is 5. |
| 422 | .SS multiport |
| 423 | This module matches a set of source or destination ports. Up to 15 |
| 424 | ports can be specified. It can only be used in conjunction with |
| 425 | .B "-p tcp" |
| 426 | or |
| 427 | .BR "-p udp" . |
| 428 | .TP |
| 429 | .BR "--source-port" " [\fIport[,port]\fP]" |
| 430 | Match if the source port is one of the given ports. |
| 431 | .TP |
| 432 | .BR "--destination-port" " [\fIport[,port]\fP]" |
| 433 | Match if the destination port is one of the given ports. |
| 434 | .TP |
| 435 | .BR "--port" " [\fIport[,port]\fP]" |
| 436 | Match if the both the source and destination ports are equal to each |
| 437 | other and to one of the given ports. |
| 438 | .SS mark |
| 439 | This module matches the netfilter mark field associated with a packet |
| 440 | (which can be set using the |
| 441 | .B MARK |
| 442 | target below). |
| 443 | .TP |
| 444 | .BI "--mark " "value[/mask]" |
| 445 | Matches packets with the given unsigned mark value (if a mask is |
| 446 | specified, this is logically ANDed with the mark before the |
| 447 | comparison). |
| 448 | .SS owner |
| 449 | This module attempts to match various characteristics of the packet |
| 450 | creator, for locally-generated packets. It is only valid in the |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 451 | .B OUTPUT |
| 452 | chain, and even this some packets (such as ICMP ping responses) may |
| 453 | have no owner, and hence never match. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 454 | .TP |
Bert Hubert | 20ecf7a | 2000-03-24 01:56:37 +0000 | [diff] [blame] | 455 | .BI "--uid-owner " "userid" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 456 | Matches if the packet was created by a process with the given |
| 457 | effective user id. |
| 458 | .TP |
Bert Hubert | 20ecf7a | 2000-03-24 01:56:37 +0000 | [diff] [blame] | 459 | .BI "--gid-owner " "groupid" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 460 | Matches if the packet was created by a process with the given |
| 461 | effective group id. |
| 462 | .TP |
Bert Hubert | 20ecf7a | 2000-03-24 01:56:37 +0000 | [diff] [blame] | 463 | .BI "--pid-owner " "processid" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 464 | Matches if the packet was created by a process with the given |
| 465 | process id. |
| 466 | .TP |
Bert Hubert | 20ecf7a | 2000-03-24 01:56:37 +0000 | [diff] [blame] | 467 | .BI "--sid-owner " "sessionid" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 468 | Matches if the packet was created by a process in the given session |
| 469 | group. |
| 470 | .SS state |
| 471 | This module, when combined with connection tracking, allows access to |
| 472 | the connection tracking state for this packet. |
| 473 | .TP |
Bert Hubert | 20ecf7a | 2000-03-24 01:56:37 +0000 | [diff] [blame] | 474 | .BI "--state " "state" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 475 | Where state is a comma separated list of the connection states to |
| 476 | match. Possible states are |
| 477 | .B INVALID |
| 478 | meaning that the packet is associated with no known connection, |
| 479 | .B ESTABLISHED |
| 480 | meaning that the packet is associated with a connection which has seen |
| 481 | packets in both directions, |
| 482 | .B NEW |
| 483 | meaning that the packet has started a new connection, or otherwise |
| 484 | associated with a connection which has not seen packets in both |
| 485 | directions, and |
| 486 | .B RELATED |
| 487 | meaning that the packet is starting a new connection, but is |
| 488 | associated with an existing connection, such as an FTP data transfer, |
| 489 | or an ICMP error. |
| 490 | .SS unclean |
| 491 | This module takes no options, but attempts to match packets which seem |
| 492 | malformed or unusual. This is regarded as experimental. |
| 493 | .SS tos |
| 494 | This module matches the 8 bits of Type of Service field in the IP |
| 495 | header (ie. including the precedence bits). |
| 496 | .TP |
Bert Hubert | 20ecf7a | 2000-03-24 01:56:37 +0000 | [diff] [blame] | 497 | .BI "--tos " "tos" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 498 | The argument is either a standard name, (use |
| 499 | .br |
| 500 | iptables -m tos -h |
| 501 | .br |
| 502 | to see the list), or a numeric value to match. |
| 503 | .SH TARGET EXTENSIONS |
| 504 | iptables can use extended target modules: the following are included |
| 505 | in the standard distribution. |
| 506 | .SS LOG |
| 507 | Turn on kernel logging of matching packets. When this option is set |
| 508 | for a rule, the Linux kernel will print some information on all |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 509 | matching packets (like most IP header fields) via the kernel log |
| 510 | (where it can be read with |
| 511 | .I dmesg |
| 512 | or |
| 513 | .IR syslogd (8)). |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 514 | .TP |
| 515 | .BI "--log-level " "level" |
| 516 | Level of logging (numeric or see \fIsyslog.conf\fP(5)). |
| 517 | .TP |
| 518 | .BI "--log-prefix " "prefix" |
Rusty Russell | f81427e | 2000-09-13 04:20:38 +0000 | [diff] [blame] | 519 | Prefix log messages with the specified prefix; up to 29 letters long, |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 520 | and useful for distinguishing messages in the logs. |
| 521 | .TP |
| 522 | .B --log-tcp-sequence |
| 523 | Log TCP sequence numbers. This is a security risk if the log is |
| 524 | readable by users. |
| 525 | .TP |
| 526 | .B --log-tcp-options |
| 527 | Log options from the TCP packet header. |
| 528 | .TP |
| 529 | .B --log-ip-options |
| 530 | Log options from the IP packet header. |
| 531 | .SS MARK |
| 532 | This is used to set the netfilter mark value associated with the |
| 533 | packet. It is only valid in the |
| 534 | .B mangle |
| 535 | table. |
| 536 | .TP |
Bert Hubert | 20ecf7a | 2000-03-24 01:56:37 +0000 | [diff] [blame] | 537 | .BI "--set-mark " "mark" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 538 | .SS REJECT |
| 539 | This is used to send back an error packet in response to the matched |
| 540 | packet: otherwise it is equivalent to |
| 541 | .BR DROP . |
| 542 | This target is only valid in the |
| 543 | .BR INPUT , |
| 544 | .B FORWARD |
| 545 | and |
| 546 | .B OUTPUT |
Rusty Russell | 9cadb43 | 2000-05-10 00:18:06 +0000 | [diff] [blame] | 547 | chains, and user-defined chains which are only called from those |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 548 | chains. Several options control the nature of the error packet |
| 549 | returned: |
| 550 | .TP |
Bert Hubert | 20ecf7a | 2000-03-24 01:56:37 +0000 | [diff] [blame] | 551 | .BI "--reject-with " "type" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 552 | The type given can be |
| 553 | .BR icmp-net-unreachable , |
| 554 | .BR icmp-host-unreachable , |
Rusty Russell | 14f390f | 2000-07-30 01:10:04 +0000 | [diff] [blame] | 555 | .BR icmp-port-unreachable , |
| 556 | .BR icmp-proto-unreachable , |
| 557 | .BR icmp-net-prohibited or |
| 558 | .BR icmp-host-prohibited , |
Rusty Russell | ddd5b3b | 2000-05-31 06:32:47 +0000 | [diff] [blame] | 559 | which return the appropriate ICMP error message (port-unreachable is |
Rusty Russell | a1ce9f9 | 2000-03-24 08:39:16 +0000 | [diff] [blame] | 560 | the default). The option |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 561 | .B echo-reply |
Rusty Russell | a1ce9f9 | 2000-03-24 08:39:16 +0000 | [diff] [blame] | 562 | is also allowed; it can only be used for rules which specify an ICMP |
Rusty Russell | 14f390f | 2000-07-30 01:10:04 +0000 | [diff] [blame] | 563 | ping packet, and generates a ping reply. Finally, the option |
| 564 | .B tcp-reset |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 565 | can be used on rules which only match the TCP protocol: this causes a |
| 566 | TCP RST packet to be sent back. This is mainly useful for blocking |
| 567 | .I ident |
| 568 | probes which frequently occur when sending mail to broken mail hosts |
| 569 | (which won't accept your mail otherwise). |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 570 | .SS TOS |
| 571 | This is used to set the 8-bit Type of Service field in the IP header. |
| 572 | It is only valid in the |
| 573 | .B mangle |
| 574 | table. |
| 575 | .TP |
Bert Hubert | 20ecf7a | 2000-03-24 01:56:37 +0000 | [diff] [blame] | 576 | .BI "--set-tos " "tos" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 577 | You can use a numeric TOS values, or use |
| 578 | .br |
| 579 | iptables -j TOS -h |
| 580 | .br |
| 581 | to see the list of valid TOS names. |
| 582 | .SS MIRROR |
| 583 | This is an experimental demonstration target which inverts the source |
| 584 | and destination fields in the IP header and retransmits the packet. |
| 585 | It is only valid in the |
| 586 | .BR INPUT , |
| 587 | .B FORWARD |
| 588 | and |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 589 | .B PREROUTING |
| 590 | chains, and user-defined chains which are only called from those |
| 591 | chains. Note that the outgoing packets are |
| 592 | .B NOT |
| 593 | seen by any packet filtering chains, connection tracking or NAT, to |
| 594 | avoid loops and other problems. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 595 | .SS SNAT |
| 596 | This target is only valid in the |
| 597 | .B nat |
| 598 | table, in the |
| 599 | .B POSTROUTING |
| 600 | chain. It specifies that the source address of the packet should be |
| 601 | modified (and all future packets in this connection will also be |
| 602 | mangled), and rules should cease being examined. It takes one option: |
| 603 | .TP |
Bert Hubert | 20ecf7a | 2000-03-24 01:56:37 +0000 | [diff] [blame] | 604 | .BI "--to-source " "<ipaddr>[-<ipaddr>][:port-port]" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 605 | which can specify a single new source IP address, an inclusive range |
| 606 | of IP addresses, and optionally, a port range (which is only valid if |
| 607 | the rule also specifies |
| 608 | .B "-p tcp" |
| 609 | or |
| 610 | .BR "-p udp" ). |
| 611 | If no port range is specified, then source ports below 512 will be |
| 612 | mapped to other ports below 512: those between 1024 will be mapped to |
| 613 | ports below 1024, and other ports will be mapped to 1024 or above. |
| 614 | Where possible, no port alteration will occur. |
| 615 | .SS DNAT |
| 616 | This target is only valid in the |
| 617 | .B nat |
| 618 | table, in the |
| 619 | .B PREROUTING |
| 620 | and |
| 621 | .B OUTPUT |
Rusty Russell | 9cadb43 | 2000-05-10 00:18:06 +0000 | [diff] [blame] | 622 | chains, and user-defined chains which are only called from those |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 623 | chains. It specifies that the destination address of the packet |
| 624 | should be modified (and all future packets in this connection will |
| 625 | also be mangled), and rules should cease being examined. It takes one |
| 626 | option: |
| 627 | .TP |
Bert Hubert | 20ecf7a | 2000-03-24 01:56:37 +0000 | [diff] [blame] | 628 | .BI "--to-destination " "<ipaddr>[-<ipaddr>][:port-port]" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 629 | which can specify a single new destination IP address, an inclusive |
| 630 | range of IP addresses, and optionally, a port range (which is only |
| 631 | valid if the rule also specifies |
| 632 | .B "-p tcp" |
| 633 | or |
| 634 | .BR "-p udp" ). |
| 635 | If no port range is specified, then the destination port will never be |
| 636 | modified. |
| 637 | .SS MASQUERADE |
| 638 | This target is only valid in the |
| 639 | .B nat |
| 640 | table, in the |
| 641 | .B POSTROUTING |
| 642 | chain. It should only be used with dynamically assigned IP (dialup) |
| 643 | connections: if you have a static IP address, you should use the SNAT |
| 644 | target. Masquerading is equivalent to specifying a mapping to the IP |
| 645 | address of the interface the packet is going out, but also has the |
| 646 | effect that connections are |
| 647 | .I forgotten |
Marc Boucher | f127a19 | 2000-03-20 08:32:15 +0000 | [diff] [blame] | 648 | when the interface goes down. This is the correct behavior when the |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 649 | next dialup is unlikely to have the same interface address (and hence |
| 650 | any established connections are lost anyway). It takes one option: |
| 651 | .TP |
Bert Hubert | 20ecf7a | 2000-03-24 01:56:37 +0000 | [diff] [blame] | 652 | .BI "--to-ports " "<port>[-<port>]" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 653 | This specifies a range of source ports to use, overriding the default |
| 654 | .B SNAT |
| 655 | source port-selection heuristics (see above). This is only valid with |
| 656 | if the rule also specifies |
| 657 | .B "-p tcp" |
| 658 | or |
| 659 | .BR "-p udp" ). |
| 660 | .SS REDIRECT |
| 661 | This target is only valid in the |
| 662 | .B nat |
| 663 | table, in the |
| 664 | .B PREROUTING |
| 665 | and |
| 666 | .B OUTPUT |
Rusty Russell | 9cadb43 | 2000-05-10 00:18:06 +0000 | [diff] [blame] | 667 | chains, and user-defined chains which are only called from those |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 668 | chains. It alters the destination IP address to send the packet to |
| 669 | the machine itself (locally-generated packets are mapped to the |
Rusty Russell | 9cadb43 | 2000-05-10 00:18:06 +0000 | [diff] [blame] | 670 | 127.0.0.1 address). It takes one option: |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 671 | .TP |
Bert Hubert | 20ecf7a | 2000-03-24 01:56:37 +0000 | [diff] [blame] | 672 | .BI "--to-ports " "<port>[-<port>]" |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 673 | This specifies a destination port or range or ports to use: without |
| 674 | this, the destination port is never altered. This is only valid with |
| 675 | if the rule also specifies |
| 676 | .B "-p tcp" |
| 677 | or |
| 678 | .BR "-p udp" ). |
Rusty Russell | 86573e5 | 2000-10-11 06:01:13 +0000 | [diff] [blame] | 679 | .SH EXTRA EXTENSIONS |
| 680 | The following extensions are not included by default in the standard |
| 681 | distribution. |
| 682 | .SS ttl |
| 683 | This module matches the time to live field in the IP header. |
| 684 | .TP |
| 685 | .BI "--ttl " "ttl" |
| 686 | Matches the given TTL value. |
| 687 | .SS TTL |
| 688 | This target is used to modify the time to live field in the IP header. |
| 689 | It is only valid in the |
| 690 | .B mangle |
| 691 | table. |
| 692 | .TP |
| 693 | .BI "--ttl-set " "ttl" |
| 694 | Set the TTL to the given value. |
| 695 | .TP |
| 696 | .BI "--ttl-dec " "ttl" |
| 697 | Decrement the TTL by the given value. |
| 698 | .TP |
| 699 | .BI "--ttl-inc " "ttl" |
| 700 | Increment the TTL by the given value. |
Rusty Russell | 5245182 | 2000-08-27 07:47:46 +0000 | [diff] [blame] | 701 | .SS ULOG |
Rusty Russell | 86573e5 | 2000-10-11 06:01:13 +0000 | [diff] [blame] | 702 | This target provides userspace logging of matching packets. When this |
| 703 | target is set for a rule, the Linux kernel will multicast this packet |
| 704 | through a |
Rusty Russell | 5245182 | 2000-08-27 07:47:46 +0000 | [diff] [blame] | 705 | .IR netlink |
Rusty Russell | 86573e5 | 2000-10-11 06:01:13 +0000 | [diff] [blame] | 706 | socket. One or more userspace processes may then subscribe to various |
Rusty Russell | 5245182 | 2000-08-27 07:47:46 +0000 | [diff] [blame] | 707 | multicast groups and receive the packets. |
| 708 | .TP |
| 709 | .BI "--ulog-nlgroup" "<nlgroup>" |
| 710 | This specifies the netlink group (1-32) to which the packet is sent. |
| 711 | .TP |
| 712 | .BI "--ulog-prefix" "<prefix>" |
| 713 | Prefix log messages with the specified prefix; up to 32 characters |
| 714 | long, and useful fro distinguishing messages in the logs. |
| 715 | .TP |
| 716 | .BI "--ulog-cprange" "<size>" |
Rusty Russell | 86573e5 | 2000-10-11 06:01:13 +0000 | [diff] [blame] | 717 | Number of bytes to be copied to userspace. A value of 0 always copies |
Rusty Russell | 5245182 | 2000-08-27 07:47:46 +0000 | [diff] [blame] | 718 | the entire packet, regardless of its size. |
Rusty Russell | 86573e5 | 2000-10-11 06:01:13 +0000 | [diff] [blame] | 719 | .SH DIAGNOSTICS |
| 720 | Various error messages are printed to standard error. The exit code |
| 721 | is 0 for correct functioning. Errors which appear to be caused by |
| 722 | invalid or abused command line parameters cause an exit code of 2, and |
| 723 | other errors cause an exit code of 1. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 724 | .SH BUGS |
| 725 | Check is not implemented (yet). |
| 726 | .SH COMPATIBILITY WITH IPCHAINS |
| 727 | This |
| 728 | .B iptables |
| 729 | is very similar to ipchains by Rusty Russell. The main difference is |
| 730 | that the chains |
| 731 | .B INPUT |
| 732 | and |
| 733 | .B OUTPUT |
| 734 | are only traversed for packets coming into the local host and |
| 735 | originating from the local host respectively. Hence every packet only |
| 736 | passes through one of the three chains; previously a forwarded packet |
| 737 | would pass through all three. |
| 738 | .PP |
| 739 | The other main difference is that |
| 740 | .B -i |
| 741 | refers to the input interface; |
| 742 | .B -o |
| 743 | refers to the output interface, and both are available for packets |
| 744 | entering the |
| 745 | .B FORWARD |
| 746 | chain. |
| 747 | .PP The various forms of NAT have been separated out; |
| 748 | .B iptables |
| 749 | is a pure packet filter when using the default `filter' table, with |
| 750 | optional extension modules. This should simplify much of the previous |
| 751 | confusion over the combination of IP masquerading and packet filtering |
| 752 | seen previously. So the following options are handled differently: |
| 753 | .br |
| 754 | -j MASQ |
| 755 | .br |
| 756 | -M -S |
| 757 | .br |
| 758 | -M -L |
| 759 | .br |
| 760 | There are several other changes in iptables. |
| 761 | .SH SEE ALSO |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 762 | The iptables-HOWTO, which details more iptables usage, the NAT-HOWTO, |
| 763 | which details NAT, and the netfilter-hacking-HOWTO which details the |
| 764 | internals. |
Marc Boucher | f127a19 | 2000-03-20 08:32:15 +0000 | [diff] [blame] | 765 | .SH AUTHORS |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 766 | Rusty Russell wrote iptables, in early consultation with Michael |
| 767 | Neuling. |
| 768 | .PP |
Marc Boucher | f127a19 | 2000-03-20 08:32:15 +0000 | [diff] [blame] | 769 | Marc Boucher made Rusty abandon ipnatctl by lobbying for a generic packet |
| 770 | selection framework in iptables, then wrote the mangle table, the owner match, |
| 771 | the mark stuff, and ran around doing cool stuff everywhere. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 772 | .PP |
| 773 | James Morris wrote the TOS target, and tos match. |
| 774 | .PP |
| 775 | Jozsef Kadlecsik wrote the REJECT target. |
| 776 | .PP |
Rusty Russell | 86573e5 | 2000-10-11 06:01:13 +0000 | [diff] [blame] | 777 | Harald Welte wrote the ULOG target, TTL match+target and libipulog. |
Rusty Russell | 5245182 | 2000-08-27 07:47:46 +0000 | [diff] [blame] | 778 | .PP |
Rusty Russell | f61bb5f | 2000-10-13 07:11:24 +0000 | [diff] [blame] | 779 | The Netfilter Core Team is: Marc Boucher, James Morris, Harald Welte |
| 780 | and Rusty Russell. |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 781 | .\" .. and did I mention that we are incredibly cool people? |
Rusty Russell | 363112d | 2000-08-11 13:49:26 +0000 | [diff] [blame] | 782 | .\" .. sexy, too .. |
Rusty Russell | 86573e5 | 2000-10-11 06:01:13 +0000 | [diff] [blame] | 783 | .\" .. witty, charming, powerful .. |
James Morris | 060ae4c | 2000-10-29 01:29:57 +0000 | [diff] [blame] | 784 | .\" .. and most of all, modest .. |