linux命令 iptables,ip6tables linux防火墙帮助文档

来源于centos 7 iptables帮助文档

译文

命令名
iptables / ip6tables-用于IPv4 / IPv6数据包过滤和NAT的管理工具

概要
iptables [-t table] {-A|-C|-D} chain rule-specification

ip6tables [-t table] {-A|-C|-D} chain rule-specification

iptables [-t table] -I chain [rulenum] rule-specification

iptables [-t table] -R chain rulenum rule-specification

iptables [-t table] -D chain rulenum

iptables [-t table] -S [chain [rulenum]]

iptables [-t table] {-F|-L|-Z} [chain [rulenum]] [options…]

iptables [-t table] -N chain

iptables [-t table] -X [chain]

iptables [-t table] -P chain target

iptables [-t table] -E old-chain-name new-chain-name

rule-specification = [matches…] [target]

match = -m matchname [per-match-options]

target = -j targetname [per-target-options]

描述
iptables和ip6tables用于在Linux内核中设置,维护和检查IPv4和IPv6数据包过滤器规则表。 可以定义几个不同的表。 每个表包含许多内置链,也可能包含用户定义的链。

每个链都是可以匹配一组数据包的规则列表。 每个规则都指定如何处理匹配的数据包。 这称为“目标”,它可以跳转到同一表中用户定义的链。

目标
防火墙规则指定数据包和目标的条件。 如果数据包不匹配,则检查链中的下一个规则。 如果匹配,则下一个规则由目标值指定,该值可以是用户定义链的名称,iptables-extensions(8)中描述的目标之一或特殊值ACCEPT ,DROP 或RETURN。

ACCEPT表示让数据包通过。 DROP意味着将数据包丢弃。 RETURN表示停止遍历此链,并在上一个(调用)链中的下一个规则处恢复。 如果到达内置链的末尾或匹配目标为RETURN的内置链中的规则,则链策略指定的目标将确定数据包的命运。


当前有五个独立的表(哪个表随时存在取决于内核配置选项和哪个模块存在)。

-t,–table 表
此选项指定命令应在其上操作的数据包匹配表。如果为内核配置了自动模块加载功能,那么将尝试为该表加载适当的模块(如果该模块尚不存在)。

列表如下:

filter:
这是默认表(如果未传递-t选项)。它包含内置链INPUT(用于发往本地套接字的数据包),FORWARD(用于通过盒子路由的数据包)和OUTPUT(用于本地生成的数据包)。

nat:
当遇到创建新连接的数据包时,请查阅此表。它由三个内置组件组成:PREROUTING(用于在进入后立即更改数据包),OUTPUT(用于在路由之前更改本地生成的数据包)和POSTROUTING(用于在即将外出时更改数据包)。从内核3.7开始提供IPv6 NAT支持。

mangle:
该表用于专门的数据包更改。在内核2.4.17之前,它具有两个内置链:PREROUTING(用于在路由之前更改传入的数据包)和OUTPUT(用于在路由之前更改本地生成的数据包)。从内核2.4.18开始,还支持其他三个内置链:INPUT(用于进入盒本身的数据包),FORWARD(用于改变通过盒路由的数据包)和POSTROUTING(用于改变即将到来的数据包)出去)。

raw:
该表主要用于配置NOTRACK目标与连接跟踪的豁免。它在较高优先级的netfilter钩子处注册,因此在ip_conntrack或任何其他IP表之前被调用。它提供以下内置链:PREROUTING(用于通过任何网络接口到达的数据包)OUTPUT(用于由本地进程生成的数据包)

security:
该表用于强制访问控制(MAC)网络规则,例如由SECMARK和CONNSECMARK目标启用的规则。强制访问控制由Linux安全模块(例如SELinux)实现。在过滤器表之后调用安全表,从而使过滤器表中的任何自由访问控制(DAC)规则在MAC规则之前生效。该表提供以下内置链:INPUT(用于进入盒子的数据包),OUTPUT(用于在路由之前更改本地生成的数据包)和FORWARD(用于改变通过盒子路由的数据包)。


