此内容没有您所选择的语言版本。
48.9.3. Command Options for IPTables
Rules for filtering packets are created using the
iptables
command. The following aspects of the packet are most often used as criteria:
- Packet Type — Specifies the type of packets the command filters.
- Packet Source/Destination — Specifies which packets the command filters based on the source or destination of the packet.
- Target — Specifies what action is taken on packets matching the above criteria.
Refer to Section 48.9.3.4, “IPTables Match Options” and Section 48.9.3.5, “Target Options” for more information about specific options that address these aspects of a packet.
The options used with specific
iptables
rules must be grouped logically, based on the purpose and conditions of the overall rule, for the rule to be valid. The remainder of this section explains commonly-used options for the iptables
command.
48.9.3.1. Structure of IPTables Command Options
Many
iptables
commands have the following structure:
iptables [-t <table-name>] <command> <chain-name> \ <parameter-1> <option-1> \ <parameter-n> <option-n>
<table-name> — Specifies which table the rule applies to. If omitted, the
filter
table is used.
<command> — Specifies the action to perform, such as appending or deleting a rule.
<chain-name> — Specifies the chain to edit, create, or delete.
<parameter>-<option> pairs — Parameters and associated options that specify how to process a packet that matches the rule.
The length and complexity of an
iptables
command can change significantly, based on its purpose.
For example, a command to remove a rule from a chain can be very short:
iptables -D <chain-name> <line-number>
In contrast, a command that adds a rule which filters packets from a particular subnet using a variety of specific parameters and options can be rather long. When constructing
iptables
commands, it is important to remember that some parameters and options require further parameters and options to construct a valid rule. This can produce a cascading effect, with the further parameters requiring yet more parameters. Until every parameter and option that requires another set of options is satisfied, the rule is not valid.
Type
iptables -h
to view a comprehensive list of iptables
command structures.