Oskar Andreasson - Iptables Tutorial 1.2.2 Страница 20
- Категория: Компьютеры и Интернет / Интернет
- Автор: Oskar Andreasson
- Год выпуска: неизвестен
- ISBN: нет данных
- Издательство: неизвестно
- Страниц: 50
- Добавлено: 2019-06-19 12:57:40
Oskar Andreasson - Iptables Tutorial 1.2.2 краткое содержание
Прочтите описание перед тем, как прочитать онлайн книгу «Oskar Andreasson - Iptables Tutorial 1.2.2» бесплатно полную версию:Oskar Andreasson - Iptables Tutorial 1.2.2 читать онлайн бесплатно
Below is the list of chunk types that the --chunk-types match will recognize. The list is quite extensive as you can see, but the mostly used packets are DATA and SACK packets. The rest are mostly used for controlling the association.
SCTP Chunk types as used in --chunk-types
• ABORT
• ASCONF
• ASCONF_ACK
• COOKIE_ACK
• COOKIE_ECHO
• DATA
• ECN_CWR
• ECN_ECNE
• ERROR
• HEARTBEAT
• HEARTBEAT_ACK
• INIT
• INIT_ACK
• SACK
• SHUTDOWN
• SHUTDOWN_ACK
• SHUTDOWN_COMPLETE
The following flags can be used with the --chunk-types match as seen above. According to the RFC 2960 - Stream Control Transmission Protocol all the rest of the flags are reserved or not in use, and must be set to 0. Iptables does currently not contain any measures to enforce this, fortunately, since it begs to become another problem such as the one previously experienced when ECN was implemented in the IP protocol.
SCTP Chunk flags as used in --chunk-types
• DATA - U or u for Unordered bit, B or b for Beginning fragment bit and E or e for Ending fragment bit.
• ABORT - T or t for TCB destroy flag.
• SHUTDOWN_COMPLETE - T or t for TCB destroyed flag.
Explicit matches
Explicit matches are those that have to be specifically loaded with the -m or --match option. State matches, for example, demand the directive -m state prior to entering the actual match that you want to use. Some of these matches may be protocol specific . Some may be unconnected with any specific protocol - for example connection states. These might be NEW (the first packet of an as yet unestablished connection), ESTABLISHED (a connection that is already registered in the kernel), RELATED (a new connection that was created by an older, established one) etc. A few may just have been evolved for testing or experimental purposes, or just to illustrate what iptables is capable of. This in turn means that not all of these matches may at first sight be of any use. Nevertheless, it may well be that you personally will find a use for specific explicit matches. And there are new ones coming along all the time, with each new iptables release. Whether you find a use for them or not depends on your imagination and your needs. The difference between implicitly loaded matches and explicitly loaded ones, is that the implicitly loaded matches will automatically be loaded when, for example, you match on the properties of TCP packets, while explicitly loaded matches will never be loaded automatically - it is up to you to discover and activate explicit matches.
Addrtype match
The addrtype module matches packets based on the address type. The address type is used inside the kernel to put different packets into different categories. With this match you will be able to match all packets based on their address type according to the kernel. It should be noted that the exact meaning of the different address types varies between the layer 3 protocols. I will give a brief general description here however, but for more information I suggest reading Linux Advanced Routing and Traffic Control HOW-TO and Policy Routing using Linux. The available types are as follows:
Table 10-6. Address types
Type Description ANYCAST This is a one-to-many associative connection type, where only one of the many receiver hosts actually receives the data. This is for example implemented in DNS. You have single address to a root server, but it actually has several locations and your packet will be directed to the closest working server. Not implemented in Linux IPv4. BLACKHOLE A blackhole address will simply delete the packet and send no reply. It works as a black hole in space basically. This is configured in the routing tables of linux. BROADCAST A broadcast packet is a single packet sent to everyone in a specific network in a one-to-many relation. This is for example used in ARP resolution, where a single packet is sent out requesting information on how to reach a specific IP, and then the host that is authoritative replies with the proper MAC address of that host. LOCAL An address that is local to the host we are working on. 127.0.0.1 for example. MULTICAST A multicast packet is sent to several hosts using the shortest distance and only one packet is sent to each waypoint where it will be multiple copies for each host/router subscribing to the specific multicast address. Commonly used in one way streaming media such as video or sound. NAT An address that has been NAT'ed by the kernel. PROHIBIT Same as blackhole except that a prohibited answer will be generated. In the IPv4 case, this means an ICMP communication prohibited (type 3, code 13) answer will be generated. THROW Special route in the Linux kernel. If a packet is thrown in a routing table it will behave as if no route was found in the table. In normal routing, this means that the packet will behave as if it had no route. In policy routing, another route might be found in another routing table. UNICAST A real routable address for a single address. The most common type of route. UNREACHABLE This signals an unreachable address that we do not know how to reach. The packets will be discarded and an ICMP Host unreachable (type 3, code 1) will be generated. UNSPEC An unspecified address that has no real meaning. XRESOLVE This address type is used to send route lookups to userland applications which will do the lookup for the kernel. This might be wanted to send ugly lookups to the outside of the kernel, or to have an application do lookups for you. Not implemented in Linux.The addrtype match is loaded by using the -m addrtype keyword. When this is done, the extra match options in the following table will be available for usage.
Table 10-7. Addrtype match options
Match --src-type Kernel 2.6 Example iptables -A INPUT -m addrtype --src-type UNICAST Explanation The --src-type match option is used to match the source address type of the packet. It can either take a single address type or several separated by coma signs, for example --src-type BROADCAST,MULTICAST. The match option may also be inverted by adding an exclamation sign before it, for example ! --src-type BROADCAST,MULTICAST. Match --dst-type Kernel 2.6 Example iptables -A INPUT -m addrtype --dst-type UNICAST Explanation The --dst-type works exactly the same way as --src-type and has the same syntax. The only difference is that it will match packets based on their destination address type.AH/ESP match
These matches are used for the IPSEC AH and ESP protocols. IPSEC is used to create secure tunnels over an insecure Internet connection. The AH and ESP protocols are used by IPSEC to create these secure connections. The AH and ESP matches are really two separate matches, but are both described here since they look very much alike, and both are used in the same function.
I will not go into detail to describe IPSEC here, instead look at the following pages and documents for more information:
• RFC 2401 - Security Architecture for the Internet Protocol
• FreeS/WAN
• IPSEC Howto
• Linux Advanced Routing and Traffic Control HOW-TO
There is also a ton more documentation on the Internet on this, but you are free to look it up as needed.
To use the AH/ESP matches, you need to use -m ah to load the AH matches, and -m esp to load the ESP matches.
Note In 2.2 and 2.4 kernels, Linux used something called FreeS/WAN for the IPSEC implementation, but as of Linux kernel 2.5.47 and up, Linux kernels have a direct implementation of IPSEC that requires no patching of the kernel. This is a total rewrite of the IPSEC implementation on Linux.
Table 10-8. AH match options
Match --ahspi Kernel 2.5 and 2.6 Example iptables -A INPUT -p 51 -m ah --ahspi 500 Explanation This matches the AH Security Parameter Index (SPI) number of the AH packets. Please note that you must specify the protocol as well, since AH runs on a different protocol than the standard TCP, UDP or ICMP protocols. The SPI number is used in conjunction with the source and destination address and the secret keys to create a security association (SA). The SA uniquely identifies each and every one of the IPSEC tunnels to all hosts. The SPI is used to uniquely distinguish each IPSEC tunnel connected between the same two peers. Using the --ahspi match, we can match a packet based on the SPI of the packets. This match can match a whole range of SPI values by using a : sign, such as 500:520, which will match the whole range of SPI's.Table 10-9. ESP match options
Match --espspi Kernel 2.5 and 2.6 Example iptables -A INPUT -p 50 -m esp --espspi 500 Explanation The ESP counterpart Security Parameter Index (SPI) is used exactly the same way as the AH variant. The match looks exactly the same, with the esp/ah difference. Of course, this match can match a whole range of SPI numbers as well as the AH variant of the SPI match, such as --espspi 200:250 which matches the whole range of SPI's.Comment match
The comment match is used to add comments inside the iptables ruleset and the kernel. This can make it much easier to understand your ruleset and to ease debugging. For example, you could add comments documenting which bash function added specific sets of rules to netfilter, and why. It should be noted that this isn't actually a match. The comment match is loaded using the -m comment keywords. At this point the following options will be available.
Table 10-10. Comment match options
Match --comment Kernel 2.6 Example iptables -A INPUT -m comment --comment "A comment" Explanation The --comment option specifies the comment to actually add to the rule in kernel. The comment can be a maximum of 256 characters.Connmark match
The connmark match is used very much the same way as the mark match is in the MARK/mark target and match combination. The connmark match is used to match marks that has been set on a connection with the CONNMARK target. It only takes one option.
Important To match a mark on the same packet as is the first to create the connection marking, you must use the connmark match after the CONNMARK target has set the mark on the first packet.
Table 10-11. Connmark match options
Match --mark Kernel 2.6 Example iptables -A INPUT -m connmark --mark 12 -j ACCEPT Explanation The mark option is used to match a specific mark associated with a connection. The mark match must be exact, and if you want to filter out unwanted flags from the connection mark before actually matching anything, you can specify a mask that will be anded to the connection mark. For example, if you have a connection mark set to 33 (10001 in binary) on a connection, and want to match the first bit only, you would be able to run something like --mark 1/1. The mask (00001) would be masked to 10001, so 10001 && 00001 equals 1, and then matched against the 1.Conntrack match
The conntrack match is an extended version of the state match, which makes it possible to match packets in a much more granular way. It let's you look at information directly available in the connection tracking system, without any "frontend" systems, such as in the state match. For more information about the connection tracking system, take a look at the The state machine chapter.
There are a number of different matches put together in the conntrack match, for several different fields in the connection tracking system. These are compiled together into the list below. To load these matches, you need to specify -m conntrack.
Table 10-12. Conntrack match options
Match --ctstate Kernel 2.5 and 2.6 Example iptables -A INPUT -p tcp -m conntrack --ctstate RELATED Explanation This match is used to match the state of a packet, according to the conntrack state. It is used to match pretty much the same states as in the original state match. The valid entries for this match are: • INVALID • ESTABLISHED • NEW • RELATED • SNAT • DNAT The entries can be used together with each other separated by a comma. For example, -m conntrack --ctstate ESTABLISHED,RELATED. It can also be inverted by putting a ! in front of --ctstate. For example: -m conntrack ! --ctstate ESTABLISHED,RELATED, which matches all but the ESTABLISHED and RELATED states. Match --ctproto Kernel 2.5 and 2.6 Example iptables -A INPUT -p tcp -m conntrack --ctproto TCP Explanation This matches the protocol, the same as the --protocol does. It can take the same types of values, and is inverted using the ! sign. For example, -m conntrack ! --ctproto TCP matches all protocols but the TCP protocol. Match --ctorigsrc Kernel 2.5 and 2.6 Example iptables -A INPUT -p tcp -m conntrack --ctorigsrc 192.168.0.0/24 Explanation --ctorigsrc matches based on the original source IP specification of the conntrack entry that the packet is related to. The match can be inverted by using a ! between the --ctorigsrc and IP specification, such as --ctorigsrc ! 192.168.0.1. It can also take a netmask of the CIDR form, such as --ctorigsrc 192.168.0.0/24. Match --ctorigdst Kernel 2.5 and 2.6 Example iptables -A INPUT -p tcp -m conntrack --ctorigdst 192.168.0.0/24 Explanation This match is used exactly as the --ctorigsrc, except that it matches on the destination field of the conntrack entry. It has the same syntax in all other respects. Match --ctreplsrc Kernel 2.5 and 2.6 Example iptables -A INPUT -p tcp -m conntrack --ctreplsrc 192.168.0.0/24 Explanation The --ctreplsrc match is used to match based on the original conntrack reply source of the packet. Basically, this is the same as the --ctorigsrc, but instead we match the reply source expected of the upcoming packets. This target can, of course, be inverted and address a whole range of addresses, just the same as the the previous targets in this class. Match --ctrepldst Kernel 2.5 and 2.6 Example iptables -A INPUT -p tcp -m conntrack --ctrepldst 192.168.0.0/24 Explanation The --ctrepldst match is the same as the --ctreplsrc match, with the exception that it matches the reply destination of the conntrack entry that matched the packet. It too can be inverted, and accept ranges, just as the --ctreplsrc match. Match --ctstatus Kernel 2.5 and 2.6 Example iptables -A INPUT -p tcp -m conntrack --ctstatus RELATED Explanation This matches the status of the connection, as described in the The state machine chapter. It can match the following statuses. • NONE - The connection has no status at all. • EXPECTED - This connection is expected and was added by one of the expectation handlers. • SEEN_REPLY - This connection has seen a reply but isn't assured yet. • ASSURED - The connection is assured and will not be removed until it times out or the connection is closed by either end. This can also be inverted by using the ! sign. For example -m conntrack ! --ctstatus ASSURED which will match all but the ASSURED status. Match --ctexpire Kernel 2.5 and 2.6 Example iptables -A INPUT -p tcp -m conntrack --ctexpire 100:150 Explanation This match is used to match on packets based on how long is left on the expiration timer of the conntrack entry, measured in seconds. It can either take a single value and match against, or a range such as in the example above. It can also be inverted by using the ! sign, such as this -m conntrack ! --ctexpire 100. This will match every expiration time, which does not have exactly 100 seconds left to it.Dscp match
Жалоба
Напишите нам, и мы в срочном порядке примем меры.