选项
iptables和ip6tables可以识别的选项可以分为几个不同的组。

指令
这些选项指定要执行的所需动作。除非下面另有说明,否则只能在命令行上指定其中之一。对于较长版本的命令和选项名称,您只需要使用足够的字母以确保iptables可以将其与所有其他选项区分开。

-A,-append chain rule-specification
将一个或多个规则附加到所选链的末尾。当源名称和/或目标名称解析为多个地址时,将为每种可能的地址组合添加一条规则。

-C,-check chain rule-specification
检查所选链中是否存在与规格匹配的规则。此命令使用与-D相同的逻辑来查找匹配的条目,但不会更改现有iptables配置,并使用其退出代码指示成功或失败。

-D,-delete chain rule-specification
-D,-delete chain rulenum
从所选链中删除一个或多个规则。此命令有两种版本:规则可以指定为链中的数字(第一个规则从1开始)或匹配的规则。

-I,-insert chain [rulenum] rule-specification
在所选链中插入一个或多个规则作为给定的规则编号。因此,如果规则编号为1,则将一个或多个规则插入到链的开头。如果未指定规则编号,这也是默认值。

-R,-replace chain rulenum rule-specification
替换所选链中的规则。如果源名称和/或目标名称解析为多个地址,该命令将失败。规则从1开始编号。

-L,-list [chain]
列出所选链中的所有规则。如果未选择链,则列出所有链。与其他所有iptables命令一样,它适用于指定的表(默认为过滤器),因此NAT规则由
iptables -t nat -n -L
请注意,它通常与-n选项一起使用,以避免长时间反向DNS查找。同时指定-Z(零)选项也是合法的,在这种情况下,将自动列出链并将其清零。
确切的输出受其他给定参数的影响。确切的规则被抑制,直到您使用
iptables -L -v

-S,-list-rules [chain]
打印选定链中的所有规则。如果未选择任何链,则所有链都将像iptables-save一样打印。与其他所有iptables命令一样,它适用于指定的表(默认为filter)。

-F,-flush [chain]
冲洗选定的链(如果没有给出表中的所有链)。这等效于删除所有规则。

-Z,–zero [chain [rulenum]]
将所有链或仅给定链或仅给定规则的包和字节计数器清零。还要指定-L,–list(list)选项,以便在清除计数器之前立即查看它们是合法的。 (往上看。)

-N,–new-chain chain
通过给定名称创建一个新的用户定义链。该名称必须已经没有目标。

-X,–delete-chain [chain]
删除指定的可选用户定义链。不得引用该链。如果存在,则必须删除或替换引用规则,然后才能删除链。链必须为空,即不包含任何规则。如果未提供任何参数,它将尝试删除表中的每个非内置链。

-P,-policy chain target
将链的策略设置为给定的目标。有关法律目标,请参阅“目标”部分。只有内置(非用户定义)链可以具有策略,内置链和用户定义链都不能成为策略目标。

-E,–rename-chain old-chain new-chain
将用户指定的链重命名为用户提供的名称。这是化妆品,对桌子的结构没有影响。

-h Help。提供命令语法的描述(当前非常简短)。

参数
以下参数构成规则规范(在添加,删除,插入,替换和附加命令中使用)。

-4,-ipv4
此选项在iptables和iptables-restore中无效。如果使用-4选项的规则与ip6tables-restore一起插入(并且仅与ip6tables-restore一起插入),它将被忽略。任何其他用途都会引发错误。此选项允许将IPv4和IPv6规则都放在一个规则文件中,以与iptables-restore和ip6tables-restore一起使用。

-6,-ipv6
如果使用-6选项的规则与iptables-restore一起插入(并且仅与iptables-restore一起插入),它将被忽略。任何其他用途都会引发错误。此选项允许将IPv4和IPv6规则都放在单个规则文件中,以与iptables-restore和ip6tables-restore一起使用。此选项在ip6tables和ip6tables-restore中无效。

