| 1 |
.TH iptables-extensions 8 "" "iptables 1.8.13" "iptables 1.8.13" |
| 2 |
.SH NAME |
| 3 |
iptables-extensions \(em list of extensions in the standard iptables distribution |
| 4 |
.SH SYNOPSIS |
| 5 |
\fBip6tables\fP [\fB\-m\fP \fIname\fP [\fImodule-options\fP...]] |
| 6 |
[\fB\-j\fP \fItarget-name\fP [\fItarget-options\fP...] |
| 7 |
.PP |
| 8 |
\fBiptables\fP [\fB\-m\fP \fIname\fP [\fImodule-options\fP...]] |
| 9 |
[\fB\-j\fP \fItarget-name\fP [\fItarget-options\fP...] |
| 10 |
.SH MATCH EXTENSIONS |
| 11 |
iptables can use extended packet matching modules |
| 12 |
with the \fB\-m\fP or \fB\-\-match\fP |
| 13 |
options, followed by the matching module name; after these, various |
| 14 |
extra command line options become available, depending on the specific |
| 15 |
module. You can specify multiple extended match modules in one line, |
| 16 |
and you can use the \fB\-h\fP or \fB\-\-help\fP |
| 17 |
options after the module has been specified to receive help specific |
| 18 |
to that module. The extended match modules are evaluated in the order |
| 19 |
they are specified in the rule. |
| 20 |
.PP |
| 21 |
If the \fB\-p\fP or \fB\-\-protocol\fP was specified and if and only if an |
| 22 |
unknown option is encountered, iptables will try load a match module of the |
| 23 |
same name as the protocol, to try making the option available. |
| 24 |
.\" @MATCH@ |
| 25 |
.SS addrtype |
| 26 |
This module matches packets based on their |
| 27 |
.B address type. |
| 28 |
Address types are used within the kernel networking stack and categorize |
| 29 |
addresses into various groups. The exact definition of that group depends on the specific layer three protocol. |
| 30 |
.PP |
| 31 |
The following address types are possible: |
| 32 |
.TP |
| 33 |
.BI "UNSPEC" |
| 34 |
an unspecified address (i.e. 0.0.0.0) |
| 35 |
.TP |
| 36 |
.BI "UNICAST" |
| 37 |
an unicast address |
| 38 |
.TP |
| 39 |
.BI "LOCAL" |
| 40 |
a local address |
| 41 |
.TP |
| 42 |
.BI "BROADCAST" |
| 43 |
a broadcast address |
| 44 |
.TP |
| 45 |
.BI "ANYCAST" |
| 46 |
an anycast packet |
| 47 |
.TP |
| 48 |
.BI "MULTICAST" |
| 49 |
a multicast address |
| 50 |
.TP |
| 51 |
.BI "BLACKHOLE" |
| 52 |
a blackhole address |
| 53 |
.TP |
| 54 |
.BI "UNREACHABLE" |
| 55 |
an unreachable address |
| 56 |
.TP |
| 57 |
.BI "PROHIBIT" |
| 58 |
a prohibited address |
| 59 |
.TP |
| 60 |
.BI "THROW" |
| 61 |
FIXME |
| 62 |
.TP |
| 63 |
.BI "NAT" |
| 64 |
FIXME |
| 65 |
.TP |
| 66 |
.BI "XRESOLVE" |
| 67 |
.TP |
| 68 |
[\fB!\fP] \fB\-\-src\-type\fP \fItype\fP |
| 69 |
Matches if the source address is of given type |
| 70 |
.TP |
| 71 |
[\fB!\fP] \fB\-\-dst\-type\fP \fItype\fP |
| 72 |
Matches if the destination address is of given type |
| 73 |
.TP |
| 74 |
.BI "\-\-limit\-iface\-in" |
| 75 |
The address type checking can be limited to the interface the packet is coming |
| 76 |
in. This option is only valid in the |
| 77 |
.BR PREROUTING , |
| 78 |
.B INPUT |
| 79 |
and |
| 80 |
.B FORWARD |
| 81 |
chains. It cannot be specified with the |
| 82 |
\fB\-\-limit\-iface\-out\fP |
| 83 |
option. |
| 84 |
.TP |
| 85 |
\fB\-\-limit\-iface\-out\fP |
| 86 |
The address type checking can be limited to the interface the packet is going |
| 87 |
out. This option is only valid in the |
| 88 |
.BR POSTROUTING , |
| 89 |
.B OUTPUT |
| 90 |
and |
| 91 |
.B FORWARD |
| 92 |
chains. It cannot be specified with the |
| 93 |
\fB\-\-limit\-iface\-in\fP |
| 94 |
option. |
| 95 |
.SS ah (IPv6-specific) |
| 96 |
This module matches the parameters in Authentication header of IPsec packets. |
| 97 |
.TP |
| 98 |
[\fB!\fP] \fB\-\-ahspi\fP \fIspi\fP[\fB:\fP\fIspi\fP] |
| 99 |
Matches SPI. |
| 100 |
.TP |
| 101 |
[\fB!\fP] \fB\-\-ahlen\fP \fIlength\fP |
| 102 |
Total length of this header in octets. |
| 103 |
.TP |
| 104 |
\fB\-\-ahres\fP |
| 105 |
Matches if the reserved field is filled with zero. |
| 106 |
.SS ah (IPv4-specific) |
| 107 |
This module matches the SPIs in Authentication header of IPsec packets. |
| 108 |
.TP |
| 109 |
[\fB!\fP] \fB\-\-ahspi\fP \fIspi\fP[\fB:\fP\fIspi\fP] |
| 110 |
.SS bpf |
| 111 |
Match using Linux Socket Filter. Expects a path to an eBPF object or a cBPF |
| 112 |
program in decimal format. |
| 113 |
.TP |
| 114 |
\fB\-\-object\-pinned\fP \fIpath\fP |
| 115 |
Pass a path to a pinned eBPF object. |
| 116 |
.PP |
| 117 |
Applications load eBPF programs into the kernel with the bpf() system call and |
| 118 |
BPF_PROG_LOAD command and can pin them in a virtual filesystem with BPF_OBJ_PIN. |
| 119 |
To use a pinned object in iptables, mount the bpf filesystem using |
| 120 |
.IP |
| 121 |
mount \-t bpf bpf ${BPF_MOUNT} |
| 122 |
.PP |
| 123 |
then insert the filter in iptables by path: |
| 124 |
.IP |
| 125 |
iptables \-A OUTPUT \-m bpf \-\-object\-pinned ${BPF_MOUNT}/{PINNED_PATH} \-j ACCEPT |
| 126 |
.TP |
| 127 |
\fB\-\-bytecode\fP \fIcode\fP |
| 128 |
Pass the BPF byte code format as generated by the \fBnfbpf_compile\fP utility. |
| 129 |
.PP |
| 130 |
The code format is similar to the output of the tcpdump \-ddd command: one line |
| 131 |
that stores the number of instructions, followed by one line for each |
| 132 |
instruction. Instruction lines follow the pattern 'u16 u8 u8 u32' in decimal |
| 133 |
notation. Fields encode the operation, jump offset if true, jump offset if |
| 134 |
false and generic multiuse field 'K'. Comments are not supported. |
| 135 |
.PP |
| 136 |
For example, to read only packets matching 'ip proto 6', insert the following, |
| 137 |
without the comments or trailing whitespace: |
| 138 |
.IP |
| 139 |
4 # number of instructions |
| 140 |
.br |
| 141 |
48 0 0 9 # load byte ip\->proto |
| 142 |
.br |
| 143 |
21 0 1 6 # jump equal IPPROTO_TCP |
| 144 |
.br |
| 145 |
6 0 0 1 # return pass (non-zero) |
| 146 |
.br |
| 147 |
6 0 0 0 # return fail (zero) |
| 148 |
.PP |
| 149 |
You can pass this filter to the bpf match with the following command: |
| 150 |
.IP |
| 151 |
iptables \-A OUTPUT \-m bpf \-\-bytecode '4,48 0 0 9,21 0 1 6,6 0 0 1,6 0 0 0' \-j ACCEPT |
| 152 |
.PP |
| 153 |
Or instead, you can invoke the nfbpf_compile utility. |
| 154 |
.IP |
| 155 |
iptables \-A OUTPUT \-m bpf \-\-bytecode "`nfbpf_compile RAW 'ip proto 6'`" \-j ACCEPT |
| 156 |
.PP |
| 157 |
Or use tcpdump \-ddd. In that case, generate BPF targeting a device with the |
| 158 |
same data link type as the xtables match. Iptables passes packets from the |
| 159 |
network layer up, without mac layer. Select a device with data link type RAW, |
| 160 |
such as a tun device: |
| 161 |
.IP |
| 162 |
ip tuntap add tun0 mode tun |
| 163 |
.br |
| 164 |
ip link set tun0 up |
| 165 |
.br |
| 166 |
tcpdump \-ddd \-i tun0 ip proto 6 |
| 167 |
.PP |
| 168 |
See tcpdump \-L \-i $dev for a list of known data link types for a given device. |
| 169 |
.PP |
| 170 |
You may want to learn more about BPF from FreeBSD's bpf(4) manpage. |
| 171 |
.SS cgroup |
| 172 |
.TP |
| 173 |
[\fB!\fP] \fB\-\-path\fP \fIpath\fP |
| 174 |
Match cgroup2 membership. |
| 175 |
|
| 176 |
Each socket is associated with the v2 cgroup of the creating process. |
| 177 |
This matches packets coming from or going to all sockets in the |
| 178 |
sub-hierarchy of the specified path. The path should be relative to |
| 179 |
the root of the cgroup2 hierarchy. |
| 180 |
.TP |
| 181 |
[\fB!\fP] \fB\-\-cgroup\fP \fIclassid\fP |
| 182 |
Match cgroup net_cls classid. |
| 183 |
|
| 184 |
classid is the marker set through the cgroup net_cls controller. This |
| 185 |
option and \-\-path can't be used together. |
| 186 |
.PP |
| 187 |
Example: |
| 188 |
.IP |
| 189 |
iptables \-A OUTPUT \-p tcp \-\-sport 80 \-m cgroup ! \-\-path service/http\-server \-j DROP |
| 190 |
.IP |
| 191 |
iptables \-A OUTPUT \-p tcp \-\-sport 80 \-m cgroup ! \-\-cgroup 1 |
| 192 |
\-j DROP |
| 193 |
.PP |
| 194 |
\fBIMPORTANT\fP: when being used in the INPUT chain, the cgroup |
| 195 |
matcher is currently only of limited functionality, meaning it |
| 196 |
will only match on packets that are processed for local sockets |
| 197 |
through early socket demuxing. Therefore, general usage on the |
| 198 |
INPUT chain is not advised unless the implications are well |
| 199 |
understood. |
| 200 |
.PP |
| 201 |
Available since Linux 3.14. |
| 202 |
.SS cluster |
| 203 |
Allows you to deploy gateway and back-end load-sharing clusters without the |
| 204 |
need of load-balancers. |
| 205 |
.PP |
| 206 |
This match requires that all the nodes see the same packets. Thus, the cluster |
| 207 |
match decides if this node has to handle a packet given the following options: |
| 208 |
.TP |
| 209 |
\fB\-\-cluster\-total\-nodes\fP \fInum\fP |
| 210 |
Set number of total nodes in cluster. |
| 211 |
.TP |
| 212 |
[\fB!\fP] \fB\-\-cluster\-local\-node\fP \fInum\fP |
| 213 |
Set the local node number ID. |
| 214 |
.TP |
| 215 |
[\fB!\fP] \fB\-\-cluster\-local\-nodemask\fP \fImask\fP |
| 216 |
Set the local node number ID mask. You can use this option instead |
| 217 |
of \fB\-\-cluster\-local\-node\fP. |
| 218 |
.TP |
| 219 |
\fB\-\-cluster\-hash\-seed\fP \fIvalue\fP |
| 220 |
Set seed value of the Jenkins hash. |
| 221 |
.PP |
| 222 |
Example: |
| 223 |
.IP |
| 224 |
iptables \-A PREROUTING \-t mangle \-i eth1 \-m cluster |
| 225 |
\-\-cluster\-total\-nodes 2 \-\-cluster\-local\-node 1 |
| 226 |
\-\-cluster\-hash\-seed 0xdeadbeef |
| 227 |
\-j MARK \-\-set\-mark 0xffff |
| 228 |
.IP |
| 229 |
iptables \-A PREROUTING \-t mangle \-i eth2 \-m cluster |
| 230 |
\-\-cluster\-total\-nodes 2 \-\-cluster\-local\-node 1 |
| 231 |
\-\-cluster\-hash\-seed 0xdeadbeef |
| 232 |
\-j MARK \-\-set\-mark 0xffff |
| 233 |
.IP |
| 234 |
iptables \-A PREROUTING \-t mangle \-i eth1 |
| 235 |
\-m mark ! \-\-mark 0xffff \-j DROP |
| 236 |
.IP |
| 237 |
iptables \-A PREROUTING \-t mangle \-i eth2 |
| 238 |
\-m mark ! \-\-mark 0xffff \-j DROP |
| 239 |
.PP |
| 240 |
And the following commands to make all nodes see the same packets: |
| 241 |
.IP |
| 242 |
ip maddr add 01:00:5e:00:01:01 dev eth1 |
| 243 |
.IP |
| 244 |
ip maddr add 01:00:5e:00:01:02 dev eth2 |
| 245 |
.IP |
| 246 |
arptables \-A OUTPUT \-o eth1 \-\-h\-length 6 |
| 247 |
\-j mangle \-\-mangle\-mac\-s 01:00:5e:00:01:01 |
| 248 |
.IP |
| 249 |
arptables \-A INPUT \-i eth1 \-\-h\-length 6 |
| 250 |
\-\-destination\-mac 01:00:5e:00:01:01 |
| 251 |
\-j mangle \-\-mangle\-mac\-d 00:zz:yy:xx:5a:27 |
| 252 |
.IP |
| 253 |
arptables \-A OUTPUT \-o eth2 \-\-h\-length 6 |
| 254 |
\-j mangle \-\-mangle\-mac\-s 01:00:5e:00:01:02 |
| 255 |
.IP |
| 256 |
arptables \-A INPUT \-i eth2 \-\-h\-length 6 |
| 257 |
\-\-destination\-mac 01:00:5e:00:01:02 |
| 258 |
\-j mangle \-\-mangle\-mac\-d 00:zz:yy:xx:5a:27 |
| 259 |
.PP |
| 260 |
\fBNOTE\fP: the arptables commands above use mainstream syntax. If you |
| 261 |
are using arptables-jf included in some RedHat, CentOS and Fedora |
| 262 |
versions, you will hit syntax errors. Therefore, you'll have to adapt |
| 263 |
these to the arptables-jf syntax to get them working. |
| 264 |
.PP |
| 265 |
In the case of TCP connections, pickup facility has to be disabled |
| 266 |
to avoid marking TCP ACK packets coming in the reply direction as |
| 267 |
valid. |
| 268 |
.IP |
| 269 |
echo 0 > /proc/sys/net/netfilter/nf_conntrack_tcp_loose |
| 270 |
.SS comment |
| 271 |
Allows you to add comments (up to 256 characters) to any rule. |
| 272 |
.TP |
| 273 |
\fB\-\-comment\fP \fIcomment\fP |
| 274 |
.TP |
| 275 |
Example: |
| 276 |
iptables \-A INPUT \-i eth1 \-m comment \-\-comment "my local LAN" |
| 277 |
.SS connbytes |
| 278 |
Match by how many bytes or packets a connection (or one of the two |
| 279 |
flows constituting the connection) has transferred so far, or by |
| 280 |
average bytes per packet. |
| 281 |
.PP |
| 282 |
The counters are 64-bit and are thus not expected to overflow ;) |
| 283 |
.PP |
| 284 |
The primary use is to detect long-lived downloads and mark them to be |
| 285 |
scheduled using a lower priority band in traffic control. |
| 286 |
.PP |
| 287 |
The transferred bytes per connection can also be viewed through |
| 288 |
`conntrack \-L` and accessed via ctnetlink. |
| 289 |
.PP |
| 290 |
NOTE that for connections which have no accounting information, the match will |
| 291 |
always return false. The "net.netfilter.nf_conntrack_acct" sysctl flag controls |
| 292 |
whether \fBnew\fP connections will be byte/packet counted. Existing connection |
| 293 |
flows will not be gaining/losing a/the accounting structure when be sysctl flag |
| 294 |
is flipped. |
| 295 |
.TP |
| 296 |
[\fB!\fP] \fB\-\-connbytes\fP \fIfrom\fP[\fB:\fP\fIto\fP] |
| 297 |
match packets from a connection whose packets/bytes/average packet |
| 298 |
size is more than FROM and less than TO bytes/packets. if TO is |
| 299 |
omitted only FROM check is done. "!" is used to match packets not |
| 300 |
falling in the range. |
| 301 |
.TP |
| 302 |
\fB\-\-connbytes\-dir\fP {\fBoriginal\fP|\fBreply\fP|\fBboth\fP} |
| 303 |
which packets to consider |
| 304 |
.TP |
| 305 |
\fB\-\-connbytes\-mode\fP {\fBpackets\fP|\fBbytes\fP|\fBavgpkt\fP} |
| 306 |
whether to check the amount of packets, number of bytes transferred or |
| 307 |
the average size (in bytes) of all packets received so far. Note that |
| 308 |
when "both" is used together with "avgpkt", and data is going (mainly) |
| 309 |
only in one direction (for example HTTP), the average packet size will |
| 310 |
be about half of the actual data packets. |
| 311 |
.TP |
| 312 |
Example: |
| 313 |
iptables .. \-m connbytes \-\-connbytes 10000:100000 \-\-connbytes\-dir both \-\-connbytes\-mode bytes ... |
| 314 |
.SS connlabel |
| 315 |
Module matches or adds connlabels to a connection. |
| 316 |
connlabels are similar to connmarks, except labels are bit-based; i.e. |
| 317 |
all labels may be attached to a flow at the same time. |
| 318 |
Up to 128 unique labels are currently supported. |
| 319 |
.TP |
| 320 |
[\fB!\fP] \fB\-\-label\fP \fBname\fP |
| 321 |
matches if label \fBname\fP has been set on a connection. |
| 322 |
Instead of a name (which will be translated to a number, see EXAMPLE below), |
| 323 |
a number may be used instead. Using a number always overrides connlabel.conf. |
| 324 |
.TP |
| 325 |
\fB\-\-set\fP |
| 326 |
if the label has not been set on the connection, set it. |
| 327 |
Note that setting a label can fail. This is because the kernel allocates the |
| 328 |
conntrack label storage area when the connection is created, and it only |
| 329 |
reserves the amount of memory required by the ruleset that exists at |
| 330 |
the time the connection is created. |
| 331 |
In this case, the match will fail (or succeed, in case \fB\-\-label\fP |
| 332 |
option was negated). |
| 333 |
.PP |
| 334 |
This match depends on libnetfilter_conntrack 1.0.4 or later. |
| 335 |
Label translation is done via the \fB/etc/xtables/connlabel.conf\fP configuration file. |
| 336 |
.PP |
| 337 |
Example: |
| 338 |
.IP |
| 339 |
.nf |
| 340 |
0 eth0\-in |
| 341 |
1 eth0\-out |
| 342 |
2 ppp\-in |
| 343 |
3 ppp\-out |
| 344 |
4 bulk\-traffic |
| 345 |
5 interactive |
| 346 |
.fi |
| 347 |
.PP |
| 348 |
.SS connlimit |
| 349 |
Allows you to restrict the number of parallel connections to a server per |
| 350 |
client IP address (or client address block). |
| 351 |
.TP |
| 352 |
\fB\-\-connlimit\-upto\fP \fIn\fP |
| 353 |
Match if the number of existing connections is below or equal \fIn\fP. |
| 354 |
.TP |
| 355 |
\fB\-\-connlimit\-above\fP \fIn\fP |
| 356 |
Match if the number of existing connections is above \fIn\fP. |
| 357 |
.TP |
| 358 |
\fB\-\-connlimit\-mask\fP \fIprefix_length\fP |
| 359 |
Group hosts using the prefix length. For IPv4, this must be a number between |
| 360 |
(including) 0 and 32. For IPv6, between 0 and 128. If not specified, the |
| 361 |
maximum prefix length for the applicable protocol is used. |
| 362 |
.TP |
| 363 |
\fB\-\-connlimit\-saddr\fP |
| 364 |
Apply the limit onto the source group. This is the default if |
| 365 |
\-\-connlimit\-daddr is not specified. |
| 366 |
.TP |
| 367 |
\fB\-\-connlimit\-daddr\fP |
| 368 |
Apply the limit onto the destination group. |
| 369 |
.PP |
| 370 |
Examples: |
| 371 |
.IP \(bu 4 |
| 372 |
allow 2 telnet connections per client host: |
| 373 |
.br |
| 374 |
iptables \-A INPUT \-p tcp \-\-syn \-\-dport 23 \-m connlimit \-\-connlimit\-above 2 \-j REJECT |
| 375 |
.IP \(bu 4 |
| 376 |
you can also match the other way around: |
| 377 |
.br |
| 378 |
iptables \-A INPUT \-p tcp \-\-syn \-\-dport 23 \-m connlimit \-\-connlimit\-upto 2 \-j ACCEPT |
| 379 |
.IP \(bu 4 |
| 380 |
limit the number of parallel HTTP requests to 16 per class C sized \ |
| 381 |
source network (24 bit netmask): |
| 382 |
.br |
| 383 |
iptables \-p tcp \-\-syn \-\-dport 80 \-m connlimit \-\-connlimit\-above 16 |
| 384 |
\-\-connlimit\-mask 24 \-j REJECT |
| 385 |
.IP \(bu 4 |
| 386 |
limit the number of parallel HTTP requests to 16 for the link local network |
| 387 |
(IPv6): |
| 388 |
.br |
| 389 |
ip6tables \-p tcp \-\-syn \-\-dport 80 \-s fe80::/64 \-m connlimit \-\-connlimit\-above |
| 390 |
16 \-\-connlimit\-mask 64 \-j REJECT |
| 391 |
.IP \(bu 4 |
| 392 |
Limit the number of connections to a particular host: |
| 393 |
.br |
| 394 |
ip6tables \-p tcp \-\-syn \-\-dport 49152:65535 \-d 2001:db8::1 \-m connlimit |
| 395 |
\-\-connlimit\-above 100 \-j REJECT |
| 396 |
.SS connmark |
| 397 |
This module matches the netfilter mark field associated with a connection |
| 398 |
(which can be set using the \fBCONNMARK\fP target below). |
| 399 |
.TP |
| 400 |
[\fB!\fP] \fB\-\-mark\fP \fIvalue\fP[\fB/\fP\fImask\fP] |
| 401 |
Matches packets in connections with the given mark value (if a mask is |
| 402 |
specified, this is logically ANDed with the mark before the comparison). |
| 403 |
.SS conntrack |
| 404 |
This module, when combined with connection tracking, allows access to the |
| 405 |
connection tracking state for this packet/connection. |
| 406 |
.TP |
| 407 |
[\fB!\fP] \fB\-\-ctstate\fP \fIstatelist\fP |
| 408 |
\fIstatelist\fP is a comma separated list of the connection states to match. |
| 409 |
Possible states are listed below. |
| 410 |
.TP |
| 411 |
[\fB!\fP] \fB\-\-ctproto\fP \fIl4proto\fP |
| 412 |
Layer-4 protocol to match (by number or name) |
| 413 |
.TP |
| 414 |
[\fB!\fP] \fB\-\-ctorigsrc\fP \fIaddress\fP[\fB/\fP\fImask\fP] |
| 415 |
.TP |
| 416 |
[\fB!\fP] \fB\-\-ctorigdst\fP \fIaddress\fP[\fB/\fP\fImask\fP] |
| 417 |
.TP |
| 418 |
[\fB!\fP] \fB\-\-ctreplsrc\fP \fIaddress\fP[\fB/\fP\fImask\fP] |
| 419 |
.TP |
| 420 |
[\fB!\fP] \fB\-\-ctrepldst\fP \fIaddress\fP[\fB/\fP\fImask\fP] |
| 421 |
Match against original/reply source/destination address |
| 422 |
.TP |
| 423 |
[\fB!\fP] \fB\-\-ctorigsrcport\fP \fIport\fP[\fB:\fP\fIport\fP] |
| 424 |
.TP |
| 425 |
[\fB!\fP] \fB\-\-ctorigdstport\fP \fIport\fP[\fB:\fP\fIport\fP] |
| 426 |
.TP |
| 427 |
[\fB!\fP] \fB\-\-ctreplsrcport\fP \fIport\fP[\fB:\fP\fIport\fP] |
| 428 |
.TP |
| 429 |
[\fB!\fP] \fB\-\-ctrepldstport\fP \fIport\fP[\fB:\fP\fIport\fP] |
| 430 |
Match against original/reply source/destination port (TCP/UDP/etc.) or GRE key. |
| 431 |
Matching against port ranges is only supported in kernel versions above 2.6.38. |
| 432 |
.TP |
| 433 |
[\fB!\fP] \fB\-\-ctstatus\fP \fIstatelist\fP |
| 434 |
\fIstatuslist\fP is a comma separated list of the connection statuses to match. |
| 435 |
Possible statuses are listed below. |
| 436 |
.TP |
| 437 |
[\fB!\fP] \fB\-\-ctexpire\fP \fItime\fP[\fB:\fP\fItime\fP] |
| 438 |
Match remaining lifetime in seconds against given value or range of values |
| 439 |
(inclusive) |
| 440 |
.TP |
| 441 |
\fB\-\-ctdir\fP {\fBORIGINAL\fP|\fBREPLY\fP} |
| 442 |
Match packets that are flowing in the specified direction. If this flag is not |
| 443 |
specified at all, matches packets in both directions. |
| 444 |
.PP |
| 445 |
States for \fB\-\-ctstate\fP: |
| 446 |
.TP |
| 447 |
\fBINVALID\fP |
| 448 |
The packet is associated with no known connection. |
| 449 |
.TP |
| 450 |
\fBNEW\fP |
| 451 |
The packet has started a new connection or otherwise associated |
| 452 |
with a connection which has not seen packets in both directions. |
| 453 |
.TP |
| 454 |
\fBESTABLISHED\fP |
| 455 |
The packet is associated with a connection which has seen packets |
| 456 |
in both directions. |
| 457 |
.TP |
| 458 |
\fBRELATED\fP |
| 459 |
The packet is starting a new connection, but is associated with an |
| 460 |
existing connection, such as an FTP data transfer or an ICMP error. |
| 461 |
.TP |
| 462 |
\fBUNTRACKED\fP |
| 463 |
The packet is not tracked at all, which happens if you explicitly untrack it |
| 464 |
by using \-j CT \-\-notrack in the raw table. |
| 465 |
.TP |
| 466 |
\fBSNAT\fP |
| 467 |
A virtual state, matching if the original source address differs from the reply |
| 468 |
destination. |
| 469 |
.TP |
| 470 |
\fBDNAT\fP |
| 471 |
A virtual state, matching if the original destination differs from the reply |
| 472 |
source. |
| 473 |
.PP |
| 474 |
Statuses for \fB\-\-ctstatus\fP: |
| 475 |
.TP |
| 476 |
\fBNONE\fP |
| 477 |
None of the below. |
| 478 |
.TP |
| 479 |
\fBEXPECTED\fP |
| 480 |
This is an expected connection (i.e. a conntrack helper set it up). |
| 481 |
.TP |
| 482 |
\fBSEEN_REPLY\fP |
| 483 |
Conntrack has seen packets in both directions. |
| 484 |
.TP |
| 485 |
\fBASSURED\fP |
| 486 |
Conntrack entry should never be early-expired. |
| 487 |
.TP |
| 488 |
\fBCONFIRMED\fP |
| 489 |
Connection is confirmed: originating packet has left box. |
| 490 |
.SS cpu |
| 491 |
.TP |
| 492 |
[\fB!\fP] \fB\-\-cpu\fP \fInumber\fP |
| 493 |
Match cpu handling this packet. cpus are numbered from 0 to NR_CPUS\-1 |
| 494 |
Can be used in combination with RPS (Remote Packet Steering) or |
| 495 |
multiqueue NICs to spread network traffic on different queues. |
| 496 |
.PP |
| 497 |
Example: |
| 498 |
.PP |
| 499 |
iptables \-t nat \-A PREROUTING \-p tcp \-\-dport 80 \-m cpu \-\-cpu 0 |
| 500 |
\-j REDIRECT \-\-to\-ports 8080 |
| 501 |
.PP |
| 502 |
iptables \-t nat \-A PREROUTING \-p tcp \-\-dport 80 \-m cpu \-\-cpu 1 |
| 503 |
\-j REDIRECT \-\-to\-ports 8081 |
| 504 |
.PP |
| 505 |
Available since Linux 2.6.36. |
| 506 |
.SS dccp |
| 507 |
.TP |
| 508 |
[\fB!\fP] \fB\-\-source\-port\fP,\fB\-\-sport\fP \fIport\fP[\fB:\fP\fIport\fP] |
| 509 |
.TP |
| 510 |
[\fB!\fP] \fB\-\-destination\-port\fP,\fB\-\-dport\fP \fIport\fP[\fB:\fP\fIport\fP] |
| 511 |
.TP |
| 512 |
[\fB!\fP] \fB\-\-dccp\-types\fP \fImask\fP |
| 513 |
Match when the DCCP packet type is one of 'mask'. 'mask' is a comma-separated |
| 514 |
list of packet types. Packet types are: |
| 515 |
.BR "REQUEST RESPONSE DATA ACK DATAACK CLOSEREQ CLOSE RESET SYNC SYNCACK INVALID" . |
| 516 |
.TP |
| 517 |
[\fB!\fP] \fB\-\-dccp\-option\fP \fInumber\fP |
| 518 |
Match if DCCP option set. |
| 519 |
.SS devgroup |
| 520 |
Match device group of a packet's incoming/outgoing interface. |
| 521 |
.TP |
| 522 |
[\fB!\fP] \fB\-\-src\-group\fP \fIname\fP |
| 523 |
Match device group of incoming device |
| 524 |
.TP |
| 525 |
[\fB!\fP] \fB\-\-dst\-group\fP \fIname\fP |
| 526 |
Match device group of outgoing device |
| 527 |
.SS dscp |
| 528 |
This module matches the 6 bit DSCP field within the TOS field in the |
| 529 |
IP header. DSCP has superseded TOS within the IETF. |
| 530 |
.TP |
| 531 |
[\fB!\fP] \fB\-\-dscp\fP \fIvalue\fP |
| 532 |
Match against a numeric (decimal or hex) value in the range 0\(en63. |
| 533 |
.TP |
| 534 |
[\fB!\fP] \fB\-\-dscp\-class\fP \fIclass\fP |
| 535 |
Match the DiffServ class. This value may be any of the |
| 536 |
BE, EF, AFxx or CSx classes. It will then be converted |
| 537 |
into its according numeric value. |
| 538 |
.SS dst (IPv6-specific) |
| 539 |
This module matches the parameters in Destination Options header |
| 540 |
.TP |
| 541 |
[\fB!\fP] \fB\-\-dst\-len\fP \fIlength\fP |
| 542 |
Total length of this header in octets. |
| 543 |
.TP |
| 544 |
\fB\-\-dst\-opts\fP \fItype\fP[\fB:\fP\fIlength\fP][\fB,\fP\fItype\fP[\fB:\fP\fIlength\fP]...] |
| 545 |
numeric type of option and the length of the option data in octets. |
| 546 |
.SS ecn |
| 547 |
This allows you to match the ECN bits of the IPv4/IPv6 and TCP header. ECN is the Explicit Congestion Notification mechanism as specified in RFC3168 |
| 548 |
.TP |
| 549 |
[\fB!\fP] \fB\-\-ecn\-tcp\-cwr\fP |
| 550 |
This matches if the TCP ECN CWR (Congestion Window Received) bit is set. |
| 551 |
.TP |
| 552 |
[\fB!\fP] \fB\-\-ecn\-tcp\-ece\fP |
| 553 |
This matches if the TCP ECN ECE (ECN Echo) bit is set. |
| 554 |
.TP |
| 555 |
[\fB!\fP] \fB\-\-ecn\-ip\-ect\fP \fInum\fP |
| 556 |
This matches a particular IPv4/IPv6 ECT (ECN-Capable Transport). You have to specify |
| 557 |
a number between `0' and `3'. |
| 558 |
.SS esp |
| 559 |
This module matches the SPIs in ESP header of IPsec packets. |
| 560 |
.TP |
| 561 |
[\fB!\fP] \fB\-\-espspi\fP \fIspi\fP[\fB:\fP\fIspi\fP] |
| 562 |
.SS eui64 (IPv6-specific) |
| 563 |
This module matches the EUI-64 part of a stateless autoconfigured IPv6 address. |
| 564 |
It compares the EUI-64 derived from the source MAC address in Ethernet frame |
| 565 |
with the lower 64 bits of the IPv6 source address. But "Universal/Local" |
| 566 |
bit is not compared. This module doesn't match other link layer frame, and |
| 567 |
is only valid in the |
| 568 |
.BR PREROUTING , |
| 569 |
.BR INPUT |
| 570 |
and |
| 571 |
.BR FORWARD |
| 572 |
chains. |
| 573 |
.SS frag (IPv6-specific) |
| 574 |
This module matches the parameters in Fragment header. |
| 575 |
.TP |
| 576 |
[\fB!\fP] \fB\-\-fragid\fP \fIid\fP[\fB:\fP\fIid\fP] |
| 577 |
Matches the given Identification or range of it. |
| 578 |
.TP |
| 579 |
[\fB!\fP] \fB\-\-fraglen\fP \fIlength\fP |
| 580 |
This option cannot be used with kernel version 2.6.10 or later. The length of |
| 581 |
Fragment header is static and this option doesn't make sense. |
| 582 |
.TP |
| 583 |
\fB\-\-fragres\fP |
| 584 |
Matches if the reserved fields are filled with zero. |
| 585 |
.TP |
| 586 |
\fB\-\-fragfirst\fP |
| 587 |
Matches on the first fragment. |
| 588 |
.TP |
| 589 |
\fB\-\-fragmore\fP |
| 590 |
Matches if there are more fragments. |
| 591 |
.TP |
| 592 |
\fB\-\-fraglast\fP |
| 593 |
Matches if this is the last fragment. |
| 594 |
.SS hashlimit |
| 595 |
\fBhashlimit\fP uses hash buckets to express a rate limiting match (like the |
| 596 |
\fBlimit\fP match) for a group of connections using a \fBsingle\fP iptables |
| 597 |
rule. Grouping can be done per-hostgroup (source and/or destination address) |
| 598 |
and/or per-port. It gives you the ability to express "\fIN\fP packets per time |
| 599 |
quantum per group" or "\fIN\fP bytes per seconds" (see below for some examples). |
| 600 |
.PP |
| 601 |
A hash limit option (\fB\-\-hashlimit\-upto\fP, \fB\-\-hashlimit\-above\fP) and |
| 602 |
\fB\-\-hashlimit\-name\fP are required. |
| 603 |
.TP |
| 604 |
\fB\-\-hashlimit\-upto\fP \fIamount\fP[\fB/second\fP|\fB/minute\fP|\fB/hour\fP|\fB/day\fP] |
| 605 |
Match if the rate is below or equal to \fIamount\fP/quantum. It is specified either as |
| 606 |
a number, with an optional time quantum suffix (the default is 3/hour), or as |
| 607 |
\fIamount\fPb/second (number of bytes per second). |
| 608 |
.TP |
| 609 |
\fB\-\-hashlimit\-above\fP \fIamount\fP[\fB/second\fP|\fB/minute\fP|\fB/hour\fP|\fB/day\fP] |
| 610 |
Match if the rate is above \fIamount\fP/quantum. |
| 611 |
.TP |
| 612 |
\fB\-\-hashlimit\-burst\fP \fIamount\fP |
| 613 |
Maximum initial number of packets to match: this number gets recharged by one |
| 614 |
every time the limit specified above is not reached, up to this number; the |
| 615 |
default is 5. When byte-based rate matching is requested, this option specifies |
| 616 |
the amount of bytes that can exceed the given rate. This option should be used |
| 617 |
with caution \(em if the entry expires, the burst value is reset too. |
| 618 |
.TP |
| 619 |
\fB\-\-hashlimit\-mode\fP {\fBsrcip\fP|\fBsrcport\fP|\fBdstip\fP|\fBdstport\fP}\fB,\fP... |
| 620 |
A comma-separated list of objects to take into consideration. If no |
| 621 |
\-\-hashlimit\-mode option is given, hashlimit acts like limit, but at the |
| 622 |
expensive of doing the hash housekeeping. |
| 623 |
.TP |
| 624 |
\fB\-\-hashlimit\-srcmask\fP \fIprefix\fP |
| 625 |
When \-\-hashlimit\-mode srcip is used, all source addresses encountered will be |
| 626 |
grouped according to the given prefix length and the so-created subnet will be |
| 627 |
subject to hashlimit. \fIprefix\fP must be between (inclusive) 0 and 32. Note |
| 628 |
that \-\-hashlimit\-srcmask 0 is basically doing the same thing as not specifying |
| 629 |
srcip for \-\-hashlimit\-mode, but is technically more expensive. |
| 630 |
.TP |
| 631 |
\fB\-\-hashlimit\-dstmask\fP \fIprefix\fP |
| 632 |
Like \-\-hashlimit\-srcmask, but for destination addresses. |
| 633 |
.TP |
| 634 |
\fB\-\-hashlimit\-name\fP \fIfoo\fP |
| 635 |
The name for the /proc/net/ipt_hashlimit/foo entry. |
| 636 |
.TP |
| 637 |
\fB\-\-hashlimit\-htable\-size\fP \fIbuckets\fP |
| 638 |
The number of buckets of the hash table |
| 639 |
.TP |
| 640 |
\fB\-\-hashlimit\-htable\-max\fP \fIentries\fP |
| 641 |
Maximum entries in the hash. |
| 642 |
.TP |
| 643 |
\fB\-\-hashlimit\-htable\-expire\fP \fImsec\fP |
| 644 |
After how many milliseconds do hash entries expire. |
| 645 |
.TP |
| 646 |
\fB\-\-hashlimit\-htable\-gcinterval\fP \fImsec\fP |
| 647 |
How many milliseconds between garbage collection intervals. |
| 648 |
.TP |
| 649 |
\fB\-\-hashlimit\-rate\-match\fP |
| 650 |
Classify the flow instead of rate-limiting it. This acts like a |
| 651 |
true/false match on whether the rate is above/below a certain number |
| 652 |
.TP |
| 653 |
\fB\-\-hashlimit\-rate\-interval\fP \fIsec\fP |
| 654 |
Can be used with \-\-hashlimit\-rate\-match to specify the interval |
| 655 |
at which the rate should be sampled |
| 656 |
.PP |
| 657 |
Examples: |
| 658 |
.TP |
| 659 |
matching on source host |
| 660 |
"1000 packets per second for every host in 192.168.0.0/16" => |
| 661 |
\-s 192.168.0.0/16 \-\-hashlimit\-mode srcip \-\-hashlimit\-upto 1000/sec |
| 662 |
.TP |
| 663 |
matching on source port |
| 664 |
"100 packets per second for every service of 192.168.1.1" => |
| 665 |
\-s 192.168.1.1 \-\-hashlimit\-mode srcport \-\-hashlimit\-upto 100/sec |
| 666 |
.TP |
| 667 |
matching on subnet |
| 668 |
"10000 packets per minute for every /28 subnet (groups of 8 addresses) |
| 669 |
in 10.0.0.0/8" => |
| 670 |
\-s 10.0.0.0/8 \-\-hashlimit\-mask 28 \-\-hashlimit\-upto 10000/min |
| 671 |
.TP |
| 672 |
matching bytes per second |
| 673 |
"flows exceeding 512kbyte/s" => |
| 674 |
\-\-hashlimit\-mode srcip,dstip,srcport,dstport \-\-hashlimit\-above 512kb/s |
| 675 |
.TP |
| 676 |
matching bytes per second |
| 677 |
"hosts that exceed 512kbyte/s, but permit up to 1Megabytes without matching" |
| 678 |
\-\-hashlimit\-mode dstip \-\-hashlimit\-above 512kb/s \-\-hashlimit\-burst 1mb |
| 679 |
.SS hbh (IPv6-specific) |
| 680 |
This module matches the parameters in Hop-by-Hop Options header |
| 681 |
.TP |
| 682 |
[\fB!\fP] \fB\-\-hbh\-len\fP \fIlength\fP |
| 683 |
Total length of this header in octets. |
| 684 |
.TP |
| 685 |
\fB\-\-hbh\-opts\fP \fItype\fP[\fB:\fP\fIlength\fP][\fB,\fP\fItype\fP[\fB:\fP\fIlength\fP]...] |
| 686 |
numeric type of option and the length of the option data in octets. |
| 687 |
.SS helper |
| 688 |
This module matches packets related to a specific conntrack helper. |
| 689 |
.TP |
| 690 |
[\fB!\fP] \fB\-\-helper\fP \fIstring\fP |
| 691 |
Matches packets related to the specified conntrack helper. |
| 692 |
.RS |
| 693 |
.PP |
| 694 |
string can be "ftp" for packets related to an FTP session on default port. |
| 695 |
For other ports, append \-\-portnr to the value, ie. "ftp\-2121". |
| 696 |
.PP |
| 697 |
Same rules apply for other conntrack helpers. |
| 698 |
.RE |
| 699 |
.SS hl (IPv6-specific) |
| 700 |
This module matches the Hop Limit field in the IPv6 header. |
| 701 |
.TP |
| 702 |
[\fB!\fP] \fB\-\-hl\-eq\fP \fIvalue\fP |
| 703 |
Matches if Hop Limit equals \fIvalue\fP. |
| 704 |
.TP |
| 705 |
\fB\-\-hl\-lt\fP \fIvalue\fP |
| 706 |
Matches if Hop Limit is less than \fIvalue\fP. |
| 707 |
.TP |
| 708 |
\fB\-\-hl\-gt\fP \fIvalue\fP |
| 709 |
Matches if Hop Limit is greater than \fIvalue\fP. |
| 710 |
.SS icmp (IPv4-specific) |
| 711 |
This extension can be used if `\-\-protocol icmp' is specified. It |
| 712 |
provides the following option: |
| 713 |
.TP |
| 714 |
[\fB!\fP] \fB\-\-icmp\-type\fP {\fItype\fP[\fB/\fP\fIcode\fP]|\fItypename\fP} |
| 715 |
This allows specification of the ICMP type, which can be a numeric |
| 716 |
ICMP type, type/code pair, or one of the ICMP type names shown by the command |
| 717 |
.nf |
| 718 |
iptables \-p icmp \-h |
| 719 |
.fi |
| 720 |
.SS icmp6 (IPv6-specific) |
| 721 |
This extension can be used if `\-\-protocol ipv6\-icmp' or `\-\-protocol icmpv6' is |
| 722 |
specified. It provides the following option: |
| 723 |
.TP |
| 724 |
[\fB!\fP] \fB\-\-icmpv6\-type\fP \fItype\fP[\fB/\fP\fIcode\fP]|\fItypename\fP |
| 725 |
This allows specification of the ICMPv6 type, which can be a numeric |
| 726 |
ICMPv6 |
| 727 |
.IR type , |
| 728 |
.IR type |
| 729 |
and |
| 730 |
.IR code , |
| 731 |
or one of the ICMPv6 type names shown by the command |
| 732 |
.nf |
| 733 |
ip6tables \-p ipv6\-icmp \-h |
| 734 |
.fi |
| 735 |
.SS iprange |
| 736 |
This matches on a given arbitrary range of IP addresses. |
| 737 |
.TP |
| 738 |
[\fB!\fP] \fB\-\-src\-range\fP \fIfrom\fP[\fB\-\fP\fIto\fP] |
| 739 |
Match source IP in the specified range. |
| 740 |
.TP |
| 741 |
[\fB!\fP] \fB\-\-dst\-range\fP \fIfrom\fP[\fB\-\fP\fIto\fP] |
| 742 |
Match destination IP in the specified range. |
| 743 |
.SS ipv6header (IPv6-specific) |
| 744 |
This module matches IPv6 extension headers and/or upper layer header. |
| 745 |
.TP |
| 746 |
\fB\-\-soft\fP |
| 747 |
Matches if the packet includes \fBany\fP of the headers specified with |
| 748 |
\fB\-\-header\fP. |
| 749 |
.TP |
| 750 |
[\fB!\fP] \fB\-\-header\fP \fIheader\fP[\fB,\fP\fIheader\fP...] |
| 751 |
Matches the packet which EXACTLY includes all specified headers. The headers |
| 752 |
encapsulated with ESP header are out of scope. |
| 753 |
Possible \fIheader\fP types can be: |
| 754 |
.TP |
| 755 |
\fBhop\fP|\fBhop\-by\-hop\fP |
| 756 |
Hop-by-Hop Options header |
| 757 |
.TP |
| 758 |
\fBdst\fP |
| 759 |
Destination Options header |
| 760 |
.TP |
| 761 |
\fBroute\fP |
| 762 |
Routing header |
| 763 |
.TP |
| 764 |
\fBfrag\fP |
| 765 |
Fragment header |
| 766 |
.TP |
| 767 |
\fBauth\fP |
| 768 |
Authentication header |
| 769 |
.TP |
| 770 |
\fBesp\fP |
| 771 |
Encapsulating Security Payload header |
| 772 |
.TP |
| 773 |
\fBnone\fP |
| 774 |
No Next header which matches 59 in the 'Next Header field' of IPv6 header or |
| 775 |
any IPv6 extension headers |
| 776 |
.TP |
| 777 |
\fBprot\fP |
| 778 |
which matches any upper layer protocol header. A protocol name from |
| 779 |
/etc/protocols and numeric value also allowed. The number 255 is equivalent to |
| 780 |
\fBprot\fP. |
| 781 |
.SS ipvs |
| 782 |
Match IPVS connection properties. |
| 783 |
.TP |
| 784 |
[\fB!\fP] \fB\-\-ipvs\fP |
| 785 |
packet belongs to an IPVS connection |
| 786 |
.TP |
| 787 |
Any of the following options implies \-\-ipvs (even negated) |
| 788 |
.TP |
| 789 |
[\fB!\fP] \fB\-\-vproto\fP \fIprotocol\fP |
| 790 |
VIP protocol to match; by number or name, e.g. "tcp" |
| 791 |
.TP |
| 792 |
[\fB!\fP] \fB\-\-vaddr\fP \fIaddress\fP[\fB/\fP\fImask\fP] |
| 793 |
VIP address to match |
| 794 |
.TP |
| 795 |
[\fB!\fP] \fB\-\-vport\fP \fIport\fP |
| 796 |
VIP port to match; by number or name, e.g. "http" |
| 797 |
.TP |
| 798 |
\fB\-\-vdir\fP {\fBORIGINAL\fP|\fBREPLY\fP} |
| 799 |
flow direction of packet |
| 800 |
.TP |
| 801 |
[\fB!\fP] \fB\-\-vmethod\fP {\fBGATE\fP|\fBIPIP\fP|\fBMASQ\fP} |
| 802 |
IPVS forwarding method used |
| 803 |
.TP |
| 804 |
[\fB!\fP] \fB\-\-vportctl\fP \fIport\fP |
| 805 |
VIP port of the controlling connection to match, e.g. 21 for FTP |
| 806 |
.SS length |
| 807 |
This module matches the length of the layer-3 payload (e.g. layer-4 packet) |
| 808 |
of a packet against a specific value |
| 809 |
or range of values. |
| 810 |
.TP |
| 811 |
[\fB!\fP] \fB\-\-length\fP \fIlength\fP[\fB:\fP\fIlength\fP] |
| 812 |
.SS limit |
| 813 |
This module matches at a limited rate using a token bucket filter. |
| 814 |
A rule using this extension will match until this limit is reached. |
| 815 |
It can be used in combination with the |
| 816 |
.B LOG |
| 817 |
target to give limited logging, for example. |
| 818 |
.PP |
| 819 |
xt_limit has no negation support \(em you will have to use \-m hashlimit ! |
| 820 |
\-\-hashlimit \fIrate\fP in this case whilst omitting \-\-hashlimit\-mode. |
| 821 |
.TP |
| 822 |
\fB\-\-limit\fP \fIrate\fP[\fB/second\fP|\fB/minute\fP|\fB/hour\fP|\fB/day\fP] |
| 823 |
Maximum average matching rate: specified as a number, with an optional |
| 824 |
`/second', `/minute', `/hour', or `/day' suffix; the default is |
| 825 |
3/hour. |
| 826 |
.TP |
| 827 |
\fB\-\-limit\-burst\fP \fInumber\fP |
| 828 |
Maximum initial number of packets to match: this number gets |
| 829 |
recharged by one every time the limit specified above is not reached, |
| 830 |
up to this number; the default is 5. |
| 831 |
.SS mac |
| 832 |
.TP |
| 833 |
[\fB!\fP] \fB\-\-mac\-source\fP \fIaddress\fP |
| 834 |
Match source MAC address. It must be of the form XX:XX:XX:XX:XX:XX. |
| 835 |
Note that this only makes sense for packets coming from an Ethernet device |
| 836 |
and entering the |
| 837 |
.BR PREROUTING , |
| 838 |
.B FORWARD |
| 839 |
or |
| 840 |
.B INPUT |
| 841 |
chains. |
| 842 |
.SS mark |
| 843 |
This module matches the netfilter mark field associated with a packet |
| 844 |
(which can be set using the |
| 845 |
.B MARK |
| 846 |
target below). |
| 847 |
.TP |
| 848 |
[\fB!\fP] \fB\-\-mark\fP \fIvalue\fP[\fB/\fP\fImask\fP] |
| 849 |
Matches packets with the given unsigned mark value (if a \fImask\fP is |
| 850 |
specified, this is logically ANDed with the \fImask\fP before the |
| 851 |
comparison). |
| 852 |
.SS mh (IPv6-specific) |
| 853 |
This extension is loaded if `\-\-protocol ipv6\-mh' or `\-\-protocol mh' is |
| 854 |
specified. It provides the following option: |
| 855 |
.TP |
| 856 |
[\fB!\fP] \fB\-\-mh\-type\fP \fItype\fP[\fB:\fP\fItype\fP] |
| 857 |
This allows specification of the Mobility Header(MH) type, which can be |
| 858 |
a numeric MH |
| 859 |
.IR type , |
| 860 |
.IR type |
| 861 |
or one of the MH type names shown by the command |
| 862 |
.nf |
| 863 |
ip6tables \-p mh \-h |
| 864 |
.fi |
| 865 |
.SS multiport |
| 866 |
This module matches a set of source or destination ports. Up to 15 |
| 867 |
ports can be specified. A port range (port:port) counts as two |
| 868 |
ports. It can only be used in conjunction with one of the |
| 869 |
following protocols: |
| 870 |
\fBtcp\fP, \fBudp\fP, \fBudplite\fP, \fBdccp\fP and \fBsctp\fP. |
| 871 |
.TP |
| 872 |
[\fB!\fP] \fB\-\-source\-ports\fP,\fB\-\-sports\fP \fIport\fP[\fB,\fP\fIport\fP|\fB,\fP\fIport\fP\fB:\fP\fIport\fP]... |
| 873 |
Match if the source port is one of the given ports. The flag |
| 874 |
\fB\-\-sports\fP |
| 875 |
is a convenient alias for this option. Multiple ports or port ranges are |
| 876 |
separated using a comma, and a port range is specified using a colon. |
| 877 |
\fB53,1024:65535\fP would therefore match ports 53 and all from 1024 through |
| 878 |
65535. |
| 879 |
.TP |
| 880 |
[\fB!\fP] \fB\-\-destination\-ports\fP,\fB\-\-dports\fP \fIport\fP[\fB,\fP\fIport\fP|\fB,\fP\fIport\fP\fB:\fP\fIport\fP]... |
| 881 |
Match if the destination port is one of the given ports. The flag |
| 882 |
\fB\-\-dports\fP |
| 883 |
is a convenient alias for this option. |
| 884 |
.TP |
| 885 |
[\fB!\fP] \fB\-\-ports\fP \fIport\fP[\fB,\fP\fIport\fP|\fB,\fP\fIport\fP\fB:\fP\fIport\fP]... |
| 886 |
Match if either the source or destination ports are equal to one of |
| 887 |
the given ports. |
| 888 |
.SS nfacct |
| 889 |
The nfacct match provides the extended accounting infrastructure for iptables. |
| 890 |
You have to use this match together with the standalone user-space utility |
| 891 |
.B nfacct(8) |
| 892 |
.PP |
| 893 |
The only option available for this match is the following: |
| 894 |
.TP |
| 895 |
\fB\-\-nfacct\-name\fP \fIname\fP |
| 896 |
This allows you to specify the existing object name that will be use for |
| 897 |
accounting the traffic that this rule-set is matching. |
| 898 |
.PP |
| 899 |
To use this extension, you have to create an accounting object: |
| 900 |
.IP |
| 901 |
nfacct add http\-traffic |
| 902 |
.PP |
| 903 |
Then, you have to attach it to the accounting object via iptables: |
| 904 |
.IP |
| 905 |
iptables \-I INPUT \-p tcp \-\-sport 80 \-m nfacct \-\-nfacct\-name http\-traffic |
| 906 |
.IP |
| 907 |
iptables \-I OUTPUT \-p tcp \-\-dport 80 \-m nfacct \-\-nfacct\-name http\-traffic |
| 908 |
.PP |
| 909 |
Then, you can check for the amount of traffic that the rules match: |
| 910 |
.IP |
| 911 |
nfacct get http\-traffic |
| 912 |
.IP |
| 913 |
{ pkts = 00000000000000000156, bytes = 00000000000000151786 } = http\-traffic; |
| 914 |
.PP |
| 915 |
You can obtain |
| 916 |
.B nfacct(8) |
| 917 |
from https://www.netfilter.org or, alternatively, from the git.netfilter.org |
| 918 |
repository. |
| 919 |
.SS osf |
| 920 |
The osf module does passive operating system fingerprinting. This module |
| 921 |
compares some data (Window Size, MSS, options and their order, TTL, DF, |
| 922 |
and others) from packets with the SYN bit set. |
| 923 |
.TP |
| 924 |
[\fB!\fP] \fB\-\-genre\fP \fIstring\fP |
| 925 |
Match an operating system genre by using a passive fingerprinting. |
| 926 |
.TP |
| 927 |
\fB\-\-ttl\fP \fIlevel\fP |
| 928 |
Do additional TTL checks on the packet to determine the operating system. |
| 929 |
\fIlevel\fP can be one of the following values: |
| 930 |
.RS |
| 931 |
.TP |
| 932 |
\fB0\fP |
| 933 |
True IP address and fingerprint TTL comparison. This generally works for |
| 934 |
LANs. |
| 935 |
.TP |
| 936 |
\fB1\fP |
| 937 |
Check if the IP header's TTL is less than the fingerprint one. Works for |
| 938 |
globally-routable addresses. |
| 939 |
.TP |
| 940 |
\fB2\fP |
| 941 |
Do not compare the TTL at all. |
| 942 |
.RE |
| 943 |
.TP |
| 944 |
\fB\-\-log\fP \fIlevel\fP |
| 945 |
Log determined genres into dmesg even if they do not match the desired one. |
| 946 |
\fIlevel\fP can be one of the following values: |
| 947 |
.RS |
| 948 |
.TP |
| 949 |
\fB0\fP |
| 950 |
Log all matched or unknown signatures |
| 951 |
.TP |
| 952 |
\fB1\fP |
| 953 |
Log only the first one |
| 954 |
.TP |
| 955 |
\fB2\fP |
| 956 |
Log all known matched signatures |
| 957 |
.RE |
| 958 |
.PP |
| 959 |
You may find something like this in syslog: |
| 960 |
.PP |
| 961 |
Windows [2000:SP3:Windows XP Pro SP1, 2000 SP3]: 11.22.33.55:4024 \-> |
| 962 |
11.22.33.44:139 hops=3 Linux [2.5\-2.6:] : 1.2.3.4:42624 \-> 1.2.3.5:22 hops=4 |
| 963 |
.PP |
| 964 |
OS fingerprints are loadable using the \fBnfnl_osf\fP program. To load |
| 965 |
fingerprints from a file, use: |
| 966 |
.PP |
| 967 |
\fBnfnl_osf \-f /usr/share/xtables/pf.os\fP |
| 968 |
.PP |
| 969 |
To remove them again, |
| 970 |
.PP |
| 971 |
\fBnfnl_osf \-f /usr/share/xtables/pf.os \-d\fP |
| 972 |
.PP |
| 973 |
The fingerprint database can be downloaded from |
| 974 |
http://www.openbsd.org/cgi\-bin/cvsweb/src/etc/pf.os . |
| 975 |
.SS owner |
| 976 |
This module attempts to match various characteristics of the packet creator, |
| 977 |
for locally generated packets. This match is only valid in the OUTPUT and |
| 978 |
POSTROUTING chains. Forwarded packets do not have any socket associated with |
| 979 |
them. Packets from kernel threads do have a socket, but usually no owner. |
| 980 |
.TP |
| 981 |
[\fB!\fP] \fB\-\-uid\-owner\fP \fIusername\fP |
| 982 |
.TP |
| 983 |
[\fB!\fP] \fB\-\-uid\-owner\fP \fIuserid\fP[\fB\-\fP\fIuserid\fP] |
| 984 |
Matches if the packet socket's file structure (if it has one) is owned by the |
| 985 |
given user. You may also specify a numerical UID, or an UID range. |
| 986 |
.TP |
| 987 |
[\fB!\fP] \fB\-\-gid\-owner\fP \fIgroupname\fP |
| 988 |
.TP |
| 989 |
[\fB!\fP] \fB\-\-gid\-owner\fP \fIgroupid\fP[\fB\-\fP\fIgroupid\fP] |
| 990 |
Matches if the packet socket's file structure is owned by the given group. |
| 991 |
You may also specify a numerical GID, or a GID range. |
| 992 |
.TP |
| 993 |
\fB\-\-suppl\-groups\fP |
| 994 |
Causes group(s) specified with \fB\-\-gid\-owner\fP to be also checked in the |
| 995 |
supplementary groups of a process. |
| 996 |
.TP |
| 997 |
[\fB!\fP] \fB\-\-socket\-exists\fP |
| 998 |
Matches if the packet is associated with a socket. |
| 999 |
.SS physdev |
| 1000 |
This module matches on the bridge port input and output devices enslaved |
| 1001 |
to a bridge device. This module is a part of the infrastructure that enables |
| 1002 |
a transparent bridging IP firewall and is only useful for kernel versions |
| 1003 |
above version 2.5.44. |
| 1004 |
.TP |
| 1005 |
[\fB!\fP] \fB\-\-physdev\-in\fP \fIname\fP |
| 1006 |
Name of a bridge port via which a packet is received (only for |
| 1007 |
packets entering the |
| 1008 |
.BR INPUT , |
| 1009 |
.B FORWARD |
| 1010 |
and |
| 1011 |
.B PREROUTING |
| 1012 |
chains). If the interface name ends in a "+", then any |
| 1013 |
interface which begins with this name will match. If the packet didn't arrive |
| 1014 |
through a bridge device, this packet won't match this option, unless '!' is used. |
| 1015 |
.TP |
| 1016 |
[\fB!\fP] \fB\-\-physdev\-out\fP \fIname\fP |
| 1017 |
Name of a bridge port via which a packet is going to be sent (for bridged packets |
| 1018 |
entering the |
| 1019 |
.BR FORWARD |
| 1020 |
and |
| 1021 |
.B POSTROUTING |
| 1022 |
chains). If the interface name ends in a "+", then any |
| 1023 |
interface which begins with this name will match. |
| 1024 |
.TP |
| 1025 |
[\fB!\fP] \fB\-\-physdev\-is\-in\fP |
| 1026 |
Matches if the packet has entered through a bridge interface. |
| 1027 |
.TP |
| 1028 |
[\fB!\fP] \fB\-\-physdev\-is\-out\fP |
| 1029 |
Matches if the packet will leave through a bridge interface. |
| 1030 |
.TP |
| 1031 |
[\fB!\fP] \fB\-\-physdev\-is\-bridged\fP |
| 1032 |
Matches if the packet is being bridged and therefore is not being routed. |
| 1033 |
This is only useful in the FORWARD and POSTROUTING chains. |
| 1034 |
.SS pkttype |
| 1035 |
This module matches the link-layer packet type. |
| 1036 |
.TP |
| 1037 |
[\fB!\fP] \fB\-\-pkt\-type\fP {\fBunicast\fP|\fBbroadcast\fP|\fBmulticast\fP} |
| 1038 |
.SS policy |
| 1039 |
This module matches the policy used by IPsec for handling a packet. |
| 1040 |
.TP |
| 1041 |
\fB\-\-dir\fP {\fBin\fP|\fBout\fP} |
| 1042 |
Used to select whether to match the policy used for decapsulation or the |
| 1043 |
policy that will be used for encapsulation. |
| 1044 |
.B in |
| 1045 |
is valid in the |
| 1046 |
.B PREROUTING, INPUT and FORWARD |
| 1047 |
chains, |
| 1048 |
.B out |
| 1049 |
is valid in the |
| 1050 |
.B POSTROUTING, OUTPUT and FORWARD |
| 1051 |
chains. |
| 1052 |
.TP |
| 1053 |
\fB\-\-pol\fP {\fBnone\fP|\fBipsec\fP} |
| 1054 |
Matches if the packet is subject to IPsec processing. \fB\-\-pol none\fP |
| 1055 |
cannot be combined with \fB\-\-strict\fP. |
| 1056 |
.TP |
| 1057 |
\fB\-\-strict\fP |
| 1058 |
Selects whether to match the exact policy or match if any rule of |
| 1059 |
the policy matches the given policy. |
| 1060 |
.PP |
| 1061 |
For each policy element that is to be described, one can use one or more of |
| 1062 |
the following options. When \fB\-\-strict\fP is in effect, at least one must be |
| 1063 |
used per element. |
| 1064 |
.TP |
| 1065 |
[\fB!\fP] \fB\-\-reqid\fP \fIid\fP |
| 1066 |
Matches the reqid of the policy rule. The reqid can be specified with |
| 1067 |
.B setkey(8) |
| 1068 |
using |
| 1069 |
.B unique:id |
| 1070 |
as level. |
| 1071 |
.TP |
| 1072 |
[\fB!\fP] \fB\-\-spi\fP \fIspi\fP |
| 1073 |
Matches the SPI of the SA. |
| 1074 |
.TP |
| 1075 |
[\fB!\fP] \fB\-\-proto\fP {\fBah\fP|\fBesp\fP|\fBipcomp\fP} |
| 1076 |
Matches the encapsulation protocol. |
| 1077 |
.TP |
| 1078 |
[\fB!\fP] \fB\-\-mode\fP {\fBtunnel\fP|\fBtransport\fP} |
| 1079 |
Matches the encapsulation mode. |
| 1080 |
.TP |
| 1081 |
[\fB!\fP] \fB\-\-tunnel\-src\fP \fIaddr\fP[\fB/\fP\fImask\fP] |
| 1082 |
Matches the source end-point address of a tunnel mode SA. |
| 1083 |
Only valid with \fB\-\-mode tunnel\fP. |
| 1084 |
.TP |
| 1085 |
[\fB!\fP] \fB\-\-tunnel\-dst\fP \fIaddr\fP[\fB/\fP\fImask\fP] |
| 1086 |
Matches the destination end-point address of a tunnel mode SA. |
| 1087 |
Only valid with \fB\-\-mode tunnel\fP. |
| 1088 |
.TP |
| 1089 |
\fB\-\-next\fP |
| 1090 |
Start the next element in the policy specification. Can only be used with |
| 1091 |
\fB\-\-strict\fP. |
| 1092 |
.SS quota |
| 1093 |
Implements network quotas by decrementing a byte counter with each |
| 1094 |
packet. The condition matches until the byte counter reaches zero. Behavior |
| 1095 |
is reversed with negation (i.e. the condition does not match until the |
| 1096 |
byte counter reaches zero). |
| 1097 |
.TP |
| 1098 |
[\fB!\fP] \fB\-\-quota\fP \fIbytes\fP |
| 1099 |
The quota in bytes. |
| 1100 |
.SS rateest |
| 1101 |
The rate estimator can match on estimated rates as collected by the RATEEST |
| 1102 |
target. It supports matching on absolute bps/pps values, comparing two rate |
| 1103 |
estimators and matching on the difference between two rate estimators. |
| 1104 |
.PP |
| 1105 |
For a better understanding of the available options, these are all possible |
| 1106 |
combinations: |
| 1107 |
.TP |
| 1108 |
Absolute: |
| 1109 |
.IP \(bu 4 |
| 1110 |
\fBrateest\fP \fIoperator\fP \fBrateest-bps\fP |
| 1111 |
.IP \(bu 4 |
| 1112 |
\fBrateest\fP \fIoperator\fP \fBrateest-pps\fP |
| 1113 |
.TP |
| 1114 |
Absolute + Delta: |
| 1115 |
.IP \(bu 4 |
| 1116 |
(\fBrateest\fP minus \fBrateest-bps1\fP) \fIoperator\fP \fBrateest-bps2\fP |
| 1117 |
.IP \(bu 4 |
| 1118 |
(\fBrateest\fP minus \fBrateest-pps1\fP) \fIoperator\fP \fBrateest-pps2\fP |
| 1119 |
.TP |
| 1120 |
Relative: |
| 1121 |
.IP \(bu 4 |
| 1122 |
\fBrateest1\fP \fIoperator\fP \fBrateest2\fP \fBrateest-bps\fP(without rate!) |
| 1123 |
.IP \(bu 4 |
| 1124 |
\fBrateest1\fP \fIoperator\fP \fBrateest2\fP \fBrateest-pps\fP(without rate!) |
| 1125 |
.TP |
| 1126 |
Relative + Delta: |
| 1127 |
.IP \(bu 4 |
| 1128 |
(\fBrateest1\fP minus \fBrateest-bps1\fP) \fIoperator\fP |
| 1129 |
(\fBrateest2\fP minus \fBrateest-bps2\fP) |
| 1130 |
.IP \(bu 4 |
| 1131 |
(\fBrateest1\fP minus \fBrateest-pps1\fP) \fIoperator\fP |
| 1132 |
(\fBrateest2\fP minus \fBrateest-pps2\fP) |
| 1133 |
.TP |
| 1134 |
\fB\-\-rateest\-delta\fP |
| 1135 |
For each estimator (either absolute or relative mode), calculate the difference |
| 1136 |
between the estimator-determined flow rate and the static value chosen with the |
| 1137 |
BPS/PPS options. If the flow rate is higher than the specified BPS/PPS, 0 will |
| 1138 |
be used instead of a negative value. In other words, "max(0, rateest#_rate \- |
| 1139 |
rateest#_bps)" is used. |
| 1140 |
.TP |
| 1141 |
[\fB!\fP] \fB\-\-rateest\-lt\fP |
| 1142 |
Match if rate is less than given rate/estimator. |
| 1143 |
.TP |
| 1144 |
[\fB!\fP] \fB\-\-rateest\-gt\fP |
| 1145 |
Match if rate is greater than given rate/estimator. |
| 1146 |
.TP |
| 1147 |
[\fB!\fP] \fB\-\-rateest\-eq\fP |
| 1148 |
Match if rate is equal to given rate/estimator. |
| 1149 |
.PP |
| 1150 |
In the so-called "absolute mode", only one rate estimator is used and compared |
| 1151 |
against a static value, while in "relative mode", two rate estimators are |
| 1152 |
compared against another. |
| 1153 |
.TP |
| 1154 |
\fB\-\-rateest\fP \fIname\fP |
| 1155 |
Name of the one rate estimator for absolute mode. |
| 1156 |
.TP |
| 1157 |
\fB\-\-rateest1\fP \fIname\fP |
| 1158 |
.TP |
| 1159 |
\fB\-\-rateest2\fP \fIname\fP |
| 1160 |
The names of the two rate estimators for relative mode. |
| 1161 |
.TP |
| 1162 |
\fB\-\-rateest\-bps\fP [\fIvalue\fP] |
| 1163 |
.TP |
| 1164 |
\fB\-\-rateest\-pps\fP [\fIvalue\fP] |
| 1165 |
.TP |
| 1166 |
\fB\-\-rateest\-bps1\fP [\fIvalue\fP] |
| 1167 |
.TP |
| 1168 |
\fB\-\-rateest\-bps2\fP [\fIvalue\fP] |
| 1169 |
.TP |
| 1170 |
\fB\-\-rateest\-pps1\fP [\fIvalue\fP] |
| 1171 |
.TP |
| 1172 |
\fB\-\-rateest\-pps2\fP [\fIvalue\fP] |
| 1173 |
Compare the estimator(s) by bytes or packets per second, and compare against |
| 1174 |
the chosen value. See the above bullet list for which option is to be used in |
| 1175 |
which case. A unit suffix may be used \(em available ones are: bit, [kmgt]bit, |
| 1176 |
[KMGT]ibit, Bps, [KMGT]Bps, [KMGT]iBps. |
| 1177 |
.PP |
| 1178 |
Example: This is what can be used to route outgoing data connections from an |
| 1179 |
FTP server over two lines based on the available bandwidth at the time the data |
| 1180 |
connection was started: |
| 1181 |
.PP |
| 1182 |
# Estimate outgoing rates |
| 1183 |
.PP |
| 1184 |
iptables \-t mangle \-A POSTROUTING \-o eth0 \-j RATEEST \-\-rateest\-name eth0 |
| 1185 |
\-\-rateest\-interval 250ms \-\-rateest\-ewma 0.5s |
| 1186 |
.PP |
| 1187 |
iptables \-t mangle \-A POSTROUTING \-o ppp0 \-j RATEEST \-\-rateest\-name ppp0 |
| 1188 |
\-\-rateest\-interval 250ms \-\-rateest\-ewma 0.5s |
| 1189 |
.PP |
| 1190 |
# Mark based on available bandwidth |
| 1191 |
.PP |
| 1192 |
iptables \-t mangle \-A balance \-m conntrack \-\-ctstate NEW \-m helper \-\-helper ftp |
| 1193 |
\-m rateest \-\-rateest\-delta \-\-rateest1 eth0 \-\-rateest\-bps1 2.5mbit \-\-rateest\-gt |
| 1194 |
\-\-rateest2 ppp0 \-\-rateest\-bps2 2mbit \-j CONNMARK \-\-set\-mark 1 |
| 1195 |
.PP |
| 1196 |
iptables \-t mangle \-A balance \-m conntrack \-\-ctstate NEW \-m helper \-\-helper ftp |
| 1197 |
\-m rateest \-\-rateest\-delta \-\-rateest1 ppp0 \-\-rateest\-bps1 2mbit \-\-rateest\-gt |
| 1198 |
\-\-rateest2 eth0 \-\-rateest\-bps2 2.5mbit \-j CONNMARK \-\-set\-mark 2 |
| 1199 |
.PP |
| 1200 |
iptables \-t mangle \-A balance \-j CONNMARK \-\-restore\-mark |
| 1201 |
.SS realm (IPv4-specific) |
| 1202 |
This matches the routing realm. Routing realms are used in complex routing |
| 1203 |
setups involving dynamic routing protocols like BGP. |
| 1204 |
.TP |
| 1205 |
[\fB!\fP] \fB\-\-realm\fP \fIvalue\fP[\fB/\fP\fImask\fP] |
| 1206 |
Matches a given realm number (and optionally mask). If not a number, value |
| 1207 |
can be a named realm from /etc/iproute2/rt_realms (mask can not be used in |
| 1208 |
that case). |
| 1209 |
Both value and mask are four byte unsigned integers and may be specified in |
| 1210 |
decimal, hex (by prefixing with "0x") or octal (if a leading zero is given). |
| 1211 |
.SS recent |
| 1212 |
Allows you to dynamically create a list of IP addresses and then match against |
| 1213 |
that list in a few different ways. |
| 1214 |
.PP |
| 1215 |
For example, you can create a "badguy" list out of people attempting to connect |
| 1216 |
to port 139 on your firewall and then DROP all future packets from them without |
| 1217 |
considering them. |
| 1218 |
.PP |
| 1219 |
\fB\-\-set\fP, \fB\-\-rcheck\fP, \fB\-\-update\fP and \fB\-\-remove\fP are |
| 1220 |
mutually exclusive. |
| 1221 |
.TP |
| 1222 |
\fB\-\-name\fP \fIname\fP |
| 1223 |
Specify the list to use for the commands. If no name is given then |
| 1224 |
\fBDEFAULT\fP will be used. |
| 1225 |
.TP |
| 1226 |
[\fB!\fP] \fB\-\-set\fP |
| 1227 |
This will add the source address of the packet to the list. If the source |
| 1228 |
address is already in the list, this will update the existing entry. This will |
| 1229 |
always return success (or failure if \fB!\fP is passed in). |
| 1230 |
.TP |
| 1231 |
\fB\-\-rsource\fP |
| 1232 |
Match/save the source address of each packet in the recent list table. This |
| 1233 |
is the default. |
| 1234 |
.TP |
| 1235 |
\fB\-\-rdest\fP |
| 1236 |
Match/save the destination address of each packet in the recent list table. |
| 1237 |
.TP |
| 1238 |
\fB\-\-mask\fP \fInetmask\fP |
| 1239 |
Netmask that will be applied to this recent list. |
| 1240 |
.TP |
| 1241 |
[\fB!\fP] \fB\-\-rcheck\fP |
| 1242 |
Check if the source address of the packet is currently in the list. |
| 1243 |
.TP |
| 1244 |
[\fB!\fP] \fB\-\-update\fP |
| 1245 |
Like \fB\-\-rcheck\fP, except it will update the "last seen" timestamp if it |
| 1246 |
matches. |
| 1247 |
.TP |
| 1248 |
[\fB!\fP] \fB\-\-remove\fP |
| 1249 |
Check if the source address of the packet is currently in the list and if so |
| 1250 |
that address will be removed from the list and the rule will return true. If |
| 1251 |
the address is not found, false is returned. |
| 1252 |
.TP |
| 1253 |
\fB\-\-seconds\fP \fIseconds\fP |
| 1254 |
This option must be used in conjunction with one of \fB\-\-rcheck\fP or |
| 1255 |
\fB\-\-update\fP. When used, this will narrow the match to only happen when the |
| 1256 |
address is in the list and was seen within the last given number of seconds. |
| 1257 |
.TP |
| 1258 |
\fB\-\-reap\fP |
| 1259 |
This option can only be used in conjunction with \fB\-\-seconds\fP. |
| 1260 |
When used, this will cause entries older than the last given number of seconds |
| 1261 |
to be purged. |
| 1262 |
.TP |
| 1263 |
\fB\-\-hitcount\fP \fIhits\fP |
| 1264 |
This option must be used in conjunction with one of \fB\-\-rcheck\fP or |
| 1265 |
\fB\-\-update\fP. When used, this will narrow the match to only happen when the |
| 1266 |
address is in the list and packets had been received greater than or equal to |
| 1267 |
the given value. This option may be used along with \fB\-\-seconds\fP to create |
| 1268 |
an even narrower match requiring a certain number of hits within a specific |
| 1269 |
time frame. |
| 1270 |
.TP |
| 1271 |
\fB\-\-rttl\fP |
| 1272 |
This option may only be used in conjunction with one of \fB\-\-rcheck\fP or |
| 1273 |
\fB\-\-update\fP. When used, this will narrow the match to only happen when the |
| 1274 |
address is in the list and the TTL of the current packet matches that of the |
| 1275 |
packet which hit the \fB\-\-set\fP rule. This may be useful if you have problems |
| 1276 |
with people faking their source address in order to DoS you via this module by |
| 1277 |
disallowing others access to your site by sending bogus packets to you. |
| 1278 |
.PP |
| 1279 |
Examples: |
| 1280 |
.IP |
| 1281 |
iptables \-A FORWARD \-m recent \-\-name badguy \-\-rcheck \-\-seconds 60 \-j DROP |
| 1282 |
.IP |
| 1283 |
iptables \-A FORWARD \-p tcp \-i eth0 \-\-dport 139 \-m recent \-\-name badguy \-\-set \-j DROP |
| 1284 |
.PP |
| 1285 |
\fB/proc/net/xt_recent/*\fP are the current lists of addresses and information |
| 1286 |
about each entry of each list. |
| 1287 |
.PP |
| 1288 |
Each file in \fB/proc/net/xt_recent/\fP can be read from to see the current |
| 1289 |
list or written two using the following commands to modify the list: |
| 1290 |
.TP |
| 1291 |
\fBecho +\fP\fIaddr\fP\fB >/proc/net/xt_recent/DEFAULT\fP |
| 1292 |
to add \fIaddr\fP to the DEFAULT list |
| 1293 |
.TP |
| 1294 |
\fBecho \-\fP\fIaddr\fP\fB >/proc/net/xt_recent/DEFAULT\fP |
| 1295 |
to remove \fIaddr\fP from the DEFAULT list |
| 1296 |
.TP |
| 1297 |
\fBecho / >/proc/net/xt_recent/DEFAULT\fP |
| 1298 |
to flush the DEFAULT list (remove all entries). |
| 1299 |
.PP |
| 1300 |
The module itself accepts parameters, defaults shown: |
| 1301 |
.TP |
| 1302 |
\fBip_list_tot\fP=\fI100\fP |
| 1303 |
Number of addresses remembered per table. |
| 1304 |
.TP |
| 1305 |
\fBip_pkt_list_tot\fP=\fI0\fP |
| 1306 |
Number of packets per address remembered. This parameter is obsolete since |
| 1307 |
kernel version 3.19 which started to calculate the table size based on given |
| 1308 |
\fB\-\-hitcount\fP parameter. |
| 1309 |
.TP |
| 1310 |
\fBip_list_hash_size\fP=\fI0\fP |
| 1311 |
Hash table size. 0 means to calculate it based on ip_list_tot by rounding it up |
| 1312 |
to the next power of two (with \fBip_list_tot\fP defaulting to \fI100\fP, |
| 1313 |
\fBip_list_hash_size\fP will calculate to \fI128\fP by default). |
| 1314 |
.TP |
| 1315 |
\fBip_list_perms\fP=\fI0644\fP |
| 1316 |
Permissions for /proc/net/xt_recent/* files. |
| 1317 |
.TP |
| 1318 |
\fBip_list_uid\fP=\fI0\fP |
| 1319 |
Numerical UID for ownership of /proc/net/xt_recent/* files. |
| 1320 |
.TP |
| 1321 |
\fBip_list_gid\fP=\fI0\fP |
| 1322 |
Numerical GID for ownership of /proc/net/xt_recent/* files. |
| 1323 |
.SS rpfilter |
| 1324 |
Performs a reverse path filter test on a packet. |
| 1325 |
If a reply to the packet would be sent via the same interface |
| 1326 |
that the packet arrived on, the packet will match. |
| 1327 |
Note that, unlike the in-kernel rp_filter, packets protected |
| 1328 |
by IPSec are not treated specially. Combine this match with |
| 1329 |
the policy match if you want this. |
| 1330 |
Also, packets arriving via the loopback interface are always permitted. |
| 1331 |
This match can only be used in the PREROUTING chain of the raw or mangle table. |
| 1332 |
.TP |
| 1333 |
\fB\-\-loose\fP |
| 1334 |
Used to specify that the reverse path filter test should match |
| 1335 |
even if the selected output device is not the expected one. |
| 1336 |
.TP |
| 1337 |
\fB\-\-validmark\fP |
| 1338 |
Also use the packets' nfmark value when performing the reverse path route lookup. |
| 1339 |
.TP |
| 1340 |
\fB\-\-accept\-local\fP |
| 1341 |
This will permit packets arriving from the network with a source address that is also |
| 1342 |
assigned to the local machine. |
| 1343 |
.TP |
| 1344 |
\fB\-\-invert\fP |
| 1345 |
This will invert the sense of the match. Instead of matching packets that passed the |
| 1346 |
reverse path filter test, match those that have failed it. |
| 1347 |
.PP |
| 1348 |
Example to log and drop packets failing the reverse path filter test: |
| 1349 |
|
| 1350 |
iptables \-t raw \-N RPFILTER |
| 1351 |
|
| 1352 |
iptables \-t raw \-A RPFILTER \-m rpfilter \-j RETURN |
| 1353 |
|
| 1354 |
iptables \-t raw \-A RPFILTER \-m limit \-\-limit 10/minute \-j NFLOG \-\-nflog\-prefix "rpfilter drop" |
| 1355 |
|
| 1356 |
iptables \-t raw \-A RPFILTER \-j DROP |
| 1357 |
|
| 1358 |
iptables \-t raw \-A PREROUTING \-j RPFILTER |
| 1359 |
|
| 1360 |
Example to drop failed packets, without logging: |
| 1361 |
|
| 1362 |
iptables \-t raw \-A RPFILTER \-m rpfilter \-\-invert \-j DROP |
| 1363 |
.SS rt (IPv6-specific) |
| 1364 |
Match on IPv6 routing header |
| 1365 |
.TP |
| 1366 |
[\fB!\fP] \fB\-\-rt\-type\fP \fItype\fP |
| 1367 |
Match the type (numeric). |
| 1368 |
.TP |
| 1369 |
[\fB!\fP] \fB\-\-rt\-segsleft\fP \fInum\fP[\fB:\fP\fInum\fP] |
| 1370 |
Match the `segments left' field (range). |
| 1371 |
.TP |
| 1372 |
[\fB!\fP] \fB\-\-rt\-len\fP \fIlength\fP |
| 1373 |
Match the length of this header. |
| 1374 |
.TP |
| 1375 |
\fB\-\-rt\-0\-res\fP |
| 1376 |
Match the reserved field, too (type=0) |
| 1377 |
.TP |
| 1378 |
\fB\-\-rt\-0\-addrs\fP \fIaddr\fP[\fB,\fP\fIaddr\fP...] |
| 1379 |
Match type=0 addresses (list). |
| 1380 |
.TP |
| 1381 |
\fB\-\-rt\-0\-not\-strict\fP |
| 1382 |
List of type=0 addresses is not a strict list. |
| 1383 |
.SS sctp |
| 1384 |
This module matches Stream Control Transmission Protocol headers. |
| 1385 |
.TP |
| 1386 |
[\fB!\fP] \fB\-\-source\-port\fP,\fB\-\-sport\fP \fIport\fP[\fB:\fP\fIport\fP] |
| 1387 |
.TP |
| 1388 |
[\fB!\fP] \fB\-\-destination\-port\fP,\fB\-\-dport\fP \fIport\fP[\fB:\fP\fIport\fP] |
| 1389 |
.TP |
| 1390 |
[\fB!\fP] \fB\-\-chunk\-types\fP {\fBall\fP|\fBany\fP|\fBonly\fP} \fIchunktype\fP[\fB:\fP\fIflags\fP] [...] |
| 1391 |
The flag letter in upper case indicates that the flag is to match if set, |
| 1392 |
in the lower case indicates to match if unset. |
| 1393 |
|
| 1394 |
Match types: |
| 1395 |
.TP |
| 1396 |
all |
| 1397 |
Match if all given chunk types are present and flags match. |
| 1398 |
.TP |
| 1399 |
any |
| 1400 |
Match if any of the given chunk types is present with given flags. |
| 1401 |
.TP |
| 1402 |
only |
| 1403 |
Match if only the given chunk types are present with given flags and none are missing. |
| 1404 |
|
| 1405 |
Chunk types: DATA INIT INIT_ACK SACK HEARTBEAT HEARTBEAT_ACK ABORT SHUTDOWN SHUTDOWN_ACK ERROR COOKIE_ECHO COOKIE_ACK ECN_ECNE ECN_CWR SHUTDOWN_COMPLETE I_DATA RE_CONFIG PAD ASCONF ASCONF_ACK FORWARD_TSN I_FORWARD_TSN |
| 1406 |
|
| 1407 |
chunk type available flags |
| 1408 |
.br |
| 1409 |
DATA I U B E i u b e |
| 1410 |
.br |
| 1411 |
I_DATA I U B E i u b e |
| 1412 |
.br |
| 1413 |
ABORT T t |
| 1414 |
.br |
| 1415 |
SHUTDOWN_COMPLETE T t |
| 1416 |
|
| 1417 |
(lowercase means flag should be "off", uppercase means "on") |
| 1418 |
.P |
| 1419 |
Examples: |
| 1420 |
|
| 1421 |
iptables \-A INPUT \-p sctp \-\-dport 80 \-j DROP |
| 1422 |
|
| 1423 |
iptables \-A INPUT \-p sctp \-\-chunk\-types any DATA,INIT \-j DROP |
| 1424 |
|
| 1425 |
iptables \-A INPUT \-p sctp \-\-chunk\-types any DATA:Be \-j ACCEPT |
| 1426 |
.SS set |
| 1427 |
This module matches IP sets which can be defined by ipset(8). |
| 1428 |
.TP |
| 1429 |
[\fB!\fP] \fB\-\-match\-set\fP \fIsetname\fP \fIflag\fP[\fB,\fP\fIflag\fP]... |
| 1430 |
where flags are the comma separated list of |
| 1431 |
.BR "src" |
| 1432 |
and/or |
| 1433 |
.BR "dst" |
| 1434 |
specifications and there can be no more than six of them. Hence the command |
| 1435 |
.IP |
| 1436 |
iptables \-A FORWARD \-m set \-\-match\-set test src,dst |
| 1437 |
.IP |
| 1438 |
will match packets, for which (if the set type is ipportmap) the source |
| 1439 |
address and destination port pair can be found in the specified set. If |
| 1440 |
the set type of the specified set is single dimension (for example ipmap), |
| 1441 |
then the command will match packets for which the source address can be |
| 1442 |
found in the specified set. |
| 1443 |
.TP |
| 1444 |
\fB\-\-return\-nomatch\fP |
| 1445 |
If the \fB\-\-return\-nomatch\fP option is specified and the set type |
| 1446 |
supports the \fBnomatch\fP flag, then the matching is reversed: a match |
| 1447 |
with an element flagged with \fBnomatch\fP returns \fBtrue\fP, while a |
| 1448 |
match with a plain element returns \fBfalse\fP. |
| 1449 |
.TP |
| 1450 |
\fB!\fP \fB\-\-update\-counters\fP |
| 1451 |
If the \fB\-\-update\-counters\fP flag is negated, then the packet and |
| 1452 |
byte counters of the matching element in the set won't be updated. Default |
| 1453 |
the packet and byte counters are updated. |
| 1454 |
.TP |
| 1455 |
\fB!\fP \fB\-\-update\-subcounters\fP |
| 1456 |
If the \fB\-\-update\-subcounters\fP flag is negated, then the packet and |
| 1457 |
byte counters of the matching element in the member set of a list type of |
| 1458 |
set won't be updated. Default the packet and byte counters are updated. |
| 1459 |
.TP |
| 1460 |
[\fB!\fP] \fB\-\-packets\-eq\fP \fIvalue\fP |
| 1461 |
If the packet is matched an element in the set, match only if the |
| 1462 |
packet counter of the element matches the given value too. |
| 1463 |
.TP |
| 1464 |
\fB\-\-packets\-lt\fP \fIvalue\fP |
| 1465 |
If the packet is matched an element in the set, match only if the |
| 1466 |
packet counter of the element is less than the given value as well. |
| 1467 |
.TP |
| 1468 |
\fB\-\-packets\-gt\fP \fIvalue\fP |
| 1469 |
If the packet is matched an element in the set, match only if the |
| 1470 |
packet counter of the element is greater than the given value as well. |
| 1471 |
.TP |
| 1472 |
[\fB!\fP] \fB\-\-bytes\-eq\fP \fIvalue\fP |
| 1473 |
If the packet is matched an element in the set, match only if the |
| 1474 |
byte counter of the element matches the given value too. |
| 1475 |
.TP |
| 1476 |
\fB\-\-bytes\-lt\fP \fIvalue\fP |
| 1477 |
If the packet is matched an element in the set, match only if the |
| 1478 |
byte counter of the element is less than the given value as well. |
| 1479 |
.TP |
| 1480 |
\fB\-\-bytes\-gt\fP \fIvalue\fP |
| 1481 |
If the packet is matched an element in the set, match only if the |
| 1482 |
byte counter of the element is greater than the given value as well. |
| 1483 |
.PP |
| 1484 |
The packet and byte counters related options and flags are ignored |
| 1485 |
when the set was defined without counter support. |
| 1486 |
.PP |
| 1487 |
The option \fB\-\-match\-set\fP can be replaced by \fB\-\-set\fP if that does |
| 1488 |
not clash with an option of other extensions. |
| 1489 |
.PP |
| 1490 |
Use of \-m set requires that ipset kernel support is provided, which, for |
| 1491 |
standard kernels, is the case since Linux 2.6.39. |
| 1492 |
.SS socket |
| 1493 |
This matches if an open TCP/UDP socket can be found by doing a socket lookup on the |
| 1494 |
packet. It matches if there is an established or non\-zero bound listening |
| 1495 |
socket (possibly with a non\-local address). The lookup is performed using |
| 1496 |
the \fBpacket\fP tuple of TCP/UDP packets, or the original TCP/UDP header |
| 1497 |
\fBembedded\fP in an ICMP/ICPMv6 error packet. |
| 1498 |
.TP |
| 1499 |
\fB\-\-transparent\fP |
| 1500 |
Ignore non-transparent sockets. |
| 1501 |
.TP |
| 1502 |
\fB\-\-nowildcard\fP |
| 1503 |
Do not ignore sockets bound to 'any' address. |
| 1504 |
The socket match won't accept zero\-bound listeners by default, since |
| 1505 |
then local services could intercept traffic that would otherwise be forwarded. |
| 1506 |
This option therefore has security implications when used to match traffic being |
| 1507 |
forwarded to redirect such packets to local machine with policy routing. |
| 1508 |
When using the socket match to implement fully transparent |
| 1509 |
proxies bound to non\-local addresses it is recommended to use the \-\-transparent |
| 1510 |
option instead. |
| 1511 |
.PP |
| 1512 |
Example (assuming packets with mark 1 are delivered locally): |
| 1513 |
.IP |
| 1514 |
\-t mangle \-A PREROUTING \-m socket \-\-transparent \-j MARK \-\-set\-mark 1 |
| 1515 |
.TP |
| 1516 |
\fB\-\-restore\-skmark\fP |
| 1517 |
Set the packet mark to the matching socket's mark. Can be combined with the |
| 1518 |
\fB\-\-transparent\fP and \fB\-\-nowildcard\fP options to restrict the sockets |
| 1519 |
to be matched when restoring the packet mark. |
| 1520 |
.PP |
| 1521 |
Example: An application opens 2 transparent (\fBIP_TRANSPARENT\fP) sockets and |
| 1522 |
sets a mark on them with \fBSO_MARK\fP socket option. We can filter matching packets: |
| 1523 |
.IP |
| 1524 |
\-t mangle \-I PREROUTING \-m socket \-\-transparent \-\-restore\-skmark \-j action |
| 1525 |
.IP |
| 1526 |
\-t mangle \-A action \-m mark \-\-mark 10 \-j action2 |
| 1527 |
.IP |
| 1528 |
\-t mangle \-A action \-m mark \-\-mark 11 \-j action3 |
| 1529 |
.SS state |
| 1530 |
The "state" extension is a subset of the "conntrack" module. |
| 1531 |
"state" allows access to the connection tracking state for this packet. |
| 1532 |
.TP |
| 1533 |
[\fB!\fP] \fB\-\-state\fP \fIstate\fP |
| 1534 |
Where state is a comma separated list of the connection states to match. Only a |
| 1535 |
subset of the states unterstood by "conntrack" are recognized: \fBINVALID\fP, |
| 1536 |
\fBESTABLISHED\fP, \fBNEW\fP, \fBRELATED\fP or \fBUNTRACKED\fP. For their |
| 1537 |
description, see the "conntrack" heading in this manpage. |
| 1538 |
.SS statistic |
| 1539 |
This module matches packets based on some statistic condition. |
| 1540 |
It supports two distinct modes settable with the |
| 1541 |
\fB\-\-mode\fP |
| 1542 |
option. |
| 1543 |
.PP |
| 1544 |
Supported options: |
| 1545 |
.TP |
| 1546 |
\fB\-\-mode\fP \fImode\fP |
| 1547 |
Set the matching mode of the matching rule, supported modes are |
| 1548 |
.B random |
| 1549 |
and |
| 1550 |
.B nth. |
| 1551 |
.TP |
| 1552 |
[\fB!\fP] \fB\-\-probability\fP \fIp\fP |
| 1553 |
Set the probability for a packet to be randomly matched. It only works with the |
| 1554 |
\fBrandom\fP mode. \fIp\fP must be within 0.0 and 1.0. The supported |
| 1555 |
granularity is in 1/2147483648th increments. |
| 1556 |
.TP |
| 1557 |
[\fB!\fP] \fB\-\-every\fP \fIn\fP |
| 1558 |
Match one packet every nth packet. It works only with the |
| 1559 |
.B nth |
| 1560 |
mode (see also the |
| 1561 |
\fB\-\-packet\fP |
| 1562 |
option). |
| 1563 |
.TP |
| 1564 |
\fB\-\-packet\fP \fIp\fP |
| 1565 |
Set the initial counter value (0 <= p <= n\-1, default 0) for the |
| 1566 |
.B nth |
| 1567 |
mode. |
| 1568 |
.SS string |
| 1569 |
This module matches a given string by using some pattern matching strategy. It requires a linux kernel >= 2.6.14. |
| 1570 |
.TP |
| 1571 |
\fB\-\-algo\fP {\fBbm\fP|\fBkmp\fP} |
| 1572 |
Select the pattern matching strategy. (bm = Boyer-Moore, kmp = Knuth-Pratt-Morris) |
| 1573 |
.TP |
| 1574 |
\fB\-\-from\fP \fIoffset\fP |
| 1575 |
Set the offset from which it starts looking for any matching. If not passed, default is 0. |
| 1576 |
.TP |
| 1577 |
\fB\-\-to\fP \fIoffset\fP |
| 1578 |
Set the offset up to which should be scanned. That is, byte \fIoffset\fP |
| 1579 |
(counting from 0) is the last one that is scanned and the maximum position of |
| 1580 |
\fIpattern\fP's last character. |
| 1581 |
If not passed, default is the packet size. |
| 1582 |
.TP |
| 1583 |
[\fB!\fP] \fB\-\-string\fP \fIpattern\fP |
| 1584 |
Matches the given pattern. |
| 1585 |
.TP |
| 1586 |
[\fB!\fP] \fB\-\-hex\-string\fP \fIpattern\fP |
| 1587 |
Matches the given pattern in hex notation. |
| 1588 |
.TP |
| 1589 |
\fB\-\-icase\fP |
| 1590 |
Ignore case when searching. |
| 1591 |
.TP |
| 1592 |
Examples: |
| 1593 |
.IP |
| 1594 |
# The string pattern can be used for simple text characters. |
| 1595 |
.br |
| 1596 |
iptables \-A INPUT \-p tcp \-\-dport 80 \-m string \-\-algo bm \-\-string 'GET /index.html' \-j LOG |
| 1597 |
.IP |
| 1598 |
# The hex string pattern can be used for non-printable characters, like |0D 0A| or |0D0A|. |
| 1599 |
.br |
| 1600 |
iptables \-p udp \-\-dport 53 \-m string \-\-algo bm \-\-from 40 \-\-to 57 \-\-hex\-string '|03|www|09|netfilter|03|org|00|' |
| 1601 |
.P |
| 1602 |
Note: Since Boyer-Moore (BM) performs searches for matches from right to left and |
| 1603 |
the kernel may store a packet in multiple discontiguous blocks, it's possible |
| 1604 |
that a match could be spread over multiple blocks, in which case this algorithm |
| 1605 |
won't find it. |
| 1606 |
.P |
| 1607 |
If you wish to ensure that such thing won't ever happen, use the |
| 1608 |
Knuth-Pratt-Morris (KMP) algorithm instead. In conclusion, choose the proper |
| 1609 |
string search algorithm depending on your use-case. |
| 1610 |
.P |
| 1611 |
For example, if you're using the module for filtering, NIDS or any similar |
| 1612 |
security-focused purpose, then choose KMP. On the other hand, if you really care |
| 1613 |
about performance \(em for example, you're classifying packets to apply Quality |
| 1614 |
of Service (QoS) policies \(em and you don't mind about missing possible matches |
| 1615 |
spread over multiple fragments, then choose BM. |
| 1616 |
.SS tcp |
| 1617 |
These extensions can be used if `\-\-protocol tcp' is specified. It |
| 1618 |
provides the following options: |
| 1619 |
.TP |
| 1620 |
[\fB!\fP] \fB\-\-source\-port\fP,\fB\-\-sport\fP \fIport\fP[\fB:\fP\fIport\fP] |
| 1621 |
Source port or port range specification. This can either be a service |
| 1622 |
name or a port number. An inclusive range can also be specified, |
| 1623 |
using the format \fIfirst\fP\fB:\fP\fIlast\fP. |
| 1624 |
If the first port is omitted, "0" is assumed; if the last is omitted, |
| 1625 |
"65535" is assumed. |
| 1626 |
The flag |
| 1627 |
\fB\-\-sport\fP |
| 1628 |
is a convenient alias for this option. |
| 1629 |
.TP |
| 1630 |
[\fB!\fP] \fB\-\-destination\-port\fP,\fB\-\-dport\fP \fIport\fP[\fB:\fP\fIport\fP] |
| 1631 |
Destination port or port range specification. The flag |
| 1632 |
\fB\-\-dport\fP |
| 1633 |
is a convenient alias for this option. |
| 1634 |
.TP |
| 1635 |
[\fB!\fP] \fB\-\-tcp\-flags\fP \fImask\fP \fIcomp\fP |
| 1636 |
Match when the TCP flags are as specified. The first argument \fImask\fP is the |
| 1637 |
flags which we should examine, written as a comma-separated list, and |
| 1638 |
the second argument \fIcomp\fP is a comma-separated list of flags which must be |
| 1639 |
set. Flags are: |
| 1640 |
.BR "SYN ACK FIN RST URG PSH ALL NONE" . |
| 1641 |
Hence the command |
| 1642 |
.nf |
| 1643 |
iptables \-A FORWARD \-p tcp \-\-tcp\-flags SYN,ACK,FIN,RST SYN |
| 1644 |
.fi |
| 1645 |
will only match packets with the SYN flag set, and the ACK, FIN and |
| 1646 |
RST flags unset. |
| 1647 |
.TP |
| 1648 |
[\fB!\fP] \fB\-\-syn\fP |
| 1649 |
Only match TCP packets with the SYN bit set and the ACK,RST and FIN bits |
| 1650 |
cleared. Such packets are used to request TCP connection initiation; |
| 1651 |
for example, blocking such packets coming in an interface will prevent |
| 1652 |
incoming TCP connections, but outgoing TCP connections will be |
| 1653 |
unaffected. |
| 1654 |
It is equivalent to \fB\-\-tcp\-flags SYN,RST,ACK,FIN SYN\fP. |
| 1655 |
If the "!" flag precedes the "\-\-syn", the sense of the |
| 1656 |
option is inverted. |
| 1657 |
.TP |
| 1658 |
[\fB!\fP] \fB\-\-tcp\-option\fP \fInumber\fP |
| 1659 |
Match if TCP option set. |
| 1660 |
.SS tcpmss |
| 1661 |
This matches the TCP MSS (maximum segment size) field of the TCP header. You can only use this on TCP SYN or SYN/ACK packets, since the MSS is only negotiated during the TCP handshake at connection startup time. |
| 1662 |
.TP |
| 1663 |
[\fB!\fP] \fB\-\-mss\fP \fIvalue\fP[\fB:\fP\fIvalue\fP] |
| 1664 |
Match a given TCP MSS value or range. If a range is given, the second \fIvalue\fP must be greater than or equal to the first \fIvalue\fP. |
| 1665 |
.SS time |
| 1666 |
This matches if the packet arrival time/date is within a given range. All |
| 1667 |
options are optional, but are ANDed when specified. All times are interpreted |
| 1668 |
as UTC by default. |
| 1669 |
.TP |
| 1670 |
\fB\-\-datestart\fP \fIYYYY\fP[\fB\-\fP\fIMM\fP[\fB\-\fP\fIDD\fP[\fBT\fP\fIhh\fP[\fB:\fP\fImm\fP[\fB:\fP\fIss\fP]]]]] |
| 1671 |
.TP |
| 1672 |
\fB\-\-datestop\fP \fIYYYY\fP[\fB\-\fP\fIMM\fP[\fB\-\fP\fIDD\fP[\fBT\fP\fIhh\fP[\fB:\fP\fImm\fP[\fB:\fP\fIss\fP]]]]] |
| 1673 |
Only match during the given time, which must be in ISO 8601 "T" notation. |
| 1674 |
The possible time range is 1970-01-01T00:00:00 to 2038-01-19T04:17:07. |
| 1675 |
.IP |
| 1676 |
If \-\-datestart or \-\-datestop are not specified, it will default to 1970-01-01 |
| 1677 |
and 2038-01-19, respectively. |
| 1678 |
.TP |
| 1679 |
\fB\-\-timestart\fP \fIhh\fP\fB:\fP\fImm\fP[\fB:\fP\fIss\fP] |
| 1680 |
.TP |
| 1681 |
\fB\-\-timestop\fP \fIhh\fP\fB:\fP\fImm\fP[\fB:\fP\fIss\fP] |
| 1682 |
Only match during the given daytime. The possible time range is 00:00:00 to |
| 1683 |
23:59:59. Leading zeroes are allowed (e.g. "06:03") and correctly interpreted |
| 1684 |
as base-10. |
| 1685 |
.TP |
| 1686 |
[\fB!\fP] \fB\-\-monthdays\fP \fIday\fP[\fB,\fP\fIday\fP...] |
| 1687 |
Only match on the given days of the month. Possible values are \fB1\fP |
| 1688 |
to \fB31\fP. Note that specifying \fB31\fP will of course not match |
| 1689 |
on months which do not have a 31st day; the same goes for 28- or 29-day |
| 1690 |
February. |
| 1691 |
.TP |
| 1692 |
[\fB!\fP] \fB\-\-weekdays\fP \fIday\fP[\fB,\fP\fIday\fP...] |
| 1693 |
Only match on the given weekdays. Possible values are \fBMon\fP, \fBTue\fP, |
| 1694 |
\fBWed\fP, \fBThu\fP, \fBFri\fP, \fBSat\fP, \fBSun\fP, or values from \fB1\fP |
| 1695 |
to \fB7\fP, respectively. You may also use two-character variants (\fBMo\fP, |
| 1696 |
\fBTu\fP, etc.). |
| 1697 |
.TP |
| 1698 |
\fB\-\-contiguous\fP |
| 1699 |
When \fB\-\-timestop\fP is smaller than \fB\-\-timestart\fP value, match |
| 1700 |
this as a single time period instead distinct intervals. See EXAMPLES. |
| 1701 |
.TP |
| 1702 |
\fB\-\-kerneltz\fP |
| 1703 |
Use the kernel timezone instead of UTC to determine whether a packet meets the |
| 1704 |
time regulations. |
| 1705 |
.PP |
| 1706 |
About kernel timezones: Linux keeps the system time in UTC, and always does so. |
| 1707 |
On boot, system time is initialized from a referential time source. Where this |
| 1708 |
time source has no timezone information, such as the x86 CMOS RTC, UTC will be |
| 1709 |
assumed. If the time source is however not in UTC, userspace should provide the |
| 1710 |
correct system time and timezone to the kernel once it has the information. |
| 1711 |
.PP |
| 1712 |
Local time is a feature on top of the (timezone independent) system time. Each |
| 1713 |
process has its own idea of local time, specified via the TZ environment |
| 1714 |
variable. The kernel also has its own timezone offset variable. The TZ |
| 1715 |
userspace environment variable specifies how the UTC-based system time is |
| 1716 |
displayed, e.g. when you run date(1), or what you see on your desktop clock. |
| 1717 |
The TZ string may resolve to different offsets at different dates, which is |
| 1718 |
what enables the automatic time-jumping in userspace. when DST changes. The |
| 1719 |
kernel's timezone offset variable is used when it has to convert between |
| 1720 |
non-UTC sources, such as FAT filesystems, to UTC (since the latter is what the |
| 1721 |
rest of the system uses). |
| 1722 |
.PP |
| 1723 |
The caveat with the kernel timezone is that Linux distributions may ignore to |
| 1724 |
set the kernel timezone, and instead only set the system time. Even if a |
| 1725 |
particular distribution does set the timezone at boot, it is usually does not |
| 1726 |
keep the kernel timezone offset \(em which is what changes on DST \(em up to date. |
| 1727 |
ntpd will not touch the kernel timezone, so running it will not resolve the |
| 1728 |
issue. As such, one may encounter a timezone that is always +0000, or one that |
| 1729 |
is wrong half of the time of the year. As such, \fBusing \-\-kerneltz is highly |
| 1730 |
discouraged.\fP |
| 1731 |
.PP |
| 1732 |
EXAMPLES. To match on weekends, use: |
| 1733 |
.IP |
| 1734 |
\-m time \-\-weekdays Sa,Su |
| 1735 |
.PP |
| 1736 |
Or, to match (once) on a national holiday block: |
| 1737 |
.IP |
| 1738 |
\-m time \-\-datestart 2007\-12\-24 \-\-datestop 2007\-12\-27 |
| 1739 |
.PP |
| 1740 |
Since the stop time is actually inclusive, you would need the following stop |
| 1741 |
time to not match the first second of the new day: |
| 1742 |
.IP |
| 1743 |
\-m time \-\-datestart 2007\-01\-01T17:00 \-\-datestop 2007\-01\-01T23:59:59 |
| 1744 |
.PP |
| 1745 |
During lunch hour: |
| 1746 |
.IP |
| 1747 |
\-m time \-\-timestart 12:30 \-\-timestop 13:30 |
| 1748 |
.PP |
| 1749 |
The fourth Friday in the month: |
| 1750 |
.IP |
| 1751 |
\-m time \-\-weekdays Fr \-\-monthdays 22,23,24,25,26,27,28 |
| 1752 |
.PP |
| 1753 |
(Note that this exploits a certain mathematical property. It is not possible to |
| 1754 |
say "fourth Thursday OR fourth Friday" in one rule. It is possible with |
| 1755 |
multiple rules, though.) |
| 1756 |
.PP |
| 1757 |
Matching across days might not do what is expected. For instance, |
| 1758 |
.IP |
| 1759 |
\-m time \-\-weekdays Mo \-\-timestart 23:00 \-\-timestop 01:00 |
| 1760 |
Will match Monday, for one hour from midnight to 1 a.m., and then |
| 1761 |
again for another hour from 23:00 onwards. If this is unwanted, e.g. if you |
| 1762 |
would like 'match for two hours from Montay 23:00 onwards' you need to also specify |
| 1763 |
the \-\-contiguous option in the example above. |
| 1764 |
.SS tos |
| 1765 |
This module matches the 8-bit Type of Service field in the IPv4 header (i.e. |
| 1766 |
including the "Precedence" bits) or the (also 8-bit) Priority field in the IPv6 |
| 1767 |
header. |
| 1768 |
.TP |
| 1769 |
[\fB!\fP] \fB\-\-tos\fP \fIvalue\fP[\fB/\fP\fImask\fP] |
| 1770 |
Matches packets with the given TOS mark value. If a mask is specified, it is |
| 1771 |
logically ANDed with the TOS mark before the comparison. |
| 1772 |
.TP |
| 1773 |
[\fB!\fP] \fB\-\-tos\fP \fIsymbol\fP |
| 1774 |
You can specify a symbolic name when using the tos match for IPv4. The list of |
| 1775 |
recognized TOS names can be obtained by calling iptables with \fB\-m tos \-h\fP. |
| 1776 |
Note that this implies a mask of 0x3F, i.e. all but the ECN bits. |
| 1777 |
.SS ttl (IPv4-specific) |
| 1778 |
This module matches the time to live field in the IP header. |
| 1779 |
.TP |
| 1780 |
[\fB!\fP] \fB\-\-ttl\-eq\fP \fIttl\fP |
| 1781 |
Matches the given TTL value. |
| 1782 |
.TP |
| 1783 |
\fB\-\-ttl\-gt\fP \fIttl\fP |
| 1784 |
Matches if TTL is greater than the given TTL value. |
| 1785 |
.TP |
| 1786 |
\fB\-\-ttl\-lt\fP \fIttl\fP |
| 1787 |
Matches if TTL is less than the given TTL value. |
| 1788 |
.SS u32 |
| 1789 |
U32 tests whether quantities of up to 4 bytes extracted from a packet have |
| 1790 |
specified values. The specification of what to extract is general enough to |
| 1791 |
find data at given offsets from tcp headers or payloads. |
| 1792 |
.TP |
| 1793 |
[\fB!\fP] \fB\-\-u32\fP \fItests\fP |
| 1794 |
The argument amounts to a program in a small language described below. |
| 1795 |
.IP |
| 1796 |
tests := location "=" value | tests "&&" location "=" value |
| 1797 |
.IP |
| 1798 |
value := range | value "," range |
| 1799 |
.IP |
| 1800 |
range := number | number ":" number |
| 1801 |
.PP |
| 1802 |
a single number, \fIn\fP, is interpreted the same as \fIn:n\fP. \fIn:m\fP is |
| 1803 |
interpreted as the range of numbers \fB>=n\fP and \fB<=m\fP. |
| 1804 |
.IP "" 4 |
| 1805 |
location := number | location operator number |
| 1806 |
.IP "" 4 |
| 1807 |
operator := "&" | "<<" | ">>" | "@" |
| 1808 |
.PP |
| 1809 |
The operators \fB&\fP, \fB<<\fP, \fB>>\fP and \fB&&\fP mean the same as in C. |
| 1810 |
The \fB=\fP is really a set membership operator and the value syntax describes |
| 1811 |
a set. The \fB@\fP operator is what allows moving to the next header and is |
| 1812 |
described further below. |
| 1813 |
.PP |
| 1814 |
There are currently some artificial implementation limits on the size of the |
| 1815 |
tests: |
| 1816 |
.IP " *" |
| 1817 |
no more than 10 of "\fB=\fP" (and 9 "\fB&&\fP"s) in the u32 argument |
| 1818 |
.IP " *" |
| 1819 |
no more than 10 ranges (and 9 commas) per value |
| 1820 |
.IP " *" |
| 1821 |
no more than 10 numbers (and 9 operators) per location |
| 1822 |
.PP |
| 1823 |
To describe the meaning of location, imagine the following machine that |
| 1824 |
interprets it. There are three registers: |
| 1825 |
.IP |
| 1826 |
A is of type \fBchar *\fP, initially the address of the IP header |
| 1827 |
.IP |
| 1828 |
B and C are unsigned 32 bit integers, initially zero |
| 1829 |
.PP |
| 1830 |
The instructions are: |
| 1831 |
.TP |
| 1832 |
.B number |
| 1833 |
B = number; |
| 1834 |
.IP |
| 1835 |
C = (*(A+B)<<24) + (*(A+B+1)<<16) + (*(A+B+2)<<8) + *(A+B+3) |
| 1836 |
.TP |
| 1837 |
.B &number |
| 1838 |
C = C & number |
| 1839 |
.TP |
| 1840 |
.B << number |
| 1841 |
C = C << number |
| 1842 |
.TP |
| 1843 |
.B >> number |
| 1844 |
C = C >> number |
| 1845 |
.TP |
| 1846 |
.B @number |
| 1847 |
A = A + C; then do the instruction number |
| 1848 |
.PP |
| 1849 |
Any access of memory outside [skb\->data,skb\->end] causes the match to fail. |
| 1850 |
Otherwise the result of the computation is the final value of C. |
| 1851 |
.PP |
| 1852 |
Whitespace is allowed but not required in the tests. However, the characters |
| 1853 |
that do occur there are likely to require shell quoting, so it is a good idea |
| 1854 |
to enclose the arguments in quotes. |
| 1855 |
.PP |
| 1856 |
Example: |
| 1857 |
.IP |
| 1858 |
match IP packets with total length >= 256 |
| 1859 |
.IP |
| 1860 |
The IP header contains a total length field in bytes 2\(en3. |
| 1861 |
.IP |
| 1862 |
\-\-u32 "\fB0 & 0xFFFF = 0x100:0xFFFF\fP" |
| 1863 |
.IP |
| 1864 |
read bytes 0\(en3 |
| 1865 |
.IP |
| 1866 |
AND that with 0xFFFF (giving bytes 2\(en3), and test whether that is in the range |
| 1867 |
[0x100:0xFFFF] |
| 1868 |
.PP |
| 1869 |
Example: (more realistic, hence more complicated) |
| 1870 |
.IP |
| 1871 |
match ICMP packets with icmp type 0 |
| 1872 |
.IP |
| 1873 |
First test that it is an ICMP packet, true iff byte 9 (protocol) = 1 |
| 1874 |
.IP |
| 1875 |
\-\-u32 "\fB6 & 0xFF = 1 &&\fP ... |
| 1876 |
.IP |
| 1877 |
read bytes 6\(en9, use \fB&\fP to throw away bytes 6\(en8 and compare the result to |
| 1878 |
1. Next test that it is not a fragment. (If so, it might be part of such a |
| 1879 |
packet but we cannot always tell.) N.B.: This test is generally needed if you |
| 1880 |
want to match anything beyond the IP header. The last 6 bits of byte 6 and all |
| 1881 |
of byte 7 are 0 iff this is a complete packet (not a fragment). Alternatively, |
| 1882 |
you can allow first fragments by only testing the last 5 bits of byte 6. |
| 1883 |
.IP |
| 1884 |
... \fB4 & 0x3FFF = 0 &&\fP ... |
| 1885 |
.IP |
| 1886 |
Last test: the first byte past the IP header (the type) is 0. This is where we |
| 1887 |
have to use the @syntax. The length of the IP header (IHL) in 32 bit words is |
| 1888 |
stored in the right half of byte 0 of the IP header itself. |
| 1889 |
.IP |
| 1890 |
... \fB0 >> 22 & 0x3C @ 0 >> 24 = 0\fP" |
| 1891 |
.IP |
| 1892 |
The first 0 means read bytes 0\(en3, \fB>>22\fP means shift that 22 bits to the |
| 1893 |
right. Shifting 24 bits would give the first byte, so only 22 bits is four |
| 1894 |
times that plus a few more bits. \fB&3C\fP then eliminates the two extra bits |
| 1895 |
on the right and the first four bits of the first byte. For instance, if IHL=5, |
| 1896 |
then the IP header is 20 (4 x 5) bytes long. In this case, bytes 0\(en1 are (in |
| 1897 |
binary) xxxx0101 yyzzzzzz, \fB>>22\fP gives the 10 bit value xxxx0101yy and |
| 1898 |
\fB&3C\fP gives 010100. \fB@\fP means to use this number as a new offset into |
| 1899 |
the packet, and read four bytes starting from there. This is the first 4 bytes |
| 1900 |
of the ICMP payload, of which byte 0 is the ICMP type. Therefore, we simply |
| 1901 |
shift the value 24 to the right to throw out all but the first byte and compare |
| 1902 |
the result with 0. |
| 1903 |
.PP |
| 1904 |
Example: |
| 1905 |
.IP |
| 1906 |
TCP payload bytes 8\(en12 is any of 1, 2, 5 or 8 |
| 1907 |
.IP |
| 1908 |
First we test that the packet is a tcp packet (similar to ICMP). |
| 1909 |
.IP |
| 1910 |
\-\-u32 "\fB6 & 0xFF = 6 &&\fP ... |
| 1911 |
.IP |
| 1912 |
Next, test that it is not a fragment (same as above). |
| 1913 |
.IP |
| 1914 |
... \fB0 >> 22 & 0x3C @ 12 >> 26 & 0x3C @ 8 = 1,2,5,8\fP" |
| 1915 |
.IP |
| 1916 |
\fB0>>22&3C\fP as above computes the number of bytes in the IP header. \fB@\fP |
| 1917 |
makes this the new offset into the packet, which is the start of the TCP |
| 1918 |
header. The length of the TCP header (again in 32 bit words) is the left half |
| 1919 |
of byte 12 of the TCP header. The \fB12>>26&3C\fP computes this length in bytes |
| 1920 |
(similar to the IP header before). "@" makes this the new offset, which is the |
| 1921 |
start of the TCP payload. Finally, 8 reads bytes 8\(en12 of the payload and |
| 1922 |
\fB=\fP checks whether the result is any of 1, 2, 5 or 8. |
| 1923 |
.SS udp |
| 1924 |
These extensions can be used if `\-\-protocol udp' is specified. It |
| 1925 |
provides the following options: |
| 1926 |
.TP |
| 1927 |
[\fB!\fP] \fB\-\-source\-port\fP,\fB\-\-sport\fP \fIport\fP[\fB:\fP\fIport\fP] |
| 1928 |
Source port or port range specification. |
| 1929 |
See the description of the |
| 1930 |
\fB\-\-source\-port\fP |
| 1931 |
option of the TCP extension for details. |
| 1932 |
.TP |
| 1933 |
[\fB!\fP] \fB\-\-destination\-port\fP,\fB\-\-dport\fP \fIport\fP[\fB:\fP\fIport\fP] |
| 1934 |
Destination port or port range specification. |
| 1935 |
See the description of the |
| 1936 |
\fB\-\-destination\-port\fP |
| 1937 |
option of the TCP extension for details. |
| 1938 |
.SH TARGET EXTENSIONS |
| 1939 |
iptables can use extended target modules: the following are included |
| 1940 |
in the standard distribution. |
| 1941 |
.\" @TARGET@ |
| 1942 |
.SS AUDIT |
| 1943 |
This target creates audit records for packets hitting the target. |
| 1944 |
It can be used to record accepted, dropped, and rejected packets. See |
| 1945 |
auditd(8) for additional details. |
| 1946 |
.TP |
| 1947 |
\fB\-\-type\fP {\fBaccept\fP|\fBdrop\fP|\fBreject\fP} |
| 1948 |
Set type of audit record. Starting with linux-4.12, this option has no effect |
| 1949 |
on generated audit messages anymore. It is still accepted by iptables for |
| 1950 |
compatibility reasons, but ignored. |
| 1951 |
.PP |
| 1952 |
Example: |
| 1953 |
.IP |
| 1954 |
iptables \-N AUDIT_DROP |
| 1955 |
.IP |
| 1956 |
iptables \-A AUDIT_DROP \-j AUDIT |
| 1957 |
.IP |
| 1958 |
iptables \-A AUDIT_DROP \-j DROP |
| 1959 |
.SS CHECKSUM |
| 1960 |
This target selectively works around broken/old applications. |
| 1961 |
It can only be used in the mangle table. |
| 1962 |
.TP |
| 1963 |
\fB\-\-checksum\-fill\fP |
| 1964 |
Compute and fill in the checksum in a packet that lacks a checksum. |
| 1965 |
This is particularly useful, if you need to work around old applications |
| 1966 |
such as dhcp clients, that do not work well with checksum offloads, |
| 1967 |
but don't want to disable checksum offload in your device. |
| 1968 |
.SS CLASSIFY |
| 1969 |
This module allows you to set the skb\->priority value (and thus classify the packet into a specific CBQ class). |
| 1970 |
.TP |
| 1971 |
\fB\-\-set\-class\fP \fImajor\fP\fB:\fP\fIminor\fP |
| 1972 |
Set the major and minor class value. The values are always interpreted as |
| 1973 |
hexadecimal even if no 0x prefix is given. |
| 1974 |
.SS CLUSTERIP (IPv4-specific) |
| 1975 |
This module allows you to configure a simple cluster of nodes that share |
| 1976 |
a certain IP and MAC address without an explicit load balancer in front of |
| 1977 |
them. Connections are statically distributed between the nodes in this |
| 1978 |
cluster. |
| 1979 |
.PP |
| 1980 |
Please note that CLUSTERIP target is considered deprecated in favour of cluster |
| 1981 |
match which is more flexible and not limited to IPv4. |
| 1982 |
.TP |
| 1983 |
\fB\-\-new\fP |
| 1984 |
Create a new ClusterIP. You always have to set this on the first rule |
| 1985 |
for a given ClusterIP. |
| 1986 |
.TP |
| 1987 |
\fB\-\-hashmode\fP \fImode\fP |
| 1988 |
Specify the hashing mode. Has to be one of |
| 1989 |
\fBsourceip\fP, \fBsourceip\-sourceport\fP, \fBsourceip\-sourceport\-destport\fP. |
| 1990 |
.TP |
| 1991 |
\fB\-\-clustermac\fP \fImac\fP |
| 1992 |
Specify the ClusterIP MAC address. Has to be a link\-layer multicast address |
| 1993 |
.TP |
| 1994 |
\fB\-\-total\-nodes\fP \fInum\fP |
| 1995 |
Number of total nodes within this cluster. |
| 1996 |
.TP |
| 1997 |
\fB\-\-local\-node\fP \fInum\fP |
| 1998 |
Local node number within this cluster. |
| 1999 |
.TP |
| 2000 |
\fB\-\-hash\-init\fP \fIrnd\fP |
| 2001 |
Specify the random seed used for hash initialization. |
| 2002 |
.SS CONNMARK |
| 2003 |
This module sets the netfilter mark value associated with a connection. The |
| 2004 |
mark is 32 bits wide. |
| 2005 |
.TP |
| 2006 |
\fB\-\-set\-xmark\fP \fIvalue\fP[\fB/\fP\fImask\fP] |
| 2007 |
Zero out the bits given by \fImask\fP and XOR \fIvalue\fP into the ctmark. |
| 2008 |
.TP |
| 2009 |
\fB\-\-save\-mark\fP [\fB\-\-nfmask\fP \fInfmask\fP] [\fB\-\-ctmask\fP \fIctmask\fP] |
| 2010 |
Copy the packet mark (nfmark) to the connection mark (ctmark) using the given |
| 2011 |
masks. The new nfmark value is determined as follows: |
| 2012 |
.IP |
| 2013 |
ctmark = (ctmark & \(tictmask) \(ha (nfmark & nfmask) |
| 2014 |
.IP |
| 2015 |
i.e. \fIctmask\fP defines what bits to clear and \fInfmask\fP what bits of the |
| 2016 |
nfmark to XOR into the ctmark. \fIctmask\fP and \fInfmask\fP default to |
| 2017 |
0xFFFFFFFF. |
| 2018 |
.TP |
| 2019 |
\fB\-\-restore\-mark\fP [\fB\-\-nfmask\fP \fInfmask\fP] [\fB\-\-ctmask\fP \fIctmask\fP] |
| 2020 |
Copy the connection mark (ctmark) to the packet mark (nfmark) using the given |
| 2021 |
masks. The new ctmark value is determined as follows: |
| 2022 |
.IP |
| 2023 |
nfmark = (nfmark & \(ti\fInfmask\fP) \(ha (ctmark & \fIctmask\fP); |
| 2024 |
.IP |
| 2025 |
i.e. \fInfmask\fP defines what bits to clear and \fIctmask\fP what bits of the |
| 2026 |
ctmark to XOR into the nfmark. \fIctmask\fP and \fInfmask\fP default to |
| 2027 |
0xFFFFFFFF. |
| 2028 |
.IP |
| 2029 |
\fB\-\-restore\-mark\fP is only valid in the \fBmangle\fP table. |
| 2030 |
.PP |
| 2031 |
The following mnemonics are available for \fB\-\-set\-xmark\fP: |
| 2032 |
.TP |
| 2033 |
\fB\-\-and\-mark\fP \fIbits\fP |
| 2034 |
Binary AND the ctmark with \fIbits\fP. (Mnemonic for \fB\-\-set\-xmark |
| 2035 |
0/\fP\fIinvbits\fP, where \fIinvbits\fP is the binary negation of \fIbits\fP.) |
| 2036 |
.TP |
| 2037 |
\fB\-\-or\-mark\fP \fIbits\fP |
| 2038 |
Binary OR the ctmark with \fIbits\fP. (Mnemonic for \fB\-\-set\-xmark\fP |
| 2039 |
\fIbits\fP\fB/\fP\fIbits\fP.) |
| 2040 |
.TP |
| 2041 |
\fB\-\-xor\-mark\fP \fIbits\fP |
| 2042 |
Binary XOR the ctmark with \fIbits\fP. (Mnemonic for \fB\-\-set\-xmark\fP |
| 2043 |
\fIbits\fP\fB/0\fP.) |
| 2044 |
.TP |
| 2045 |
\fB\-\-set\-mark\fP \fIvalue\fP[\fB/\fP\fImask\fP] |
| 2046 |
Set the connection mark. If a mask is specified then only those bits set in the |
| 2047 |
mask are modified. |
| 2048 |
.TP |
| 2049 |
\fB\-\-save\-mark\fP [\fB\-\-mask\fP \fImask\fP] |
| 2050 |
Copy the nfmark to the ctmark. If a mask is specified, only those bits are |
| 2051 |
copied. |
| 2052 |
.TP |
| 2053 |
\fB\-\-restore\-mark\fP [\fB\-\-mask\fP \fImask\fP] |
| 2054 |
Copy the ctmark to the nfmark. If a mask is specified, only those bits are |
| 2055 |
copied. This is only valid in the \fBmangle\fP table. |
| 2056 |
.SS CONNSECMARK |
| 2057 |
This module copies security markings from packets to connections |
| 2058 |
(if unlabeled), and from connections back to packets (also only |
| 2059 |
if unlabeled). Typically used in conjunction with SECMARK, it is |
| 2060 |
valid in the |
| 2061 |
.B security |
| 2062 |
table (for backwards compatibility with older kernels, it is also |
| 2063 |
valid in the |
| 2064 |
.B mangle |
| 2065 |
table). |
| 2066 |
.TP |
| 2067 |
\fB\-\-save\fP |
| 2068 |
If the packet has a security marking, copy it to the connection |
| 2069 |
if the connection is not marked. |
| 2070 |
.TP |
| 2071 |
\fB\-\-restore\fP |
| 2072 |
If the packet does not have a security marking, and the connection |
| 2073 |
does, copy the security marking from the connection to the packet. |
| 2074 |
|
| 2075 |
.SS CT |
| 2076 |
The CT target sets parameters for a packet or its associated |
| 2077 |
connection. The target attaches a "template" connection tracking entry to |
| 2078 |
the packet, which is then used by the conntrack core when initializing |
| 2079 |
a new ct entry. This target is thus only valid in the "raw" table. |
| 2080 |
.TP |
| 2081 |
\fB\-\-notrack\fP |
| 2082 |
Disables connection tracking for this packet. |
| 2083 |
.TP |
| 2084 |
\fB\-\-helper\fP \fIname\fP |
| 2085 |
Use the helper identified by \fIname\fP for the connection. This is more |
| 2086 |
flexible than loading the conntrack helper modules with preset ports. |
| 2087 |
.TP |
| 2088 |
\fB\-\-ctevents\fP \fIevent\fP[\fB,\fP...] |
| 2089 |
Only generate the specified conntrack events for this connection. Possible |
| 2090 |
event types are: \fBnew\fP, \fBrelated\fP, \fBdestroy\fP, \fBreply\fP, |
| 2091 |
\fBassured\fP, \fBprotoinfo\fP, \fBhelper\fP, \fBmark\fP (this refers to |
| 2092 |
the ctmark, not nfmark), \fBnatseqinfo\fP, \fBsecmark\fP (ctsecmark). |
| 2093 |
.TP |
| 2094 |
\fB\-\-expevents\fP \fIevent\fP[\fB,\fP...] |
| 2095 |
Only generate the specified expectation events for this connection. |
| 2096 |
Possible event types are: \fBnew\fP. |
| 2097 |
.TP |
| 2098 |
\fB\-\-zone\-orig\fP {\fIid\fP|\fBmark\fP} |
| 2099 |
For traffic coming from ORIGINAL direction, assign this packet to zone |
| 2100 |
\fIid\fP and only have lookups done in that zone. If \fBmark\fP is used |
| 2101 |
instead of \fIid\fP, the zone is derived from the packet nfmark. |
| 2102 |
.TP |
| 2103 |
\fB\-\-zone\-reply\fP {\fIid\fP|\fBmark\fP} |
| 2104 |
For traffic coming from REPLY direction, assign this packet to zone |
| 2105 |
\fIid\fP and only have lookups done in that zone. If \fBmark\fP is used |
| 2106 |
instead of \fIid\fP, the zone is derived from the packet nfmark. |
| 2107 |
.TP |
| 2108 |
\fB\-\-zone\fP {\fIid\fP|\fBmark\fP} |
| 2109 |
Assign this packet to zone \fIid\fP and only have lookups done in that zone. |
| 2110 |
If \fBmark\fP is used instead of \fIid\fP, the zone is derived from the |
| 2111 |
packet nfmark. By default, packets have zone 0. This option applies to both |
| 2112 |
directions. |
| 2113 |
.TP |
| 2114 |
\fB\-\-timeout\fP \fIname\fP |
| 2115 |
Use the timeout policy identified by \fIname\fP for the connection. This is |
| 2116 |
provides more flexible timeout policy definition than global timeout values |
| 2117 |
available at /proc/sys/net/netfilter/nf_conntrack_*_timeout_*. |
| 2118 |
.SS DNAT |
| 2119 |
This target is only valid in the |
| 2120 |
.B nat |
| 2121 |
table, in the |
| 2122 |
.B PREROUTING |
| 2123 |
and |
| 2124 |
.B OUTPUT |
| 2125 |
chains, and user-defined chains which are only called from those |
| 2126 |
chains. It specifies that the destination address of the packet |
| 2127 |
should be modified (and all future packets in this connection will |
| 2128 |
also be mangled), and rules should cease being examined. It takes the |
| 2129 |
following options: |
| 2130 |
.TP |
| 2131 |
\fB\-\-to\-destination\fP [\fIipaddr\fP[\fB\-\fP\fIipaddr\fP]][\fB:\fP\fIport\fP[\fB\-\fP\fIport\fP[\fB/\fIbaseport\fP]]] |
| 2132 |
which can specify a single new destination IP address, an inclusive |
| 2133 |
range of IP addresses. Optionally a port range, |
| 2134 |
if the rule also specifies one of the following protocols: |
| 2135 |
\fBtcp\fP, \fBudp\fP, \fBdccp\fP or \fBsctp\fP. |
| 2136 |
If no port range is specified, then the destination port will never be |
| 2137 |
modified. If no IP address is specified then only the destination port |
| 2138 |
will be modified. |
| 2139 |
If \fBbaseport\fP is given, the difference of the original destination port and |
| 2140 |
its value is used as offset into the mapping port range. This allows one to create |
| 2141 |
shifted portmap ranges and is available since kernel version 4.18. |
| 2142 |
For a single port or \fIbaseport\fP, a service name as listed in |
| 2143 |
\fB/etc/services\fP may be used. |
| 2144 |
If \fIipaddr\fP is an IPv4 loopback address (i.e. 127.0.0.0/8) the |
| 2145 |
"net.ipv4.conf.*.route_localnet" sysctl for the input interface needs |
| 2146 |
to be set to 1. Otherwise packets will be dropped by the routing code |
| 2147 |
as "martians". |
| 2148 |
.TP |
| 2149 |
\fB\-\-random\fP |
| 2150 |
Randomize source port mapping (kernel >= 2.6.22). |
| 2151 |
.TP |
| 2152 |
\fB\-\-persistent\fP |
| 2153 |
Gives a client the same source-/destination-address for each connection. |
| 2154 |
This supersedes the SAME target. Support for persistent mappings is available |
| 2155 |
from 2.6.29-rc2. |
| 2156 |
.TP |
| 2157 |
IPv6 support available since Linux kernels >= 3.7. |
| 2158 |
.SS DNPT (IPv6-specific) |
| 2159 |
Provides stateless destination IPv6-to-IPv6 Network Prefix Translation (as |
| 2160 |
described by RFC 6296). |
| 2161 |
.PP |
| 2162 |
You have to use this target in the |
| 2163 |
.B mangle |
| 2164 |
table, not in the |
| 2165 |
.B nat |
| 2166 |
table. It takes the following options: |
| 2167 |
.TP |
| 2168 |
\fB\-\-src\-pfx\fP [\fIprefix/\fP\fIlength] |
| 2169 |
Set source prefix that you want to translate and length |
| 2170 |
.TP |
| 2171 |
\fB\-\-dst\-pfx\fP [\fIprefix/\fP\fIlength] |
| 2172 |
Set destination prefix that you want to use in the translation and length |
| 2173 |
.PP |
| 2174 |
You have to use the SNPT target to undo the translation. Example: |
| 2175 |
.IP |
| 2176 |
ip6tables \-t mangle \-I POSTROUTING \-s fd00::/64 ! \-o vboxnet0 |
| 2177 |
\-j SNPT \-\-src-pfx fd00::/64 \-\-dst-pfx 2001:e20:2000:40f::/64 |
| 2178 |
.IP |
| 2179 |
ip6tables \-t mangle \-I PREROUTING \-i wlan0 \-d 2001:e20:2000:40f::/64 |
| 2180 |
\-j DNPT \-\-src-pfx 2001:e20:2000:40f::/64 \-\-dst\-pfx fd00::/64 |
| 2181 |
.PP |
| 2182 |
You may need to enable IPv6 neighbor proxy: |
| 2183 |
.IP |
| 2184 |
sysctl \-w net.ipv6.conf.all.proxy_ndp=1 |
| 2185 |
.PP |
| 2186 |
You also have to use the |
| 2187 |
.B NOTRACK |
| 2188 |
target to disable connection tracking for translated flows. |
| 2189 |
.SS DSCP |
| 2190 |
This target alters the value of the DSCP bits within the TOS |
| 2191 |
header of the IPv4 packet. As this manipulates a packet, it can only |
| 2192 |
be used in the mangle table. |
| 2193 |
.TP |
| 2194 |
\fB\-\-set\-dscp\fP \fIvalue\fP |
| 2195 |
Set the DSCP field to a numerical value (can be decimal or hex) |
| 2196 |
.TP |
| 2197 |
\fB\-\-set\-dscp\-class\fP \fIclass\fP |
| 2198 |
Set the DSCP field to a DiffServ class. |
| 2199 |
.SS ECN (IPv4-specific) |
| 2200 |
This target selectively works around known ECN blackholes. |
| 2201 |
It can only be used in the mangle table. |
| 2202 |
.TP |
| 2203 |
\fB\-\-ecn\-tcp\-remove\fP |
| 2204 |
Remove all ECN bits from the TCP header. Of course, it can only be used |
| 2205 |
in conjunction with |
| 2206 |
\fB\-p tcp\fP. |
| 2207 |
.SS HL (IPv6-specific) |
| 2208 |
This is used to modify the Hop Limit field in IPv6 header. The Hop Limit field |
| 2209 |
is similar to what is known as TTL value in IPv4. Setting or incrementing the |
| 2210 |
Hop Limit field can potentially be very dangerous, so it should be avoided at |
| 2211 |
any cost. This target is only valid in |
| 2212 |
.B mangle |
| 2213 |
table. |
| 2214 |
.PP |
| 2215 |
.B Don't ever set or increment the value on packets that leave your local network! |
| 2216 |
.TP |
| 2217 |
\fB\-\-hl\-set\fP \fIvalue\fP |
| 2218 |
Set the Hop Limit to `value'. |
| 2219 |
.TP |
| 2220 |
\fB\-\-hl\-dec\fP \fIvalue\fP |
| 2221 |
Decrement the Hop Limit `value' times. |
| 2222 |
.TP |
| 2223 |
\fB\-\-hl\-inc\fP \fIvalue\fP |
| 2224 |
Increment the Hop Limit `value' times. |
| 2225 |
.SS HMARK |
| 2226 |
Like MARK, i.e. set the fwmark, but the mark is calculated from hashing |
| 2227 |
packet selector at choice. You have also to specify the mark range and, |
| 2228 |
optionally, the offset to start from. ICMP error messages are inspected |
| 2229 |
and used to calculate the hashing. |
| 2230 |
.PP |
| 2231 |
Existing options are: |
| 2232 |
.TP |
| 2233 |
\fB\-\-hmark\-tuple\fP tuple\fI\fP |
| 2234 |
Possible tuple members are: |
| 2235 |
.B src |
| 2236 |
meaning source address (IPv4, IPv6 address), |
| 2237 |
.B dst |
| 2238 |
meaning destination address (IPv4, IPv6 address), |
| 2239 |
.B sport |
| 2240 |
meaning source port (TCP, UDP, UDPlite, SCTP, DCCP), |
| 2241 |
.B dport |
| 2242 |
meaning destination port (TCP, UDP, UDPlite, SCTP, DCCP), |
| 2243 |
.B spi |
| 2244 |
meaning Security Parameter Index (AH, ESP), and |
| 2245 |
.B ct |
| 2246 |
meaning the usage of the conntrack tuple instead of the packet selectors. |
| 2247 |
.TP |
| 2248 |
\fB\-\-hmark\-mod\fP \fIvalue (must be > 0)\fP |
| 2249 |
Modulus for hash calculation (to limit the range of possible marks) |
| 2250 |
.TP |
| 2251 |
\fB\-\-hmark\-offset\fP \fIvalue\fP |
| 2252 |
Offset to start marks from. |
| 2253 |
.TP |
| 2254 |
For advanced usage, instead of using \-\-hmark\-tuple, you can specify custom |
| 2255 |
prefixes and masks: |
| 2256 |
.TP |
| 2257 |
\fB\-\-hmark\-src\-prefix\fP \fIcidr\fP |
| 2258 |
The source address mask in CIDR notation. |
| 2259 |
.TP |
| 2260 |
\fB\-\-hmark\-dst\-prefix\fP \fIcidr\fP |
| 2261 |
The destination address mask in CIDR notation. |
| 2262 |
.TP |
| 2263 |
\fB\-\-hmark\-sport\-mask\fP \fIvalue\fP |
| 2264 |
A 16 bit source port mask in hexadecimal. |
| 2265 |
.TP |
| 2266 |
\fB\-\-hmark\-dport\-mask\fP \fIvalue\fP |
| 2267 |
A 16 bit destination port mask in hexadecimal. |
| 2268 |
.TP |
| 2269 |
\fB\-\-hmark\-spi\-mask\fP \fIvalue\fP |
| 2270 |
A 32 bit field with spi mask. |
| 2271 |
.TP |
| 2272 |
\fB\-\-hmark\-proto\-mask\fP \fIvalue\fP |
| 2273 |
An 8 bit field with layer 4 protocol number. |
| 2274 |
.TP |
| 2275 |
\fB\-\-hmark\-rnd\fP \fIvalue\fP |
| 2276 |
A 32 bit random custom value to feed hash calculation. |
| 2277 |
.PP |
| 2278 |
\fIExamples:\fP |
| 2279 |
.PP |
| 2280 |
iptables \-t mangle \-A PREROUTING \-m conntrack \-\-ctstate NEW |
| 2281 |
\-j HMARK \-\-hmark-tuple ct,src,dst,proto \-\-hmark\-offset 10000 |
| 2282 |
\-\-hmark\-mod 10 \-\-hmark\-rnd 0xfeedcafe |
| 2283 |
.PP |
| 2284 |
iptables \-t mangle \-A PREROUTING \-j HMARK \-\-hmark\-offset 10000 |
| 2285 |
\-\-hmark-tuple src,dst,proto \-\-hmark-mod 10 \-\-hmark\-rnd 0xdeafbeef |
| 2286 |
.SS IDLETIMER |
| 2287 |
This target can be used to identify when interfaces have been idle for a |
| 2288 |
certain period of time. Timers are identified by labels and are created when |
| 2289 |
a rule is set with a new label. The rules also take a timeout value (in |
| 2290 |
seconds) as an option. If more than one rule uses the same timer label, the |
| 2291 |
timer will be restarted whenever any of the rules get a hit. One entry for |
| 2292 |
each timer is created in sysfs. This attribute contains the timer remaining |
| 2293 |
for the timer to expire. The attributes are located under the xt_idletimer |
| 2294 |
class: |
| 2295 |
.PP |
| 2296 |
/sys/class/xt_idletimer/timers/<label> |
| 2297 |
.PP |
| 2298 |
When the timer expires, the target module sends a sysfs notification to the |
| 2299 |
userspace, which can then decide what to do (eg. disconnect to save power). |
| 2300 |
.TP |
| 2301 |
\fB\-\-timeout\fP \fIamount\fP |
| 2302 |
This is the time in seconds that will trigger the notification. |
| 2303 |
.TP |
| 2304 |
\fB\-\-label\fP \fIstring\fP |
| 2305 |
This is a unique identifier for the timer. The maximum length for the |
| 2306 |
label string is 27 characters. |
| 2307 |
.SS LED |
| 2308 |
This creates an LED-trigger that can then be attached to system indicator |
| 2309 |
lights, to blink or illuminate them when certain packets pass through the |
| 2310 |
system. One example might be to light up an LED for a few minutes every time |
| 2311 |
an SSH connection is made to the local machine. The following options control |
| 2312 |
the trigger behavior: |
| 2313 |
.TP |
| 2314 |
\fB\-\-led\-trigger\-id\fP \fIname\fP |
| 2315 |
This is the name given to the LED trigger. The actual name of the trigger |
| 2316 |
will be prefixed with "netfilter\-". |
| 2317 |
.TP |
| 2318 |
\fB\-\-led\-delay\fP \fIms\fP |
| 2319 |
This indicates how long (in milliseconds) the LED should be left illuminated |
| 2320 |
when a packet arrives before being switched off again. The default is 0 |
| 2321 |
(blink as fast as possible.) The special value \fIinf\fP can be given to |
| 2322 |
leave the LED on permanently once activated. (In this case the trigger will |
| 2323 |
need to be manually detached and reattached to the LED device to switch it |
| 2324 |
off again.) |
| 2325 |
.TP |
| 2326 |
\fB\-\-led\-always\-blink\fP |
| 2327 |
Always make the LED blink on packet arrival, even if the LED is already on. |
| 2328 |
This allows notification of new packets even with long delay values (which |
| 2329 |
otherwise would result in a silent prolonging of the delay time.) |
| 2330 |
.TP |
| 2331 |
Example: |
| 2332 |
.TP |
| 2333 |
Create an LED trigger for incoming SSH traffic: |
| 2334 |
iptables \-A INPUT \-p tcp \-\-dport 22 \-j LED \-\-led\-trigger\-id ssh |
| 2335 |
.TP |
| 2336 |
Then attach the new trigger to an LED: |
| 2337 |
echo netfilter\-ssh >/sys/class/leds/\fIledname\fP/trigger |
| 2338 |
.SS LOG |
| 2339 |
Turn on kernel logging of matching packets. When this option is set |
| 2340 |
for a rule, the Linux kernel will print some information on all |
| 2341 |
matching packets (like most IP/IPv6 header fields) via the kernel log |
| 2342 |
(where it can be read with \fIdmesg(1)\fP or read in the syslog). |
| 2343 |
.PP |
| 2344 |
This is a "non-terminating target", i.e. rule traversal continues at |
| 2345 |
the next rule. So if you want to LOG the packets you refuse, use two |
| 2346 |
separate rules with the same matching criteria, first using target LOG |
| 2347 |
then DROP (or REJECT). |
| 2348 |
.TP |
| 2349 |
\fB\-\-log\-level\fP \fIlevel\fP |
| 2350 |
Level of logging, which can be (system-specific) numeric or a mnemonic. |
| 2351 |
Possible values are (in decreasing order of priority): \fBemerg\fP, |
| 2352 |
\fBalert\fP, \fBcrit\fP, \fBerror\fP, \fBwarning\fP, \fBnotice\fP, \fBinfo\fP |
| 2353 |
or \fBdebug\fP. |
| 2354 |
.TP |
| 2355 |
\fB\-\-log\-prefix\fP \fIprefix\fP |
| 2356 |
Prefix log messages with the specified prefix; up to 29 letters long, |
| 2357 |
and useful for distinguishing messages in the logs. |
| 2358 |
.TP |
| 2359 |
\fB\-\-log\-tcp\-sequence\fP |
| 2360 |
Log TCP sequence numbers. This is a security risk if the log is |
| 2361 |
readable by users. |
| 2362 |
.TP |
| 2363 |
\fB\-\-log\-tcp\-options\fP |
| 2364 |
Log options from the TCP packet header. |
| 2365 |
.TP |
| 2366 |
\fB\-\-log\-ip\-options\fP |
| 2367 |
Log options from the IP/IPv6 packet header. |
| 2368 |
.TP |
| 2369 |
\fB\-\-log\-uid\fP |
| 2370 |
Log the userid of the process which generated the packet. |
| 2371 |
.TP |
| 2372 |
\fB\-\-log\-macdecode\fP |
| 2373 |
Log MAC addresses and protocol. |
| 2374 |
.SS MARK |
| 2375 |
This target is used to set the Netfilter mark value associated with the packet. |
| 2376 |
It can, for example, be used in conjunction with routing based on fwmark (needs |
| 2377 |
iproute2). If you plan on doing so, note that the mark needs to be set in |
| 2378 |
either the PREROUTING or the OUTPUT chain of the mangle table to affect routing. |
| 2379 |
The mark field is 32 bits wide. |
| 2380 |
.TP |
| 2381 |
\fB\-\-set\-xmark\fP \fIvalue\fP[\fB/\fP\fImask\fP] |
| 2382 |
Zeroes out the bits given by \fImask\fP and XORs \fIvalue\fP into the packet |
| 2383 |
mark ("nfmark"). If \fImask\fP is omitted, 0xFFFFFFFF is assumed. |
| 2384 |
.TP |
| 2385 |
\fB\-\-set\-mark\fP \fIvalue\fP[\fB/\fP\fImask\fP] |
| 2386 |
Zeroes out the bits given by \fImask\fP and ORs \fIvalue\fP into the packet |
| 2387 |
mark. If \fImask\fP is omitted, 0xFFFFFFFF is assumed. |
| 2388 |
.PP |
| 2389 |
The following mnemonics are available: |
| 2390 |
.TP |
| 2391 |
\fB\-\-and\-mark\fP \fIbits\fP |
| 2392 |
Binary AND the nfmark with \fIbits\fP. (Mnemonic for \fB\-\-set\-xmark |
| 2393 |
0/\fP\fIinvbits\fP, where \fIinvbits\fP is the binary negation of \fIbits\fP.) |
| 2394 |
.TP |
| 2395 |
\fB\-\-or\-mark\fP \fIbits\fP |
| 2396 |
Binary OR the nfmark with \fIbits\fP. (Mnemonic for \fB\-\-set\-xmark\fP |
| 2397 |
\fIbits\fP\fB/\fP\fIbits\fP.) |
| 2398 |
.TP |
| 2399 |
\fB\-\-xor\-mark\fP \fIbits\fP |
| 2400 |
Binary XOR the nfmark with \fIbits\fP. (Mnemonic for \fB\-\-set\-xmark\fP |
| 2401 |
\fIbits\fP\fB/0\fP.) |
| 2402 |
.SS MASQUERADE |
| 2403 |
This target is only valid in the |
| 2404 |
.B nat |
| 2405 |
table, in the |
| 2406 |
.B POSTROUTING |
| 2407 |
chain. It should only be used with dynamically assigned IP (dialup) |
| 2408 |
connections: if you have a static IP address, you should use the SNAT |
| 2409 |
target. Masquerading is equivalent to specifying a mapping to the IP |
| 2410 |
address of the interface the packet is going out, but also has the |
| 2411 |
effect that connections are |
| 2412 |
.I forgotten |
| 2413 |
when the interface goes down. This is the correct behavior when the |
| 2414 |
next dialup is unlikely to have the same interface address (and hence |
| 2415 |
any established connections are lost anyway). |
| 2416 |
.TP |
| 2417 |
\fB\-\-to\-ports\fP \fIport\fP[\fB\-\fP\fIport\fP] |
| 2418 |
This specifies a range of source ports to use, overriding the default |
| 2419 |
.B SNAT |
| 2420 |
source port selection heuristics (see above). This is only valid |
| 2421 |
if the rule also specifies one of the following protocols: |
| 2422 |
\fBtcp\fP, \fBudp\fP, \fBdccp\fP or \fBsctp\fP. |
| 2423 |
.TP |
| 2424 |
\fB\-\-random\fP |
| 2425 |
Randomize source port mapping (kernel >= 2.6.21). |
| 2426 |
Since kernel 5.0, \fB\-\-random\fP is identical to \fB\-\-random\-fully\fP. |
| 2427 |
.TP |
| 2428 |
\fB\-\-random\-fully\fP |
| 2429 |
Fully randomize source port mapping (kernel >= 3.13). |
| 2430 |
.TP |
| 2431 |
IPv6 support available since Linux kernels >= 3.7. |
| 2432 |
.SS NETMAP |
| 2433 |
This target allows you to statically map a whole network of addresses onto |
| 2434 |
another network of addresses. It can only be used from rules in the |
| 2435 |
.B nat |
| 2436 |
table. |
| 2437 |
.TP |
| 2438 |
\fB\-\-to\fP \fIaddress\fP[\fB/\fP\fImask\fP] |
| 2439 |
Network address to map to. The resulting address will be constructed in the |
| 2440 |
following way: All 'one' bits in the mask are filled in from the new `address'. |
| 2441 |
All bits that are zero in the mask are filled in from the original address. |
| 2442 |
.TP |
| 2443 |
IPv6 support available since Linux kernels >= 3.7. |
| 2444 |
.SS NFLOG |
| 2445 |
This target provides logging of matching packets. When this target is |
| 2446 |
set for a rule, the Linux kernel will pass the packet to the loaded |
| 2447 |
logging backend to log the packet. This is usually used in combination |
| 2448 |
with nfnetlink_log as logging backend, which will multicast the packet |
| 2449 |
through a |
| 2450 |
.IR netlink |
| 2451 |
socket to the specified multicast group. One or more userspace processes |
| 2452 |
may subscribe to the group to receive the packets. Like LOG, this is a |
| 2453 |
non-terminating target, i.e. rule traversal continues at the next rule. |
| 2454 |
.TP |
| 2455 |
\fB\-\-nflog\-group\fP \fInlgroup\fP |
| 2456 |
The netlink group (0\(en2\(ha16\-1) to which packets are (only applicable for |
| 2457 |
nfnetlink_log). The default value is 0. |
| 2458 |
.TP |
| 2459 |
\fB\-\-nflog\-prefix\fP \fIprefix\fP |
| 2460 |
A prefix string to include in the log message, up to 64 characters |
| 2461 |
long, useful for distinguishing messages in the logs. |
| 2462 |
.TP |
| 2463 |
\fB\-\-nflog\-range\fP \fIsize\fP |
| 2464 |
This option has never worked, use \-\-nflog\-size instead |
| 2465 |
.TP |
| 2466 |
\fB\-\-nflog\-size\fP \fIsize\fP |
| 2467 |
The number of bytes to be copied to userspace (only applicable for |
| 2468 |
nfnetlink_log). nfnetlink_log instances may specify their own |
| 2469 |
range, this option overrides it. |
| 2470 |
.TP |
| 2471 |
\fB\-\-nflog\-threshold\fP \fIsize\fP |
| 2472 |
Number of packets to queue inside the kernel before sending them |
| 2473 |
to userspace (only applicable for nfnetlink_log). Higher values |
| 2474 |
result in less overhead per packet, but increase delay until the |
| 2475 |
packets reach userspace. The default value is 1. |
| 2476 |
.BR |
| 2477 |
.SS NFQUEUE |
| 2478 |
This target passes the packet to userspace using the |
| 2479 |
\fBnfnetlink_queue\fP handler. The packet is put into the queue |
| 2480 |
identified by its 16-bit queue number. Userspace can inspect |
| 2481 |
and modify the packet if desired. Userspace must then drop or |
| 2482 |
reinject the packet into the kernel. Please see libnetfilter_queue |
| 2483 |
for details. |
| 2484 |
.B |
| 2485 |
nfnetlink_queue |
| 2486 |
was added in Linux 2.6.14. The \fBqueue\-balance\fP option was added in Linux |
| 2487 |
2.6.31, |
| 2488 |
\fBqueue\-bypass\fP in 2.6.39. |
| 2489 |
.TP |
| 2490 |
\fB\-\-queue\-num\fP \fIvalue\fP |
| 2491 |
This specifies the QUEUE number to use. Valid queue numbers are 0 to 65535. The default value is 0. |
| 2492 |
.PP |
| 2493 |
.TP |
| 2494 |
\fB\-\-queue\-balance\fP \fIvalue\fP\fB:\fP\fIvalue\fP |
| 2495 |
This specifies a range of queues to use. Packets are then balanced across the given queues. |
| 2496 |
This is useful for multicore systems: start multiple instances of the userspace program on |
| 2497 |
queues x, x+1, .. x+n and use "\-\-queue\-balance \fIx\fP\fB:\fP\fIx+n\fP". |
| 2498 |
Packets belonging to the same connection are put into the same nfqueue. |
| 2499 |
Due to implementation details, a lower range value of 0 limits the higher range |
| 2500 |
value to 65534, i.e. one can only balance between at most 65535 queues. |
| 2501 |
.PP |
| 2502 |
.TP |
| 2503 |
\fB\-\-queue\-bypass\fP |
| 2504 |
By default, if no userspace program is listening on an NFQUEUE, then all packets that are to be queued |
| 2505 |
are dropped. When this option is used, the NFQUEUE rule behaves like ACCEPT instead, and the packet |
| 2506 |
will move on to the next table. |
| 2507 |
.PP |
| 2508 |
.TP |
| 2509 |
\fB\-\-queue\-cpu\-fanout\fP |
| 2510 |
Available starting Linux kernel 3.10. When used together with |
| 2511 |
\fB\-\-queue\-balance\fP this will use the CPU ID as an index to map packets to |
| 2512 |
the queues. The idea is that you can improve performance if there's a queue |
| 2513 |
per CPU. This requires \fB\-\-queue\-balance\fP to be specified. |
| 2514 |
.SS NOTRACK |
| 2515 |
This extension disables connection tracking for all packets matching that rule. |
| 2516 |
It is equivalent with \-j CT \-\-notrack. Like CT, NOTRACK can only be used in |
| 2517 |
the \fBraw\fP table. |
| 2518 |
.SS RATEEST |
| 2519 |
The RATEEST target collects statistics, performs rate estimation calculation |
| 2520 |
and saves the results for later evaluation using the \fBrateest\fP match. |
| 2521 |
.TP |
| 2522 |
\fB\-\-rateest\-name\fP \fIname\fP |
| 2523 |
Count matched packets into the pool referred to by \fIname\fP, which is freely |
| 2524 |
choosable. |
| 2525 |
.TP |
| 2526 |
\fB\-\-rateest\-interval\fP \fIamount\fP{\fBs\fP|\fBms\fP|\fBus\fP} |
| 2527 |
Rate measurement interval, in seconds, milliseconds or microseconds. |
| 2528 |
.TP |
| 2529 |
\fB\-\-rateest\-ewmalog\fP \fIvalue\fP |
| 2530 |
Rate measurement averaging time constant. |
| 2531 |
.SS REDIRECT |
| 2532 |
This target is only valid in the |
| 2533 |
.B nat |
| 2534 |
table, in the |
| 2535 |
.B PREROUTING |
| 2536 |
and |
| 2537 |
.B OUTPUT |
| 2538 |
chains, and user-defined chains which are only called from those |
| 2539 |
chains. It redirects the packet to the machine itself by changing the |
| 2540 |
destination IP to the primary address of the incoming interface |
| 2541 |
(locally-generated packets are mapped to the localhost address, |
| 2542 |
127.0.0.1 for IPv4 and ::1 for IPv6, and packets arriving on |
| 2543 |
interfaces that don't have an IP address configured are dropped). |
| 2544 |
.TP |
| 2545 |
\fB\-\-to\-ports\fP \fIport\fP[\fB\-\fP\fIport\fP] |
| 2546 |
This specifies a destination port or range of ports to use: without |
| 2547 |
this, the destination port is never altered. This is only valid |
| 2548 |
if the rule also specifies one of the following protocols: |
| 2549 |
\fBtcp\fP, \fBudp\fP, \fBdccp\fP or \fBsctp\fP. |
| 2550 |
For a single port, a service name as listed in \fB/etc/services\fP may be used. |
| 2551 |
.TP |
| 2552 |
\fB\-\-random\fP |
| 2553 |
Randomize source port mapping (kernel >= 2.6.22). |
| 2554 |
.TP |
| 2555 |
IPv6 support available starting Linux kernels >= 3.7. |
| 2556 |
.SS REJECT (IPv6-specific) |
| 2557 |
This is used to send back an error packet in response to the matched |
| 2558 |
packet: otherwise it is equivalent to |
| 2559 |
.B DROP |
| 2560 |
so it is a terminating TARGET, ending rule traversal. |
| 2561 |
This target is only valid in the |
| 2562 |
.BR INPUT , |
| 2563 |
.B FORWARD |
| 2564 |
and |
| 2565 |
.B OUTPUT |
| 2566 |
chains, and user-defined chains which are only called from those |
| 2567 |
chains. The following option controls the nature of the error packet |
| 2568 |
returned: |
| 2569 |
.TP |
| 2570 |
\fB\-\-reject\-with\fP \fItype\fP |
| 2571 |
The type given can be |
| 2572 |
\fBicmp6\-no\-route\fP, |
| 2573 |
\fBno\-route\fP, |
| 2574 |
\fBicmp6\-adm\-prohibited\fP, |
| 2575 |
\fBadm\-prohibited\fP, |
| 2576 |
\fBicmp6\-addr\-unreachable\fP, |
| 2577 |
\fBaddr\-unreach\fP, or |
| 2578 |
\fBicmp6\-port\-unreachable\fP, |
| 2579 |
which return the appropriate ICMPv6 error message (\fBicmp6\-port\-unreachable\fP is |
| 2580 |
the default). Finally, the option |
| 2581 |
\fBtcp\-reset\fP |
| 2582 |
can be used on rules which only match the TCP protocol: this causes a |
| 2583 |
TCP RST packet to be sent back. This is mainly useful for blocking |
| 2584 |
.I ident |
| 2585 |
(113/tcp) probes which frequently occur when sending mail to broken mail |
| 2586 |
hosts (which won't accept your mail otherwise). |
| 2587 |
\fBtcp\-reset\fP |
| 2588 |
can only be used with kernel versions 2.6.14 or later. |
| 2589 |
.PP |
| 2590 |
\fIWarning:\fP You should not indiscriminately apply the REJECT target to |
| 2591 |
packets whose connection state is classified as INVALID; instead, you should |
| 2592 |
only DROP these. |
| 2593 |
.PP |
| 2594 |
Consider a source host transmitting a packet P, with P experiencing so much |
| 2595 |
delay along its path that the source host issues a retransmission, P_2, with |
| 2596 |
P_2 being successful in reaching its destination and advancing the connection |
| 2597 |
state normally. It is conceivable that the late-arriving P may be considered |
| 2598 |
not to be associated with any connection tracking entry. Generating a reject |
| 2599 |
response for a packet so classed would then terminate the healthy connection. |
| 2600 |
.PP |
| 2601 |
So, instead of: |
| 2602 |
.PP |
| 2603 |
\-A INPUT ... \-j REJECT |
| 2604 |
.PP |
| 2605 |
do consider using: |
| 2606 |
.PP |
| 2607 |
\-A INPUT ... \-m conntrack \-\-ctstate INVALID \-j DROP |
| 2608 |
.br |
| 2609 |
\-A INPUT ... \-j REJECT |
| 2610 |
.SS REJECT (IPv4-specific) |
| 2611 |
This is used to send back an error packet in response to the matched |
| 2612 |
packet: otherwise it is equivalent to |
| 2613 |
.B DROP |
| 2614 |
so it is a terminating TARGET, ending rule traversal. |
| 2615 |
This target is only valid in the |
| 2616 |
.BR INPUT , |
| 2617 |
.B FORWARD |
| 2618 |
and |
| 2619 |
.B OUTPUT |
| 2620 |
chains, and user-defined chains which are only called from those |
| 2621 |
chains. The following option controls the nature of the error packet |
| 2622 |
returned: |
| 2623 |
.TP |
| 2624 |
\fB\-\-reject\-with\fP \fItype\fP |
| 2625 |
The type given can be |
| 2626 |
\fBicmp\-net\-unreachable\fP, |
| 2627 |
\fBicmp\-host\-unreachable\fP, |
| 2628 |
\fBicmp\-port\-unreachable\fP, |
| 2629 |
\fBicmp\-proto\-unreachable\fP, |
| 2630 |
\fBicmp\-net\-prohibited\fP, |
| 2631 |
\fBicmp\-host\-prohibited\fP, or |
| 2632 |
\fBicmp\-admin\-prohibited\fP (*), |
| 2633 |
which return the appropriate ICMP error message (\fBicmp\-port\-unreachable\fP is |
| 2634 |
the default). The option |
| 2635 |
\fBtcp\-reset\fP |
| 2636 |
can be used on rules which only match the TCP protocol: this causes a |
| 2637 |
TCP RST packet to be sent back. This is mainly useful for blocking |
| 2638 |
.I ident |
| 2639 |
(113/tcp) probes which frequently occur when sending mail to broken mail |
| 2640 |
hosts (which won't accept your mail otherwise). |
| 2641 |
.IP |
| 2642 |
(*) Using icmp\-admin\-prohibited with kernels that do not support it will result in a plain DROP instead of REJECT |
| 2643 |
.PP |
| 2644 |
\fIWarning:\fP You should not indiscriminately apply the REJECT target to |
| 2645 |
packets whose connection state is classified as INVALID; instead, you should |
| 2646 |
only DROP these. |
| 2647 |
.PP |
| 2648 |
Consider a source host transmitting a packet P, with P experiencing so much |
| 2649 |
delay along its path that the source host issues a retransmission, P_2, with |
| 2650 |
P_2 being successful in reaching its destination and advancing the connection |
| 2651 |
state normally. It is conceivable that the late-arriving P may be considered |
| 2652 |
not to be associated with any connection tracking entry. Generating a reject |
| 2653 |
response for a packet so classed would then terminate the healthy connection. |
| 2654 |
.PP |
| 2655 |
So, instead of: |
| 2656 |
.PP |
| 2657 |
\-A INPUT ... \-j REJECT |
| 2658 |
.PP |
| 2659 |
do consider using: |
| 2660 |
.PP |
| 2661 |
\-A INPUT ... \-m conntrack \-\-ctstate INVALID \-j DROP |
| 2662 |
.br |
| 2663 |
\-A INPUT ... \-j REJECT |
| 2664 |
.SS SECMARK |
| 2665 |
This is used to set the security mark value associated with the |
| 2666 |
packet for use by security subsystems such as SELinux. It is |
| 2667 |
valid in the |
| 2668 |
.B security |
| 2669 |
table (for backwards compatibility with older kernels, it is also |
| 2670 |
valid in the |
| 2671 |
.B mangle |
| 2672 |
table). The mark is 32 bits wide. |
| 2673 |
.TP |
| 2674 |
\fB\-\-selctx\fP \fIsecurity_context\fP |
| 2675 |
.SS SET |
| 2676 |
This module adds and/or deletes entries from IP sets which can be defined |
| 2677 |
by ipset(8). |
| 2678 |
.TP |
| 2679 |
\fB\-\-add\-set\fP \fIsetname\fP \fIflag\fP[\fB,\fP\fIflag\fP...] |
| 2680 |
add the address(es)/port(s) of the packet to the set |
| 2681 |
.TP |
| 2682 |
\fB\-\-del\-set\fP \fIsetname\fP \fIflag\fP[\fB,\fP\fIflag\fP...] |
| 2683 |
delete the address(es)/port(s) of the packet from the set |
| 2684 |
.TP |
| 2685 |
\fB\-\-map\-set\fP \fIsetname\fP \fIflag\fP[\fB,\fP\fIflag\fP...] |
| 2686 |
[\-\-map\-mark] [\-\-map\-prio] [\-\-map\-queue] |
| 2687 |
map packet properties (firewall mark, tc priority, hardware queue) |
| 2688 |
.IP |
| 2689 |
where \fIflag\fP(s) are |
| 2690 |
.BR "src" |
| 2691 |
and/or |
| 2692 |
.BR "dst" |
| 2693 |
specifications and there can be no more than six of them. |
| 2694 |
.TP |
| 2695 |
\fB\-\-timeout\fP \fIvalue\fP |
| 2696 |
when adding an entry, the timeout value to use instead of the default |
| 2697 |
one from the set definition |
| 2698 |
.TP |
| 2699 |
\fB\-\-exist\fP |
| 2700 |
when adding an entry if it already exists, reset the timeout value |
| 2701 |
to the specified one or to the default from the set definition |
| 2702 |
.TP |
| 2703 |
\fB\-\-map\-set\fP \fIset-name\fP |
| 2704 |
the set-name should be created with \-\-skbinfo option |
| 2705 |
\fB\-\-map\-mark\fP |
| 2706 |
map firewall mark to packet by lookup of value in the set |
| 2707 |
\fB\-\-map\-prio\fP |
| 2708 |
map traffic control priority to packet by lookup of value in the set |
| 2709 |
\fB\-\-map\-queue\fP |
| 2710 |
map hardware NIC queue to packet by lookup of value in the set |
| 2711 |
.IP |
| 2712 |
The |
| 2713 |
\fB\-\-map\-set\fP |
| 2714 |
option can be used from the mangle table only. The |
| 2715 |
\fB\-\-map\-prio\fP |
| 2716 |
and |
| 2717 |
\fB\-\-map\-queue\fP |
| 2718 |
flags can be used in the OUTPUT, FORWARD and POSTROUTING chains. |
| 2719 |
.PP |
| 2720 |
Use of \-j SET requires that ipset kernel support is provided, which, for |
| 2721 |
standard kernels, is the case since Linux 2.6.39. |
| 2722 |
.SS SNAT |
| 2723 |
This target is only valid in the |
| 2724 |
.B nat |
| 2725 |
table, in the |
| 2726 |
.B POSTROUTING |
| 2727 |
and |
| 2728 |
.B INPUT |
| 2729 |
chains, and user-defined chains which are only called from those |
| 2730 |
chains. It specifies that the source address of the packet should be |
| 2731 |
modified (and all future packets in this connection will also be |
| 2732 |
mangled), and rules should cease being examined. It takes the |
| 2733 |
following options: |
| 2734 |
.TP |
| 2735 |
\fB\-\-to\-source\fP [\fIipaddr\fP[\fB\-\fP\fIipaddr\fP]][\fB:\fP\fIport\fP[\fB\-\fP\fIport\fP]] |
| 2736 |
which can specify a single new source IP address, an inclusive range |
| 2737 |
of IP addresses. Optionally a port range, |
| 2738 |
if the rule also specifies one of the following protocols: |
| 2739 |
\fBtcp\fP, \fBudp\fP, \fBdccp\fP or \fBsctp\fP. |
| 2740 |
If no port range is specified, then source ports below 512 will be |
| 2741 |
mapped to other ports below 512: those between 512 and 1023 inclusive |
| 2742 |
will be mapped to ports below 1024, and other ports will be mapped to |
| 2743 |
1024 or above. Where possible, no port alteration will occur. |
| 2744 |
.TP |
| 2745 |
\fB\-\-random\fP |
| 2746 |
Randomize source port mapping through a hash-based algorithm (kernel >= 2.6.21). |
| 2747 |
.TP |
| 2748 |
\fB\-\-random\-fully\fP |
| 2749 |
Fully randomize source port mapping through a PRNG (kernel >= 3.14). |
| 2750 |
.TP |
| 2751 |
\fB\-\-persistent\fP |
| 2752 |
Gives a client the same source-/destination-address for each connection. |
| 2753 |
This supersedes the SAME target. Support for persistent mappings is available |
| 2754 |
from 2.6.29-rc2. |
| 2755 |
.PP |
| 2756 |
Kernels prior to 2.6.36-rc1 don't have the ability to |
| 2757 |
.B SNAT |
| 2758 |
in the |
| 2759 |
.B INPUT |
| 2760 |
chain. |
| 2761 |
.TP |
| 2762 |
IPv6 support available since Linux kernels >= 3.7. |
| 2763 |
.SS SNPT (IPv6-specific) |
| 2764 |
Provides stateless source IPv6-to-IPv6 Network Prefix Translation (as described |
| 2765 |
by RFC 6296). |
| 2766 |
.PP |
| 2767 |
You have to use this target in the |
| 2768 |
.B mangle |
| 2769 |
table, not in the |
| 2770 |
.B nat |
| 2771 |
table. It takes the following options: |
| 2772 |
.TP |
| 2773 |
\fB\-\-src\-pfx\fP [\fIprefix/\fP\fIlength] |
| 2774 |
Set source prefix that you want to translate and length |
| 2775 |
.TP |
| 2776 |
\fB\-\-dst\-pfx\fP [\fIprefix/\fP\fIlength] |
| 2777 |
Set destination prefix that you want to use in the translation and length |
| 2778 |
.PP |
| 2779 |
You have to use the DNPT target to undo the translation. Example: |
| 2780 |
.IP |
| 2781 |
ip6tables \-t mangle \-I POSTROUTING \-s fd00::/64 ! \-o vboxnet0 |
| 2782 |
\-j SNPT \-\-src-pfx fd00::/64 \-\-dst-pfx 2001:e20:2000:40f::/64 |
| 2783 |
.IP |
| 2784 |
ip6tables \-t mangle \-I PREROUTING \-i wlan0 \-d 2001:e20:2000:40f::/64 |
| 2785 |
\-j DNPT \-\-src-pfx 2001:e20:2000:40f::/64 \-\-dst\-pfx fd00::/64 |
| 2786 |
.PP |
| 2787 |
You may need to enable IPv6 neighbor proxy: |
| 2788 |
.IP |
| 2789 |
sysctl \-w net.ipv6.conf.all.proxy_ndp=1 |
| 2790 |
.PP |
| 2791 |
You also have to use the |
| 2792 |
.B NOTRACK |
| 2793 |
target to disable connection tracking for translated flows. |
| 2794 |
.SS SYNPROXY |
| 2795 |
This target will process TCP three-way-handshake parallel in netfilter |
| 2796 |
context to protect either local or backend system. This target requires |
| 2797 |
connection tracking because sequence numbers need to be translated. |
| 2798 |
The kernels ability to absorb SYNFLOOD was greatly improved starting with |
| 2799 |
Linux 4.4, so this target should not be needed anymore to protect Linux servers. |
| 2800 |
.TP |
| 2801 |
\fB\-\-mss\fP \fImaximum segment size\fP |
| 2802 |
Maximum segment size announced to clients. This must match the backend. |
| 2803 |
.TP |
| 2804 |
\fB\-\-wscale\fP \fIwindow scale\fP |
| 2805 |
Window scale announced to clients. This must match the backend. |
| 2806 |
.TP |
| 2807 |
\fB\-\-sack\-perm\fP |
| 2808 |
Pass client selective acknowledgement option to backend (will be disabled |
| 2809 |
if not present). |
| 2810 |
.TP |
| 2811 |
\fB\-\-timestamps\fP |
| 2812 |
Pass client timestamp option to backend (will be disabled if not present, |
| 2813 |
also needed for selective acknowledgement and window scaling). |
| 2814 |
.PP |
| 2815 |
Example: |
| 2816 |
.PP |
| 2817 |
Determine tcp options used by backend, from an external system |
| 2818 |
.IP |
| 2819 |
tcpdump \-pni eth0 \-c 1 'tcp[tcpflags] == (tcp\-syn|tcp\-ack)' |
| 2820 |
.br |
| 2821 |
port 80 & |
| 2822 |
.br |
| 2823 |
telnet 192.0.2.42 80 |
| 2824 |
.br |
| 2825 |
18:57:24.693307 IP 192.0.2.42.80 > 192.0.2.43.48757: |
| 2826 |
.br |
| 2827 |
Flags [S.], seq 360414582, ack 788841994, win 14480, |
| 2828 |
.br |
| 2829 |
options [mss 1460,sackOK, |
| 2830 |
.br |
| 2831 |
TS val 1409056151 ecr 9690221, |
| 2832 |
.br |
| 2833 |
nop,wscale 9], |
| 2834 |
.br |
| 2835 |
length 0 |
| 2836 |
.PP |
| 2837 |
Switch tcp_loose mode off, so conntrack will mark out-of-flow |
| 2838 |
packets as state INVALID. |
| 2839 |
.IP |
| 2840 |
echo 0 > /proc/sys/net/netfilter/nf_conntrack_tcp_loose |
| 2841 |
.PP |
| 2842 |
Make SYN packets untracked |
| 2843 |
.IP |
| 2844 |
iptables \-t raw \-A PREROUTING \-i eth0 \-p tcp \-\-dport 80 |
| 2845 |
\-\-syn \-j CT \-\-notrack |
| 2846 |
.PP |
| 2847 |
Catch UNTRACKED (SYN packets) and INVALID (3WHS ACK packets) states |
| 2848 |
and send them to SYNPROXY. This rule will respond to SYN packets with |
| 2849 |
SYN+ACK syncookies, create ESTABLISHED for valid client response (3WHS ACK |
| 2850 |
packets) and drop incorrect cookies. Flags combinations not expected |
| 2851 |
during 3WHS will not match and continue (e.g. SYN+FIN, SYN+ACK). |
| 2852 |
.IP |
| 2853 |
iptables \-A INPUT \-i eth0 \-p tcp \-\-dport 80 |
| 2854 |
\-m state \-\-state UNTRACKED,INVALID \-j SYNPROXY |
| 2855 |
\-\-sack\-perm \-\-timestamp \-\-mss 1460 \-\-wscale 9 |
| 2856 |
.PP |
| 2857 |
Drop invalid packets, this will be out\-of\-flow packets that were not |
| 2858 |
matched by SYNPROXY. |
| 2859 |
.IP |
| 2860 |
iptables \-A INPUT \-i eth0 \-p tcp \-\-dport 80 \-m state \-\-state INVALID \-j DROP |
| 2861 |
.SS TCPMSS |
| 2862 |
This target alters the MSS value of TCP SYN packets, to control |
| 2863 |
the maximum size for that connection (usually limiting it to your |
| 2864 |
outgoing interface's MTU minus 40 for IPv4 or 60 for IPv6, respectively). |
| 2865 |
Of course, it can only be used |
| 2866 |
in conjunction with |
| 2867 |
\fB\-p tcp\fP. |
| 2868 |
.PP |
| 2869 |
This target is used to overcome criminally braindead ISPs or servers |
| 2870 |
which block "ICMP Fragmentation Needed" or "ICMPv6 Packet Too Big" |
| 2871 |
packets. The symptoms of this |
| 2872 |
problem are that everything works fine from your Linux |
| 2873 |
firewall/router, but machines behind it can never exchange large |
| 2874 |
packets: |
| 2875 |
.IP 1. 4 |
| 2876 |
Web browsers connect, then hang with no data received. |
| 2877 |
.IP 2. 4 |
| 2878 |
Small mail works fine, but large emails hang. |
| 2879 |
.IP 3. 4 |
| 2880 |
ssh works fine, but scp hangs after initial handshaking. |
| 2881 |
.PP |
| 2882 |
Workaround: activate this option and add a rule to your firewall |
| 2883 |
configuration like: |
| 2884 |
.IP |
| 2885 |
iptables \-t mangle \-A FORWARD \-p tcp \-\-tcp\-flags SYN,RST SYN |
| 2886 |
\-j TCPMSS \-\-clamp\-mss\-to\-pmtu |
| 2887 |
.TP |
| 2888 |
\fB\-\-set\-mss\fP \fIvalue\fP |
| 2889 |
Explicitly sets MSS option to specified value. If the MSS of the packet is |
| 2890 |
already lower than \fIvalue\fP, it will \fBnot\fP be increased (from Linux |
| 2891 |
2.6.25 onwards) to avoid more problems with hosts relying on a proper MSS. |
| 2892 |
.TP |
| 2893 |
\fB\-\-clamp\-mss\-to\-pmtu\fP |
| 2894 |
Automatically clamp MSS value to (path_MTU \- 40 for IPv4; \-60 for IPv6). |
| 2895 |
This may not function as desired where asymmetric routes with differing |
| 2896 |
path MTU exist \(em the kernel uses the path MTU which it would use to send |
| 2897 |
packets from itself to the source and destination IP addresses. Prior to |
| 2898 |
Linux 2.6.25, only the path MTU to the destination IP address was |
| 2899 |
considered by this option; subsequent kernels also consider the path MTU |
| 2900 |
to the source IP address. |
| 2901 |
.PP |
| 2902 |
These options are mutually exclusive. |
| 2903 |
.SS TCPOPTSTRIP |
| 2904 |
This target will strip TCP options off a TCP packet. (It will actually replace |
| 2905 |
them by NO-OPs.) As such, you will need to add the \fB\-p tcp\fP parameters. |
| 2906 |
.TP |
| 2907 |
\fB\-\-strip\-options\fP \fIoption\fP[\fB,\fP\fIoption\fP...] |
| 2908 |
Strip the given option(s). The options may be specified by TCP option number or |
| 2909 |
by symbolic name. The list of recognized options can be obtained by calling |
| 2910 |
iptables with \fB\-j TCPOPTSTRIP \-h\fP. |
| 2911 |
.SS TEE |
| 2912 |
The \fBTEE\fP target will clone a packet and redirect this clone to another |
| 2913 |
machine on the \fBlocal\fP network segment. In other words, the nexthop |
| 2914 |
must be the target, or you will have to configure the nexthop to forward it |
| 2915 |
further if so desired. |
| 2916 |
.TP |
| 2917 |
\fB\-\-gateway\fP \fIipaddr\fP |
| 2918 |
Send the cloned packet to the host reachable at the given IP address. |
| 2919 |
Use of 0.0.0.0 (for IPv4 packets) or :: (IPv6) is invalid. |
| 2920 |
.PP |
| 2921 |
To forward all incoming traffic on eth0 to an Network Layer logging box: |
| 2922 |
.PP |
| 2923 |
\-t mangle \-A PREROUTING \-i eth0 \-j TEE \-\-gateway 2001:db8::1 |
| 2924 |
.SS TOS |
| 2925 |
This module sets the Type of Service field in the IPv4 header (including the |
| 2926 |
"precedence" bits) or the Priority field in the IPv6 header. Note that TOS |
| 2927 |
shares the same bits as DSCP and ECN. The TOS target is only valid in the |
| 2928 |
\fBmangle\fP table. |
| 2929 |
.TP |
| 2930 |
\fB\-\-set\-tos\fP \fIvalue\fP[\fB/\fP\fImask\fP] |
| 2931 |
Zeroes out the bits given by \fImask\fP (see NOTE below) and XORs \fIvalue\fP |
| 2932 |
into the TOS/Priority field. If \fImask\fP is omitted, 0xFF is assumed. |
| 2933 |
.TP |
| 2934 |
\fB\-\-set\-tos\fP \fIsymbol\fP |
| 2935 |
You can specify a symbolic name when using the TOS target for IPv4. It implies |
| 2936 |
a mask of 0xFF (see NOTE below). The list of recognized TOS names can be |
| 2937 |
obtained by calling iptables with \fB\-j TOS \-h\fP. |
| 2938 |
.PP |
| 2939 |
The following mnemonics are available: |
| 2940 |
.TP |
| 2941 |
\fB\-\-and\-tos\fP \fIbits\fP |
| 2942 |
Binary AND the TOS value with \fIbits\fP. (Mnemonic for \fB\-\-set\-tos |
| 2943 |
0/\fP\fIinvbits\fP, where \fIinvbits\fP is the binary negation of \fIbits\fP. |
| 2944 |
See NOTE below.) |
| 2945 |
.TP |
| 2946 |
\fB\-\-or\-tos\fP \fIbits\fP |
| 2947 |
Binary OR the TOS value with \fIbits\fP. (Mnemonic for \fB\-\-set\-tos\fP |
| 2948 |
\fIbits\fP\fB/\fP\fIbits\fP. See NOTE below.) |
| 2949 |
.TP |
| 2950 |
\fB\-\-xor\-tos\fP \fIbits\fP |
| 2951 |
Binary XOR the TOS value with \fIbits\fP. (Mnemonic for \fB\-\-set\-tos\fP |
| 2952 |
\fIbits\fP\fB/0\fP. See NOTE below.) |
| 2953 |
.PP |
| 2954 |
NOTE: In Linux kernels up to and including 2.6.38, with the exception of |
| 2955 |
longterm releases 2.6.32 (>=.42), 2.6.33 (>=.15), and 2.6.35 (>=.14), there is |
| 2956 |
a bug whereby IPv6 TOS mangling does not behave as documented and differs from |
| 2957 |
the IPv4 version. The TOS mask indicates the bits one wants to zero out, so it |
| 2958 |
needs to be inverted before applying it to the original TOS field. However, the |
| 2959 |
aforementioned kernels forgo the inversion which breaks \-\-set\-tos and its |
| 2960 |
mnemonics. |
| 2961 |
.SS TPROXY |
| 2962 |
This target is only valid in the \fBmangle\fP table, in the \fBPREROUTING\fP |
| 2963 |
chain and user-defined chains which are only called from this chain. It |
| 2964 |
redirects the packet to a local socket without changing the packet header in |
| 2965 |
any way. It can also change the mark value which can then be used in advanced |
| 2966 |
routing rules. |
| 2967 |
It takes three options: |
| 2968 |
.TP |
| 2969 |
\fB\-\-on\-port\fP \fIport\fP |
| 2970 |
This specifies a destination port to use. It is a required option, 0 means the |
| 2971 |
new destination port is the same as the original. This is only valid if the |
| 2972 |
rule also specifies \fB\-p tcp\fP or \fB\-p udp\fP. |
| 2973 |
.TP |
| 2974 |
\fB\-\-on\-ip\fP \fIaddress\fP |
| 2975 |
This specifies a destination address to use. By default the address is the IP |
| 2976 |
address of the incoming interface. This is only valid if the rule also |
| 2977 |
specifies \fB\-p tcp\fP or \fB\-p udp\fP. |
| 2978 |
.TP |
| 2979 |
\fB\-\-tproxy\-mark\fP \fIvalue\fP[\fB/\fP\fImask\fP] |
| 2980 |
Marks packets with the given value/mask. The fwmark value set here can be used |
| 2981 |
by advanced routing. (Required for transparent proxying to work: otherwise |
| 2982 |
these packets will get forwarded, which is probably not what you want.) |
| 2983 |
.SS TRACE |
| 2984 |
This target marks packets so that the kernel will log every rule which match |
| 2985 |
the packets as those traverse the tables, chains, rules. It can only be used in |
| 2986 |
the |
| 2987 |
.BR raw |
| 2988 |
table. |
| 2989 |
.PP |
| 2990 |
With iptables-legacy, a logging backend, such as ip(6)t_LOG or nfnetlink_log, |
| 2991 |
must be loaded for this to be visible. |
| 2992 |
The packets are logged with the string prefix: |
| 2993 |
"TRACE: tablename:chainname:type:rulenum " where type can be "rule" for |
| 2994 |
plain rule, "return" for implicit rule at the end of a user defined chain |
| 2995 |
and "policy" for the policy of the built in chains. |
| 2996 |
.PP |
| 2997 |
With iptables-nft, the target is translated into nftables' |
| 2998 |
.B "meta nftrace" |
| 2999 |
expression. Hence the kernel sends trace events via netlink to userspace where |
| 3000 |
they may be displayed using |
| 3001 |
.B "xtables\-monitor \-\-trace" |
| 3002 |
command. For details, refer to |
| 3003 |
.BR xtables\-monitor (8). |
| 3004 |
.SS TTL (IPv4-specific) |
| 3005 |
This is used to modify the IPv4 TTL header field. The TTL field determines |
| 3006 |
how many hops (routers) a packet can traverse until it's time to live is |
| 3007 |
exceeded. |
| 3008 |
.PP |
| 3009 |
Setting or incrementing the TTL field can potentially be very dangerous, |
| 3010 |
so it should be avoided at any cost. This target is only valid in |
| 3011 |
.B mangle |
| 3012 |
table. |
| 3013 |
.PP |
| 3014 |
.B Don't ever set or increment the value on packets that leave your local network! |
| 3015 |
.TP |
| 3016 |
\fB\-\-ttl\-set\fP \fIvalue\fP |
| 3017 |
Set the TTL value to `value'. |
| 3018 |
.TP |
| 3019 |
\fB\-\-ttl\-dec\fP \fIvalue\fP |
| 3020 |
Decrement the TTL value `value' times. |
| 3021 |
.TP |
| 3022 |
\fB\-\-ttl\-inc\fP \fIvalue\fP |
| 3023 |
Increment the TTL value `value' times. |
| 3024 |
.SS ULOG (IPv4-specific) |
| 3025 |
This is the deprecated IPv4-only predecessor of the NFLOG target. |
| 3026 |
It provides userspace logging of matching packets. When this |
| 3027 |
target is set for a rule, the Linux kernel will multicast this packet |
| 3028 |
through a |
| 3029 |
.IR netlink |
| 3030 |
socket. One or more userspace processes may then subscribe to various |
| 3031 |
multicast groups and receive the packets. |
| 3032 |
Like LOG, this is a "non-terminating target", i.e. rule traversal |
| 3033 |
continues at the next rule. |
| 3034 |
.TP |
| 3035 |
\fB\-\-ulog\-nlgroup\fP \fInlgroup\fP |
| 3036 |
This specifies the netlink group (1\(en32) to which the packet is sent. |
| 3037 |
Default value is 1. |
| 3038 |
.TP |
| 3039 |
\fB\-\-ulog\-prefix\fP \fIprefix\fP |
| 3040 |
Prefix log messages with the specified prefix; up to 32 characters |
| 3041 |
long, and useful for distinguishing messages in the logs. |
| 3042 |
.TP |
| 3043 |
\fB\-\-ulog\-cprange\fP \fIsize\fP |
| 3044 |
Number of bytes to be copied to userspace. A value of 0 always copies |
| 3045 |
the entire packet, regardless of its size. Default is 0. |
| 3046 |
.TP |
| 3047 |
\fB\-\-ulog\-qthreshold\fP \fIsize\fP |
| 3048 |
Number of packet to queue inside kernel. Setting this value to, e.g. 10 |
| 3049 |
accumulates ten packets inside the kernel and transmits them as one |
| 3050 |
netlink multipart message to userspace. Default is 1 (for backwards |
| 3051 |
compatibility). |
| 3052 |
.br |