tips:生肉,慢点吃,不好消化,嘿嘿。
系统:Ubuntu 20.04
版本:iptables v1.8.4 (legacy)
官网指南:Iptables Tutorial 1.2.2 (frozentux.net)
Chapter 6. Traversing of tables and chains
In this chapter we'll discuss how packets traverse the different chains, and in which order. We will also discuss the order in which the tables are traversed. We'll see how valuable this is later on, when we write our own specific rules. We will also look at the points which certain other components, that also are kernel dependent, enter into the picture. Which is to say the different routing decisions and so on. This is especially necessary if we want to write iptables rules that could change routing patterns/rules for packets; i.e. why and how the packets get routed, good examples of this are DNAT and SNAT. Not to be forgotten are, of course, the TOS bits.
General
When a packet first enters the firewall, it hits the hardware and then gets passed on to the proper device driver in the kernel. Then the packet starts to go through a series of steps in the kernel, before it is either sent to the correct application (locally), or forwarded to another host - or whatever happens to it.
First, let us have a look at a packet that is destined for our own local host. It would pass through the following steps before actually being delivered to our application that receives it:
Table 6-1. Destination local host (our own machine)
Step | Table | Chain | Comment |
---|---|---|---|
1 | On the wire (e.g., Internet) | ||
2 | Comes in on the interface (e.g., eth0) | ||
3 | raw | PREROUTING | This chain is used to handle packets before the connection tracking takes place. It can be used to set a specific connection not to be handled by the connection tracking code for example. |
4 | This is when the connection tracking code takes place as discussed in the The state machine chapter. | ||
5 | mangle | PREROUTING | This chain is normally used for mangling packets, i.e., changing TOS and so on. |
6 | nat | PREROUTING | This chain is used for DNAT mainly. Avoid filtering in this chain since it will be bypassed in certain cases. |
7 | Routing decision, i.e., is the packet destined for our local h |