[!] -p,–protocol协议
要检查的规则或数据包的协议。指定的协议可以是tcp,udp,udplite,icmp,icmpv6,esp,ah,sctp,mh之一或特殊关键字“ all”,也可以是代表这些协议之一或不同协议的数字值。还允许/ etc / protocols中的协议名称。使用一个 ”!”反转协议测试之前的参数。数字零等于全部。 “ all”将与所有协议匹配,并且在忽略此选项时将其作为默认值。请注意,在ip6tables中,不允许使用除esp之外的IPv6扩展头。 esp和ipv6-nonext可以与2.6.11或更高版本的内核一起使用。数字零等于全部,这意味着您不能直接测试协议字段的值0。要匹配HBH标头,即使它是最后一个,也不能使用-p 0,但始终需要-m hbh。

[!] -s,-source address[/ mask] [,…]
源规范。地址可以是网络名称,主机名,网络IP地址(带有/ mask)或纯IP地址。在将规则提交给内核之前,主机名将仅被解析一次。请注意,指定要通过远程查询(例如DNS)解析的任何名称都是一个糟糕的主意。该掩码可以是ipv4网络掩码(用于iptables)或纯数字,指定网络掩码的左侧第一个数。因此,iptables掩码为24等于255.255.255.0。使用一个 ”!”会反转地址规范之前的参数地址的含义。标志–src是此选项的别名。可以指定多个地址,但这将扩展为多个规则(使用-A添加时),或者将导致删除多个规则(使用-D)。

[!] -d,-destination address[/ mask] [,…]
目标规范。有关语法的详细说明,请参见-s(source address)标志的说明。标志–dst是此选项的别名。

-m,–match match
指定要使用的匹配项,即测试特定属性的扩展模块。匹配集构成了调用目标的条件。匹配将按照命令行中的指定从头到尾进行评估,并且以短路方式工作,即,如果一个扩展名产生false,则评估将停止。

-j,–jump target
这指定了规则的目标;即,如果数据包匹配,该怎么办。目标可以是用户定义的链(此规则所在的链除外),可以立即确定数据包命运的特殊内置目标之一,也可以是扩展(请参见下面的“扩展”)。如果在规则中省略了此选项(并且未使用-g),则匹配规则将对数据包的命运没有影响,但是规则上的计数器将增加。

-g,–goto chain
这指定处理应按用户指定的链继续进行。与–jump选项不同,return将不在此链中继续处理,而是在通过–jump调用我们的链中继续处理。

[!] -i,–in-interface name
接收数据包所经过的接口的名称(仅适用于进入INPUT,FORWARD和PREROUTING链的数据包)。如果在接口名称的参数前使用“!”,则含义相反。如果接口名称以“ +”结尾,则以该名称开头的任何接口都将匹配。如果省略此选项,则任何接口名称都将匹配。

[!] -o,–out-interface name
数据包将通过其发送的接口的名称(对于进入FORWARD,OUTPUT和POSTROUTING链的数据包)。如果在接口名称的参数前使用“!”,则含义相反。如果接口名称以“ +”结尾,则任何以该名称开头的接口都将匹配。如果省略此选项,则任何接口名称都将匹配。

[!] -f,–fragment
这意味着该规则仅引用分段数据包的第二个和其他IPv4片段。由于无法告知此类数据包(或ICMP类型)的源端口或目标端口,因此此类数据包将不匹配任何指定它们的规则。如果在“-f”前使用“!”,该规则将仅匹配头片段或未分段的数据包。此选项特定于IPv4,在ip6tables中不可用。

-c,–set-counters packets bytes
这使管理员能够初始化规则的包和字节计数器(在INSERT,APPEND,REPLACE操作期间)。


其他选择
可以指定以下附加选项:

