Use of the new package filtering structure in Linux Kernel

Source: Internet
Author: User
Use of the new Linux kernel package filtering structure-general Linux technology-Linux programming and kernel information. The following is a detailed description. 1. How to filter packets through (traverse)

The kernel starts from the three lists (lists) in the "filter" table. These three lists are called firewall chains (firewall chain) or chains (chain ). The three links are INPUT, OUTPUT, and FORWARD.

Shows the chains:



(400) {this. resized = true; this. width = 400; this. alt = 'click here to open new window';} "onmouseover =" if (this. resized) this. style. cursor = 'hand'; "onclick =" window. open ('HTTP: // linux.ccidnet.com/col/attachment/2006/12/964959.png'); ">



Three circles represent the preceding three chains. When a package arrives at one of the chains, the corresponding chains will be tested (examined) to determine how to deal with the package. If the chain thinks the packet should be dropped, it will be discarded; if the chain thinks it should ACCEPT the packet, it will continue to traverse in the figure.

A chain is actually a checklist of many rules ). The format of each rule is like this: "If the package header is like this, handle the package like this ". If the rule settings do not match the package, the rule will be processed by the next rule in the chain. Until there are no remaining Rules for reference at the end, the kernel will decide how to deal with them based on the chain policy. In a secure system, the kernel is usually required to discard the package.

(1) When a package enters (assuming it is through the Ethernet NIC), the kernel first looks at the Packet destination (destination): This is called routing ).

(2) If the destination address is the local machine, the package will be directed to the INPUT chain as shown in the following figure. If it can pass, it will go to the subsequent package processing process.

(3) Otherwise, if the kernel does not enable the forwarding function or does not know how to forward the package, the package will be discarded. If the forwarding function is enabled and the package points to another network interface (if the network is connected to another network), the package will be directed to the FORWARD chain as shown in the following figure. If the package is not accepted, it will be sent out.

(4) Last case: a program running on the local machine sends a network package, and the package directly passes through the OUTPUT chain. If it is accepted, the package will be sent to the network interface specified by the package.

Ii. Use iptables

Iptables is useful. The three built-in (built-in) chains mentioned above: INPUT, OUTPUT, and FORWARD cannot be deleted. Let's take a look at how to manage the entire chain:

(1) create a new chain (-N );

(2) Delete an empty chain (-X );

(3) change a built-in chain Policy (-P );

(4) list the rules in a chain (-L );

(5) understand all the rules in a chain (-F)

(6) Replace the byte counter of all the rules in a chain with zero (-Z ).

The following operations are used to manage rules in a chain:

(1) append A new rule to A chain (-);

(2) Insert a new rule (-I) at a specified position in the chain );

(3) Replace a rule (-R) at a specified position in the chain );

(4) Delete a rule at a specified position in the chain (-D );

(5) Delete the first rule (-D) in the chain ).

Processing during machine startup

The iptables module is named "iptable_filter.o". iptables is automatically loaded when it is run for the first time. It can also be permanently built in the kernel.

Before running any iptables commands (note that some release versions may use their initial commands to run iptables), built-in chains (INPUT, OUTPUT, and FORWARD) will not carry any rules, all links are set to ACCEPT. You can change the default forward chain policy by setting the iptable_filter module option to "FORWARD = 0.

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.