- Z [chain]
Zero the datagram and byte counters for all rules of the specified chain, or for all chains if no chain is specified.
- N chain
Create a new chain with the specified name. A chain of the same name must not already exist. This is how user-defined chains are created.
- X [chain]
Delete the specified user-defined chain, or all user-defined chains if no chain is specified. For this command to be successful, there must be no references to the specified chain from any other rules chain.
- P chain policy
Set the default policy of the specified chain to the specified policy. Valid firewalling policies are ACCEPT, DROP, QUEUE, and RETURN. ACCEPT allows the datagram to pass. DROP causes the datagram to be discarded. QUEUE causes the datagram to be passed to userspace for further processing. The RETURN target causes the IP firewall code to return to the Firewall Chain that called the one containing this rule, and continue starting at the rule after the calling rule.
Rule specification parameters
There are a number of iptables parameters that constitute a rule specification. Wherever a rule specification is required, each of these parameters must be supplied or their default will be assumed.
- p [!]protocol
Specifies the protocol of the datagram that will match this rule. Valid protocol names are tcp, udp, icmp, or a number, if you know the IP protocol number.[64] For example, you might use 4 to match the ipip encapsulation protocol. If the! character is supplied, the rule is negated and the datagram will match any protocol other than the specified protocol. If this parameter isn't supplied, it will default to match all protocols.
- s [!]address[/mask]
Specifies the source address of the datagram that will match this rule. The address may be supplied as a hostname, a network name, or an IP address. The optional mask is the netmask to use and may be supplied either in the traditional form (e.g., /255.255.255.0) or in the modern form (e.g., /24).
- d [!]address[/mask]
Specifies the destination address and port of the datagram that will match this rule. The coding of this parameter is the same as that of the
- j target
Specifies what action to take when this rule matches. You can think of this parameter as meaning 'jump to.' Valid targets are ACCEPT, DROP, QUEUE, and RETURN. We described the meanings of each of these previously in the 'Commands' section. You may also specify the name of a user-defined chain where processing will continue. You may also supply the name of a target supplied by an extension. We'll talk about extensions shortly. If this parameter is omitted, no action is taken on matching datagrams at all, other than to update the datagram and byte counters of this rule.
- i [!]interface-name
Specifies the interface on which the datagram was received. Again, the! inverts the result of the match. If the interface name ends with ' + ' then any interface that begins with the supplied string will match. For example, -i ppp+ would match any PPP network device and -i! eth+ would match all interfaces except ethernet devices.
- o [!]interface-name
Specifies the interface on which the datagram is to be transmitted. This argument has the same coding as the
[!] -f
Specifies that this rule applies only to the second and later fragments of a fragmented datagram, not to the first fragment.
Options
The following iptables options are more general in nature. Some of them control rather esoteric features of the
- v
causes iptables to be verbose in its output; it will supply more information.
- n
causes iptables to display IP address and ports as numbers without attempting to resolve them to their corresponding names.
- x
causes any numbers in the iptables output to be expanded to their exact values with no rounding.
- -line-numbers
causes line numbers to be displayed when listing rulesets. The line number will correspond to the rule's position within the chain.
Extensions
We said earlier that the iptables utility is extensible through optional shared library modules. There are some standard extensions that provide some of the features ipchains provided. To make use of an extension, you must specify its name through the
TCP Extensions: used with -m tcp -p tcp
- -sport [!] [port[:port]]
Specifies the port that the datagram source must be using to match this rule. Ports may be specified as a range by specifying the upper and lower limits of the range using the colon as a delimiter. For example, 20:25 described all of the ports numbered 20 up to and including 25. Again, the! character may be used to negate the values.
- -dport [!] [port[:port]]
Specifies the port that the datagram destination must be using to match this rule. The argument is coded identically to the
- -tcp-flags [!] mask comp
Specifies that this rule should match when the TCP flags in the datagram match those specified by