-v,–verbose
详细输出。此选项使list命令显示接口名称,规则选项(如果有)和TOS掩码。还列出了数据包和字节计数器,其后缀分别为1000,1,000,000和1,000,000,000乘数的后缀“K”,“M”或“G”(但请参见-x标志进行更改)。对于追加,插入,删除和替换,这将导致打印有关一个或多个规则的详细信息。可以多次指定-v以发出更详细的调试语句。

-w,-wait [seconds]
等待xtables锁定。为了防止程序的多个实例同时运行,将尝试在启动时获取排他锁。默认情况下,如果无法获得锁,则程序将退出。此选项将使程序等待(无限期或可选秒),直到获得排他锁。

-W,–wait-interval microseconds
每次迭代等待的时间间隔。运行对延迟敏感的应用程序时,长时间等待xtables锁定可能是不可接受的。此选项将使每次迭代花费指定的时间。默认间隔为1秒。该选项仅与-w一起使用。

-n,–numeric
数值输出。 IP地址和端口号将以数字格式打印。默认情况下,程序将尝试将它们显示为主机名,网络名或服务(如果适用)。

-x,–exact
展开数字。显示数据包和字节计数器的确切值,而不是仅舍入以K(1000的倍数),M(1000K的倍数)或G(1000M的倍数)的舍入数。此选项仅与-L命令有关。

–line-numbers
列出规则时,将行号添加到每个规则的开头,对应于该规则在链中的位置。

–modprobe=command
在将规则添加或插入到链中时,请使用命令来加载任何必要的模块(目标,匹配扩展名等)。

匹配和目标扩展
iptables可以使用扩展的数据包匹配和目标模块。 iptables-extensions(8)联机帮助页中提供了这些列表。

诊断
将各种错误消息打印为标准错误。 退出代码为0,表示功能正常。 看来是由无效或滥用命令行参数引起的错误导致退出代码为2,其他错误导致退出代码为1。

BUGS
BUGS? What’s this? ;-)好吧,您可能想看看http://bugzilla.netfilter.org/

与IPCHAIN的兼容性
该iptables与Rusty Russell的ipchains非常相似。主要区别在于,仅针对进入本地主机且分别来自本地主机的数据包遍历链INPUT和OUTPUT。
因此,每个数据包仅通过三个链之一(环回流量除外,后者涉及INPUT和OUTPUT链);以前,转发的数据包将通过所有三个。

另一个主要区别是-i表示输入接口; -o表示输出接口,并且两者都可用于进入FORWARD链的数据包。

NAT的各种形式已被分离出来。 iptables是使用默认`filter’表和可选扩展模块时的纯数据包过滤器。与IP伪装和数据包过滤的组合相比,这应该可以简化以前的许多混乱情况。因此,以下选项的处理方式有所不同:
-j MASQ
-M -S
-M -L
iptables还有其他一些变化。
也可以看看
iptables-apply(8),iptables-save(8),iptables-restore(8),iptables-extensions(8),

packet-filtering-HOWTO详细介绍了iptables用于数据包过滤的用法,NAT-HOWTO详细介绍了NAT,netfilter-extensions-HOWTO详细介绍了标准分发版中没有的扩展,netfilter-hacking-HOWTO详细介绍了netfilter内部。请参阅http://www.netfilter.org/。

作者
Rusty Russell最初是在与Michael Neuling协商后编写iptables的。

Marc Boucher游说在iptables中使用通用数据包选择框架,从而使Rusty放弃了ipnatctl,然后编写了mangle表,所有者匹配,标记内容,然后到处闲逛。

詹姆斯·莫里斯(James Morris)撰写了TOS目标,并进行了比赛。

Jozsef Kadlecsik编写了REJECT目标。

Harald Welte编写了ULOG和NFQUEUE目标,新的libiptc以及TTL,DSCP,ECN匹配项和目标。

Netfilter核心团队是:Marc Boucher,Martin Josefsson,Yasuyuki Kozakai,Jozsef Kadlecsik,Patrick McHardy,James Morris,Pablo Neira Ayuso,Harald Welte和Rusty Russell。

手册页最初由Herve Eychenne rv@wallfire.org编写。

版本
本手册页适用于iptables / ip6tables @ PACKAGE_AND_VERSION @。

原文

NAME
iptables/ip6tables — administration tool for IPv4/IPv6 packet filtering and NAT

SYNOPSIS
iptables [-t table] {-A|-C|-D} chain rule-specification

ip6tables [-t table] {-A|-C|-D} chain rule-specification

iptables [-t table] -I chain [rulenum] rule-specification

iptables [-t table] -R chain rulenum rule-specification

iptables [-t table] -D chain rulenum

iptables [-t table] -S [chain [rulenum]]

iptables [-t table] {-F|-L|-Z} [chain [rulenum]] [options…]

iptables [-t table] -N chain

iptables [-t table] -X [chain]

iptables [-t table] -P chain target

iptables [-t table] -E old-chain-name new-chain-name

rule-specification = [matches…] [target]

match = -m matchname [per-match-options]

target = -j targetname [per-target-options]
DESCRIPTION
Iptables and ip6tables are used to set up, maintain, and inspect the tables of IPv4 and IPv6 packet filter rules in the Linux kernel. Several different tables may be defined. Each table contains a number of built-in chains
and may also contain user-defined chains.

Each chain is a list of rules which can match a set of packets. Each rule specifies what to do with a packet that matches. This is called a `target’, which may be a jump to a user-defined chain in the same table.

