- o [!]interface-name
Specifies the interface on which the datagram is to be transmitted. This argument has the same coding as the -i argument.
[!] -f
Specifies that this rule applies only to the second and later fragments of a fragmented datagram, not to the first fragment.
The following iptables options are more general in nature. Some of them control rather esoteric features of the netfilter software.
- 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.
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 -m name argument to iptables. The following list shows the -m and -p options that set up the extension's context, and the options provided by that extension.
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 - -sport option.
- -tcp-flags [!] mask comp
Specifies that this rule should match when the TCP flags in the datagram match those specified by mask and comp . mask is a comma-separated list of flags that should be examined when making the test. comp is a comma-separated list of flags that must be set for the rule to match. Valid flags are: SYN , ACK , FIN , RST , URG , PSH , ALL or NONE . This is an advanced option: refer to a good description of the TCP protocol, such as RFC-793, for a description of the meaning and implication of each of these flags. The! character negates the rule.
[!] - -syn
Specifies the rule to match only datagrams with the SYN bit set and the ACK and FIN bits cleared. Datagrams with these options are used to open TCP connections, and this option can therefore be used to manage connection requests. This option is shorthand for:
- -tcp-flags SYN,RST,ACK SYN
When you use the negation operator, the rule will match all datagrams that do not have both the SYN and ACK bits set.
UDP Extensions: used with -m udp -p udp
- -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 describes 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 - -sport option.
ICMP Extensions: used with -m icmp -p icmp
- -icmp-type [!] typename
Specifies the ICMP message type that this rule will match. The type may be specified by number or name. Some valid names are: echo-request, echo-reply, source-quench, time-exceeded, destination-unreachable, network-unreachable, host-unreachable, protocol-unreachable, and port-unreachable.
MAC Extensions: used with -m mac
- -mac-source [!] address
Specifies the host's Ethernet address that transmitted the datagram that this rule will match. This only makes sense in a rule in the input or forward chains because we will be transmitting any datagram that passes the output chain.
Our Naïve Example Revisited, Yet Again
To implement our naïve example using the netfilter , you could simply load the ipchains.o module and pretend it is the ipchains version. Instead, we'll reimplement it using iptables to illustrate how similar it is.
Yet again, let's suppose that we have a network in our organization and that we are using a Linux-based firewall machine to allow our users to be able to access WWW servers on the Internet, but to allow no other traffic to be passed.
If our network has a 24-bit network mask (class C) and has an address of 172.16.1.0, then we'd use the following iptables rules:
# modprobe ip_tables
# iptables -F FORWARD
# iptables -P FORWARD DROP
# iptables -A FORWARD -m tcp -p tcp -s 0/0 -sport 80 -d 172.16.1.0/24 /
-syn -j DROP
# iptables -A FORWARD -m tcp -p tcp -s 172.16.1.0/24 -sport /
80 -d 0/0 -j ACCEPT
# iptables -A FORWARD -m tcp -p tcp -d 172.16.1.0/24 -dport 80 -s 0/0 -j /
ACCEPT
In this example the iptables commands are interpreted exactly as the equivalent ipchains commands. The major exception that the ip_tables.o module must load. Note that iptables doesn't support the -b option, so we must supply a rule for each direction.
The Type Of Service (TOS) bits are a set of four-bit flags in the IP header. When any one of these bit flags is set, routers may handle the datagram differently than datagrams with no TOS bits set. Each of the four bits has a different purpose and only one of the TOS bits may be set at any time, so combinations are not allowed. The bit flags are called Type of Service bits because they enable the application transmitting the data to tell the network the type of network service it requires.
The classes of network service available are:
Minimum delay
Used when the time it takes for a datagram to travel from the source host to destination host (latency) is most important. A network provider might, for example, use both optical fiber and satellite network connections. Data carried across satellite connections has farther to travel and their latency is generally therefore higher than for terrestrial-based network connections between the same endpoints. A network provider might choose to ensure that datagrams with this type of service set are not carried by satellite.
Maximum throughput
Used when the volume of data transmitted in any period of time is important. There are many types of network applications for which latency is not particularly important but the network throughput is; for example, bulk-file transfers. A network provider might choose to route datagrams with this type of service set via high-latency, high-bandwidth routes, such as satellite connections.
Maximum reliability
Used when it is important that you have some certainty that the data will arrive at the destination without retransmission being required. The IP protocol may be carried over any number of underlying transmission mediums. While SLIP and PPP are adequate datalink protocols, they are not as reliable as carrying IP over some other network, such as an X.25 network. A network provider might make an alternate network available, offering high reliability, to carry IP that would be used if this type of service is selected.
Читать дальше