Use iptables in CentOS to configure the nat service

Source: Internet
Author: User
Referring to the articles in howtoforge, the findings are not complex, but several basic concepts must be clarified. Otherwise, they will not be quite clear. The most important thing is the two steps: iptables -- tablenat -- appendPOSTROUTING -- out-interfaceeth0-jMASQUERADEiptables -- appendFORWARD -- in-I refer to the articles above howtoforge and find that they are not complex, but several basic concepts must be clarified, otherwise they will not be quite clear.
The most important step is:
Iptables-- Table nat -- append POSTROUTING -- out-interface eth0-j (MASQUERADE)
Iptables -- append FORWARD -- in-interface eth1-j ACCEPT
Here, eth0 is an external interface and eth1 is an internal interface.
Then, change/proc/sys/net/ipv4/ip_forward to 1. Before that, check the iptables rules to see if there are any conflicts with the NAT rules.
The howtoforge website does not have any explanation for this. Therefore, if you have set it up, you just don't know why. Later, I checked the document. The original iptables rule contains three tables: filter, nat, and mangle. by default, they are all operated on the filter table. Therefore, the nat table and mangle table are not used for general rule modification, the -- table option is not used either. it is no wonder that the articles on howtoforge will be confused at the beginning.
In Linux nat, the forwarded packets are actually combined by the following table-chain:
1. Mangle -- PREROUTING
2. nat -- PREROUTING                             ; Used for external access to the internal website NAT
3. mangle -- FORWARD
4. filter -- FORWARD
5. mangle -- POSTROUTING
6. nat-POSTROUTING                           ; Used for internal browsing of external NAT
Generally, rules are set in the filter -- FORWARD and nat -- POSTROUTING combinations. Therefore, eth0 is used as the egress route here. All forwarding packets entering eth1 are allowed. of course, you can also perform some filtering based on the specific situation.
CentOS's system-config-securitylevel tool is not suitable for this configuration. after modifying the nat, you should not use this tool to check the configuration. it seems that the configuration is unrecognizable.
  The filter table contains three chains, FORWARD, INPUT   And OUTPUT.
Common iptables options:
-P indicates the protocol. -S specifies the source address-d specifies the destination address-I specifies the inbound interface -O specifies the output interface
-P specifies the protocol, you can use -- sport -- Dport: specifies the port number. -- syn indicates that the syn packet can be followed by-m limit -- limit n/s to limit the number of SYN packets per second.
Extension options:
-M multiport -- sports
  The port numbers are separated by commas (,), not necessarily consecutive.
-M mulitport -- dports

-M multiport -- ports

-M -- stateThe status can be ESTABLISHED.

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.