TARGETS
A firewall rule specifies criteria for a packet and a target. If the packet does not match, the next rule in the chain is examined; if it does match, then the next rule is specified by the value of the target, which can be the
name of a user-defined chain, one of the targets described in iptables-extensions(8), or one of the special values ACCEPT, DROP or RETURN.

ACCEPT means to let the packet through. DROP means to drop the packet on the floor. RETURN means stop traversing this chain and resume at the next rule in the previous (calling) chain. If the end of a built-in chain is
reached or a rule in a built-in chain with target RETURN is matched, the target specified by the chain policy determines the fate of the packet.

TABLES
There are currently five independent tables (which tables are present at any time depends on the kernel configuration options and which modules are present).

-t, --table table
This option specifies the packet matching table which the command should operate on. If the kernel is configured with automatic module loading, an attempt will be made to load the appropriate module for that table if it
is not already there.

The tables are as follows:

filter:
This is the default table (if no -t option is passed). It contains the built-in chains INPUT (for packets destined to local sockets), FORWARD (for packets being routed through the box), and OUTPUT (for locally-gener‐
ated packets).

nat:
This table is consulted when a packet that creates a new connection is encountered. It consists of three built-ins: PREROUTING (for altering packets as soon as they come in), OUTPUT (for altering locally-generated
packets before routing), and POSTROUTING (for altering packets as they are about to go out). IPv6 NAT support is available since kernel 3.7.

mangle:
This table is used for specialized packet alteration. Until kernel 2.4.17 it had two built-in chains: PREROUTING (for altering incoming packets before routing) and OUTPUT (for altering locally-generated packets
before routing). Since kernel 2.4.18, three other built-in chains are also supported: INPUT (for packets coming into the box itself), FORWARD (for altering packets being routed through the box), and POSTROUTING (for
altering packets as they are about to go out).

raw:
This table is used mainly for configuring exemptions from connection tracking in combination with the NOTRACK target. It registers at the netfilter hooks with higher priority and is thus called before ip_conntrack,
or any other IP tables. It provides the following built-in chains: PREROUTING (for packets arriving via any network interface) OUTPUT (for packets generated by local processes)

security:
This table is used for Mandatory Access Control (MAC) networking rules, such as those enabled by the SECMARK and CONNSECMARK targets. Mandatory Access Control is implemented by Linux Security Modules such as
SELinux. The security table is called after the filter table, allowing any Discretionary Access Control (DAC) rules in the filter table to take effect before MAC rules. This table provides the following built-in
chains: INPUT (for packets coming into the box itself), OUTPUT (for altering locally-generated packets before routing), and FORWARD (for altering packets being routed through the box).

