Introduction to iptables on red-flag Linux-Linux Enterprise Application-Linux server application information. The following is a detailed description. Iptables is a powerful packet filtering-based network tool. This article briefly introduces how to use iptables and how to use it to build a network firewall.
Iptables consists of two subsystems: the kernel module and user interface application. It can be compiled into the system kernel or into a detachable kernel module, you can also choose to install some components that can complete certain functions. These components implement a series of functions such as IP address camouflage, port ing, and packet filtering.
Install iptables
The configuration and compilation of many iptables components are associated with Kernel configuration and compilation. Some Linux distributions have installed iptables in advance, such as RedHat and RedFlag. However, you may need to install it on your own.
First you need a kernel version 2.4.X or later, which can be downloaded from the http://Kernel.org.
You also need the iptables user space program, which can be downloaded from the Netfilter homepage.
After you prepare, compile the kernel. Find the Network packet filtering sub-item under Networking Options, select Network packet filtering replaces ipchains, and configure the sub-item.
Use the new kernel boot to compile the iptables user space program. The installer will copy the executable file to the/usr/local/sbin directory.
If everything goes smoothly, we have successfully installed support for iptables and Netfilter in the kernel.
You can use service iptables start to start the service.
Table and chain
Here we will discuss how data packets are transmitted between the chains and tables of iptables.
For example, a data packet sent from an external host to the local machine must be received by the application in the following ways:
1. Data packets are transmitted from the network and received by the network adapter.
2. The PREROUTING chain is then transferred to the mangle table.
3. Transfer the chain to the PRETOUTING chain of the nat table. This chain is mainly used for DNAT, that is, destination address forwarding.
4. route determination.
5. Because data packets are transmitted to the local machine, they are transferred to the INPUT chain of the mangle table.
6. Transfer the INPUT chain of the filter table.
7. The application that finally receives the data packet.
Similarly, a data packet sent from the local host to the external host is transmitted through the following channels:
1. The application generates a data packet and determines the route based on the source address, Destination Address, outbound interface, and other information.
2. The OUTPUT chain is then transferred to the mangle table.
3. Transfer the OUTPUT chain of the nat table, which can be used for DNAT.
4. Go to the OUTPUT chain of the filter table and perform selective filtering on the data packet.
5. Enter the POSTROUTING chain of the mangle table.
6. Enter the POSTROUTING chain of the nat table. The chain can be SNAT, that is, source address forwarding, and finally enter the network.
For a forwarded packet, that is, when the destination address of the incoming packet is a host in another network, there are also the following ways:
1. input the data into the PREROUTING chain of the mangle table.
2. Transfer the PREROUTING chain to the nat table.
3. Determine the route. The destination address of this package is another host, so it is transferred to the FORWARD chain of the mangle table.
4. transfer it to the FORWARD chain of the filter table. All the filtering operations for this type of package are carried out in this chain.
5. After filtering, it is transferred to the POSTROUTING chain of the mangle chain. Finally, it is SNAT through the POSTROUTING chain of the nat table and finally enters the network.
After learning about the flow of network packets, we will introduce how to write iptables rules in the next section.
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