It is clear that PREROUTING is used when POSTROUTING is used for going out from the Intranet, but PREROUTING is used for transparent proxy. Why? Reply: whether sunnyguple or post is determined based on the data packet flow. Usually, the Intranet to the Internet is pre, and the Intranet is post, but the Intranet is only a relative
It is clear that PREROUTING is used when POSTROUTING is used for going out from the Intranet, but PREROUTING is used for transparent proxy. Why?
Reply:SuNnygg
Pre or post are determined based on the data packet flow.
Usually, the Intranet to the Internet is pre, and the Intranet is post, but the Intranet is only a relative concept, which can be converted under certain conditions. Implemented on the network card, for each network card data inflows must pass through the pre, the number of outflows must pass through the post.
The principle of transparent proxy is to redirect webpage access requests from the Intranet to the Internet and forward Intranet requests back to the internal proxy server. The proxy service is integrated with the gateway. If post is used for processing, then the data will flow out, and the transparent proxy settings will fail. Therefore, you must rewrite the rules when the data flows in to timely respond to the request.
Reply:
POSTROUTING refers to source address conversion. You need to convert your intranet address to a public address to enable Internet access.
PREROUTING is a conversion of destination addresses. You need to replace others' public IP addresses with your internal IP addresses so that you can access your internal firewall-protected machines.
Reply:
1. First, you need to understand what is "PREROUTING" and what is "POSTROUTING". We can simply use the following link to represent it:
The source address sends data --> {PREROUTING --> routing rule --> POSTROUTING} --> the destination address receives data.
When you use: iptables-t nat-a prerouting-I eth1-d 1.2.3.4-j DNAT -- to 192.168.1.40
When you access 1.2.3.4, the linux router changes the destination address to 192.168.1.40 before the "routing rule", and the Linux router (iptables) records the connection at the same time, when the data is returned from 192.168.1.40, the data is sent to the requesting machine through the linux router. Therefore, your "POSTROUTING" rule does not work.
"POSTROUTING" is an action after "routing Rules.
2. You 'd better have a detailed network topology so that I can better explain it to you.
3. I can give a simple example to illustrate the different application environments of "PREROUTING" and "POSTROUTING:
3.1 PREROUTING applications,
Generally, PREROUTING is used in normal NAT (that is, SNAT). For example, if you use ADSL to access the Internet, your network has only one public IP address (for example, 61.129.66.5 ), however, users in your LAN need to access the Internet (the IP address of the LAN is 192.168.1.0/24). In this case, you can use PREROUTING (SNAT) to convert users' IP addresses in the LAN to 61.129.66.5, so that they can also access the Internet:
Iptables-t nat-a prerouting-s 192.168.1.0/24-j SNAT 61.129.66.5
3.2 POSTROUTING application,
POSTROUTING is used to put your server behind the firewall and protect the server. For example:
A. Your Server IP address is 192.168.1.2;
B. Your Firewall (Linux & iptables) addresses are 192.168.1.1 and 202.96.129.5.
Users on the Internet can access 202.96.129.5 normally, but they cannot access 192.168.1.2. In this case, you can make the following settings in the Linux Firewall:
Iptables-t nat-a postrouting-d 202.96.129.5-j DNAT 192.168.1.2
Conclusion: The most important thing is to remember that PREROUTING is the action before "routing rules" and POSTROUTING is the action after "routing Rules!
Use port ing. For example, if the server is 192.168.0.5 on the Intranet, the Service port is 8080, And the gateway IP222.240.9.211 is used, the gateway port 8080 is used to map to the server 8080.CommandAs follows:
1 # iptables-t nat-a postrouting-o ppp0-j MASQUERADE
// # Iptables-t nat-a postrouting-d 192.168.0.0/24-p tCp-J SNAT -- to-source 222.240.9.211
// # Iptables-t nat-a postrouting-d 192.168.0.5-p tcp -- dport 8080-j SNAT -- to-source 222.240.9.211 // use nat for A specific ip address-specific port
2 # iptables-t nat-a prerouting-p tcp-d 222.240.9.211 -- dport 8080-j DNAT -- to 192.168.0.5: 8080
3 # iptables-t nat-a postrouting-d 192.168.0.5-p tcp -- dport 8080-j SNAT -- to-source 222.240.9.211
When an Internet interface is dynamically allocated instead of a static IP address, it uses the snat method to connect to the interface. In this case, the interface automatically determines the disguised source address when the interface is connected. If you use a static IP address, it is best to use snat to reduce the pressure on the system, because it does not need to determine which IP address to use for camouflage. That is to say, the MASQUERADE method is an exception of the snat method in combination with system functions. It does not need to specify -- to-source like snat, but is automatically determined by the system.
2nd commands for port ing. -D must be used for configuration after the system is started <外部接口ip> But cannot use-I <接口名称> . If init is used at startup, the latter can be used, but no test is performed.
The 3rd commands use a fixed snat for a specific ip address specific port on the Intranet. It seems that this sentence can not be used, but the link is not established during the test, but it seems that there is no data transmission.