OPTIONS
The options that are recognized by iptables and ip6tables can be divided into several different groups.

COMMANDS
These options specify the desired action to perform. Only one of them can be specified on the command line unless otherwise stated below. For long versions of the command and option names, you need to use only enough letters to
ensure that iptables can differentiate it from all other options.

-A, --append chain rule-specification
Append one or more rules to the end of the selected chain. When the source and/or destination names resolve to more than one address, a rule will be added for each possible address combination.

-C, --check chain rule-specification
Check whether a rule matching the specification does exist in the selected chain. This command uses the same logic as -D to find a matching entry, but does not alter the existing iptables configuration and uses its exit
code to indicate success or failure.

-D, --delete chain rule-specification
-D, --delete chain rulenum
Delete one or more rules from the selected chain. There are two versions of this command: the rule can be specified as a number in the chain (starting at 1 for the first rule) or a rule to match.

-I, --insert chain [rulenum] rule-specification
Insert one or more rules in the selected chain as the given rule number. So, if the rule number is 1, the rule or rules are inserted at the head of the chain. This is also the default if no rule number is specified.

-R, --replace chain rulenum rule-specification
Replace a rule in the selected chain. If the source and/or destination names resolve to multiple addresses, the command will fail. Rules are numbered starting at 1.

-L, --list [chain]
List all rules in the selected chain. If no chain is selected, all chains are listed. Like every other iptables command, it applies to the specified table (filter is the default), so NAT rules get listed by
iptables -t nat -n -L
Please note that it is often used with the -n option, in order to avoid long reverse DNS lookups. It is legal to specify the -Z (zero) option as well, in which case the chain(s) will be atomically listed and zeroed.
The exact output is affected by the other arguments given. The exact rules are suppressed until you use
iptables -L -v

-S, --list-rules [chain]
Print all rules in the selected chain. If no chain is selected, all chains are printed like iptables-save. Like every other iptables command, it applies to the specified table (filter is the default).

-F, --flush [chain]
Flush the selected chain (all the chains in the table if none is given). This is equivalent to deleting all the rules one by one.

-Z, --zero [chain [rulenum]]
Zero the packet and byte counters in all chains, or only the given chain, or only the given rule in a chain. It is legal to specify the -L, --list (list) option as well, to see the counters immediately before they are
cleared. (See above.)

-N, --new-chain chain
Create a new user-defined chain by the given name. There must be no target of that name already.

-X, --delete-chain [chain]
Delete the optional user-defined chain specified. There must be no references to the chain. If there are, you must delete or replace the referring rules before the chain can be deleted. The chain must be empty, i.e.
not contain any rules. If no argument is given, it will attempt to delete every non-builtin chain in the table.

-P, --policy chain target
Set the policy for the chain to the given target. See the section TARGETS for the legal targets. Only built-in (non-user-defined) chains can have policies, and neither built-in nor user-defined chains can be policy
targets.

-E, --rename-chain old-chain new-chain
Rename the user specified chain to the user supplied name. This is cosmetic, and has no effect on the structure of the table.

-h Help. Give a (currently very brief) description of the command syntax.

PARAMETERS
The following parameters make up a rule specification (as used in the add, delete, insert, replace and append commands).

-4, --ipv4
This option has no effect in iptables and iptables-restore. If a rule using the -4 option is inserted with (and only with) ip6tables-restore, it will be silently ignored. Any other uses will throw an error. This option
allows to put both IPv4 and IPv6 rules in a single rule file for use with both iptables-restore and ip6tables-restore.

-6, --ipv6
If a rule using the -6 option is inserted with (and only with) iptables-restore, it will be silently ignored. Any other uses will throw an error. This option allows to put both IPv4 and IPv6 rules in a single rule file
for use with both iptables-restore and ip6tables-restore. This option has no effect in ip6tables and ip6tables-restore.

