Iptables-1.1.9 Guide (Classic) (5)

Source: Internet
Author: User
Iptables-1.1.9 Guide (Classic) (5)-Linux Enterprise Application-Linux server application information, which is described below. When iptables is used, if the required parameters are not input, press enter, and the system will prompt you with the following information: What parameters are required, and so on. The iptables option-v is used to display the iptables version.-h provides a brief description of the syntax .. The following describes some options and their functions.

Table 6-3. Options
Option (Option)-v, -- verbose (detailed)
Command -- list, -- append, -- insert, -- delete, -- replace
This option details the output and is often used with -- list. When connected to -- list, the output includes the network interface address, rule options, TOS mask, bytes, and package counters, the counter is in the unit of K, M, and G (here the power of 10 is used instead of the power of 2. If you want to know how many packages and how many bytes are there, you also need to use option-x, which will be described below. If-v is used with -- append, -- insert, -- delete, or -- replace, iptables will output detailed information to show you how the rule is interpreted, and whether it is correctly inserted.
Option-x, -- exact (exact)
Commands used with -- list
The Explanation enables the counters in the -- list output to display accurate values instead of the values such as K, M, and G. Note that this option can only be used with -- list.
Option-n, -- numeric (numerical value)
Commands used with -- list
Explanation displays the IP addresses and ports in the output as numerical values instead of default names, such as host names, network names, and program names. Note that this option can only be used with -- list.
Option -- line-numbers
Commands used with -- list
Explanation is an option that can only be used with -- list. It displays the sequence numbers of each rule in the corresponding chain. This allows you to know the serial number, which is useful for inserting new rules.
Option-c, -- set-counters
Commands used with -- insert, -- append, -- replace
Explanation sets a counter when creating or changing a rule. The syntax is as follows: -- set-counters 20 4000, which means that the kernel sets the package counter to 20 and the byte counter to 4000.
Option -- modprobe
Commands used with All
Explanation this option tells iptables to detect and load the module to be used. This is a very useful option. In case the modprobe command is not in the search path, it will be used. With this option, iptables knows to search even if a module is not loaded.
6.4. Matches

In this section, we will discuss matche in detail and I will classify them into five categories. The first type is generic matches (general-purpose matching), which applies to all rules. The second type is TCP matches, which can only be used for TCP packets, and the third type is UDP matches, of course, it can only be used on UDP packets; the fourth class is ICMP matches, for ICMP packets; the fifth class is special, for the status, owner) and the frequency limit of access (limit), they have been divided into more small classes, although they are not completely different. I hope this is a classification that is easy to understand.
6.4.1. General match

No matter what protocols we use or what extensions we mount with matching, generic matching is available. That is to say, they can be used directly without any precondition. Later, you will see that many matching operations require other matching as the precondition.

Table 6-4. Generic matches
Match-p, -- protocol
Example iptables-a input-p tcp
The description matches the specified protocol. The format of the specified protocol is as follows:

1. The name is case-insensitive, but must be defined in/etc/protocols.

2. You can use the corresponding integer values. For example, the values of ICMP are 1, TCP is 6, and UDP is 17.

3. The default value is "ALL". The corresponding value is 0. Note that this parameter only matches TCP, UDP, and ICMP, rather than ALL protocols defined in/etc/protocols.

4. The protocol list can be separated by commas (,), for example, udp or tcp.

5. You can add an English exclamation point before the protocol to reverse the request. Note that there are spaces, such as -- protocol! Tcp indicates non-tcp protocol, that is, UDP and ICMP. We can see that the range of this inversion is TCP, UDP, and ICMP.
Match-s, -- src, -- source
Example iptables-a input-s 192.168.1.1
The Explanation matches the package with the IP source address. The address format is as follows:

1. A single address, such as 192.168.1.1, can also be written as 192.168.1.1/255.255.255.255 or 192.168.1.1/32.

2. network, such as 192.168.0.0/24 or 192.168.0.0/255.255.255.0

3. Add an English exclamation mark (exclamation mark) before the address to return an inverse sign. Pay attention to spaces, such as -- source! 192.168.0.0/24 indicates all other addresses.