[!] -p, --protocol protocol
The protocol of the rule or of the packet to check. The specified protocol can be one of tcp, udp, udplite, icmp, icmpv6,esp, ah, sctp, mh or the special keyword “all”, or it can be a numeric value, representing one of
these protocols or a different one. A protocol name from /etc/protocols is also allowed. A “!” argument before the protocol inverts the test. The number zero is equivalent to all. “all” will match with all protocols
and is taken as default when this option is omitted. Note that, in ip6tables, IPv6 extension headers except esp are not allowed. esp and ipv6-nonext can be used with Kernel version 2.6.11 or later. The number zero is
equivalent to all, which means that you cannot test the protocol field for the value 0 directly. To match on a HBH header, even if it were the last, you cannot use -p 0, but always need -m hbh.

[!] -s, --source address[/mask][,…]
Source specification. Address can be either a network name, a hostname, a network IP address (with /mask), or a plain IP address. Hostnames will be resolved once only, before the rule is submitted to the kernel. Please
note that specifying any name to be resolved with a remote query such as DNS is a really bad idea. The mask can be either an ipv4 network mask (for iptables) or a plain number, specifying the number of 1’s at the left
side of the network mask. Thus, an iptables mask of 24 is equivalent to 255.255.255.0. A “!” argument before the address specification inverts the sense of the address. The flag --src is an alias for this option. Mul‐
tiple addresses can be specified, but this will expand to multiple rules (when adding with -A), or will cause multiple rules to be deleted (with -D).

[!] -d, --destination address[/mask][,…]
Destination specification. See the description of the -s (source) flag for a detailed description of the syntax. The flag --dst is an alias for this option.

-m, --match match
Specifies a match to use, that is, an extension module that tests for a specific property. The set of matches make up the condition under which a target is invoked. Matches are evaluated first to last as specified on the
command line and work in short-circuit fashion, i.e. if one extension yields false, evaluation will stop.

-j, --jump target
This specifies the target of the rule; i.e., what to do if the packet matches it. The target can be a user-defined chain (other than the one this rule is in), one of the special builtin targets which decide the fate of
the packet immediately, or an extension (see EXTENSIONS below). If this option is omitted in a rule (and -g is not used), then matching the rule will have no effect on the packet’s fate, but the counters on the rule
will be incremented.

-g, --goto chain
This specifies that the processing should continue in a user specified chain. Unlike the --jump option return will not continue processing in this chain but instead in the chain that called us via --jump.

[!] -i, --in-interface name
Name of an interface via which a packet was received (only for packets entering the INPUT, FORWARD and PREROUTING chains). When the “!” argument is used before the interface name, the sense is inverted. If the inter‐
face name ends in a “+”, then any interface which begins with this name will match. If this option is omitted, any interface name will match.

[!] -o, --out-interface name
Name of an interface via which a packet is going to be sent (for packets entering the FORWARD, OUTPUT and POSTROUTING chains). When the “!” argument is used before the interface name, the sense is inverted. If the
interface name ends in a “+”, then any interface which begins with this name will match. If this option is omitted, any interface name will match.

[!] -f, --fragment
This means that the rule only refers to second and further IPv4 fragments of fragmented packets. Since there is no way to tell the source or destination ports of such a packet (or ICMP type), such a packet will not
match any rules which specify them. When the “!” argument precedes the “-f” flag, the rule will only match head fragments, or unfragmented packets. This option is IPv4 specific, it is not available in ip6tables.

-c, --set-counters packets bytes
This enables the administrator to initialize the packet and byte counters of a rule (during INSERT, APPEND, REPLACE operations).

OTHER OPTIONS
The following additional options can be specified:

-v, --verbose
Verbose output. This option makes the list command show the interface name, the rule options (if any), and the TOS masks. The packet and byte counters are also listed, with the suffix ‘K’, ‘M’ or ‘G’ for 1000,
1,000,000 and 1,000,000,000 multipliers respectively (but see the -x flag to change this). For appending, insertion, deletion and replacement, this causes detailed information on the rule or rules to be printed. -v may
be specified multiple times to possibly emit more detailed debug statements.

-w, --wait [seconds]
Wait for the xtables lock. To prevent multiple instances of the program from running concurrently, an attempt will be made to obtain an exclusive lock at launch. By default, the program will exit if the lock cannot be
obtained. This option will make the program wait (indefinitely or for optional seconds) until the exclusive lock can be obtained.

-W, --wait-interval microseconds
Interval to wait per each iteration. When running latency sensitive applications, waiting for the xtables lock for extended durations may not be acceptable. This option will make each iteration take the amount of time
specified. The default interval is 1 second. This option only works with -w.

-n, --numeric
Numeric output. IP addresses and port numbers will be printed in numeric format. By default, the program will try to display them as host names, network names, or services (whenever applicable).

-x, --exact
Expand numbers. Display the exact value of the packet and byte counters, instead of only the rounded number in K’s (multiples of 1000) M’s (multiples of 1000K) or G’s (multiples of 1000M). This option is only relevant
for the -L command.

–line-numbers
When listing rules, add line numbers to the beginning of each rule, corresponding to that rule’s position in the chain.

–modprobe=command
When adding or inserting rules into a chain, use command to load any necessary modules (targets, match extensions, etc).

MATCH AND TARGET EXTENSIONS
iptables can use extended packet matching and target modules. A list of these is available in the iptables-extensions(8) manpage.

DIAGNOSTICS
Various error messages are printed to standard error. The exit code is 0 for correct functioning. Errors which appear to be caused by invalid or abused command line parameters cause an exit code of 2, and other errors cause
an exit code of 1.

BUGS
Bugs? What’s this? ? Well, you might want to have a look at http://bugzilla.netfilter.org/

COMPATIBILITY WITH IPCHAINS
This iptables is very similar to ipchains by Rusty Russell. The main difference is that the chains INPUT and OUTPUT are only traversed for packets coming into the local host and originating from the local host respectively.
Hence every packet only passes through one of the three chains (except loopback traffic, which involves both INPUT and OUTPUT chains); previously a forwarded packet would pass through all three.

The other main difference is that -i refers to the input interface; -o refers to the output interface, and both are available for packets entering the FORWARD chain.

The various forms of NAT have been separated out; iptables is a pure packet filter when using the default `filter’ table, with optional extension modules. This should simplify much of the previous confusion over the combina‐
tion of IP masquerading and packet filtering seen previously. So the following options are handled differently:
-j MASQ
-M -S
-M -L
There are several other changes in iptables.

SEE ALSO
iptables-apply(8), iptables-save(8), iptables-restore(8), iptables-extensions(8),

The packet-filtering-HOWTO details iptables usage for packet filtering, the NAT-HOWTO details NAT, the netfilter-extensions-HOWTO details the extensions that are not in the standard distribution, and the netfilter-hacking-HOWTO
details the netfilter internals.
See http://www.netfilter.org/.

AUTHORS
Rusty Russell originally wrote iptables, in early consultation with Michael Neuling.

Marc Boucher made Rusty abandon ipnatctl by lobbying for a generic packet selection framework in iptables, then wrote the mangle table, the owner match, the mark stuff, and ran around doing cool stuff everywhere.

James Morris wrote the TOS target, and tos match.

Jozsef Kadlecsik wrote the REJECT target.

Harald Welte wrote the ULOG and NFQUEUE target, the new libiptc, as well as the TTL, DSCP, ECN matches and targets.

The Netfilter Core Team is: Marc Boucher, Martin Josefsson, Yasuyuki Kozakai, Jozsef Kadlecsik, Patrick McHardy, James Morris, Pablo Neira Ayuso, Harald Welte and Rusty Russell.

Man page originally written by Herve Eychenne rv@wallfire.org.

VERSION
This manual page applies to iptables/ip6tables @PACKAGE_AND_VERSION@.