4. All addresses by default
Match-d, -- dst, -- destination
Example iptables-a input-d 192.168.1.1
The description matches the package with the IP address. The address format is exactly the same as -- source.
Match-I, -- in-interface
Example iptables-a input-I eth0
Explanation matches the package with the network interface used by the package to enter the local device. Note that this matching operation can only be used for the INPUT, FORWARD, and PREROUTING links. If it is used elsewhere, an error message is prompted. The specified interface has the following methods:

1. Specify the interface name, such as eth0 and ppp0.

2. Use a wildcard, that is, the English plus sign, which represents a string of characters and numbers. If you use A plus sign, iptables-a input-I +, to match all packages, you do not need to consider which interface to use. This is also the default action without specifying an interface. Wildcard characters can also be placed behind a certain type of interface. For example, eth + indicates all Ethernet interfaces, that is, matching all packets that enter from the Ethernet interface.

3. Add an English exclamation point before the interface to return an inverse sign. Pay attention to spaces, such as-I! Eth0 indicates matching all packages except eth0.
Match-o, -- out-interface
Example iptables-a forward-o eth0
The Explanation matches the package with the network interface used by the package to exit the local device. The range used and the method of the specified interface are exactly the same as that of -- in-interface.
Match-f, -- fragment
Example iptables-a input-f
Explanation is used to match the second or later parts of a fragmented package. Because they do not contain information such as the source or destination address, or ICMP type, other rules cannot match it, so this matching operation is available. Pay attention to fragment attacks. This operation can also contain an English exclamation mark (Exclamation point), but pay attention to the position, such :! -F. When the image is reversed, it indicates that only the unsharded package or the first shard of the package to be split can be matched, and neither of the later parts can be matched. Currently, the kernel has a complete fragment reorganization function to prevent fragment attacks, so you do not need to use the reverse function to prevent fragment from passing through. If you use Connection Tracing, you will not see any fragments, because they are processed before they reach any chain.
6.4.2. Implicit match

This matching operation is automatically or implicitly loaded into the kernel. For example, when we use -- protocol tcp, we can match some features that only the IP package has without loading anything. Three implicit matching protocols are available for TCP matches, UDP matches, and ICMP matches. They respectively include a set of criteria applicable only to the corresponding protocols. Compared with implicit matching, explicit matching is required. They must be explicitly loaded using-m or -- match, rather than automatically or implicitly. The next section will introduce them.
6.4.2.1. TCP matches

TCP matches can only match the details of TCP packets or streams. They must have -- protocol tcp as the precondition.

Table 6-5. TCP matches
Match -- sport, -- source-port
Example iptables-a input-p tcp -- sport 22
The Explanation matches the packet based on the source port of the TCP packet. The port is specified as follows:

1. If this option is not specified, all ports are indicated.

2. Use the service name or port number, but the name must be defined in/etc/services, because iptables searches for the corresponding port number from this file. From this we can see that using the port number will make the rule load a little faster, of course, the readability is worse. But if you want to write a rule set containing 200 or more rules, you should use the port number honestly, time is the main factor (on a host that is a little slow, it may be 10 seconds at most, but if it is 1000 or 10000 ).

3. You can use continuous ports, such as -- source-port 22: 80. This indicates all ports from 22 to 80, including 22 and 80. It does not matter if the order of the two numbers is reversed, for example, -- source-port 80: 22, which has the same effect as -- source-port 22: 80.

4. The first number can be omitted. The first number is 0 by default. For example, -- source-port: 80 indicates all ports from 0 to 80.

5. You can also omit the second number. The default value is 65535. For example, -- source-port 22: indicates all ports from 22 to 65535.

6. Add an English exclamation point in front of the port number to return an inverse sign. Pay attention to spaces, for example, -- source-port! 22 indicates all ports except 22nd; -- source-port! 22: 80 indicates all ports from 22 to 80 (including 22 and 80.

Note: This matching operation cannot identify the list of discontinuous ports, for example, -- source-port! Operations such as 22, 36, and 80 are completed by the multi-port matching extension described later.
Match -- dport, -- destination-port
Example iptables-A I

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.