Centos7 iptables public network address rotation training
As a crawler, in order to prevent the server's IP from being blocked.. Multiple server egress IP configurations are configured to rotate the egress IP.. each time you climb the page.
How to do it:
Through iptables's SNAT, we won't talk about this principle. If you don't understand it, just go straight to Baidu.
The machine here uses centos7.
Server-side configuration:
1. Enable IP forwarding
Echo'1' > / proc/sys/net/ipv4/ip_forward
2.-s represents the source address, and-o represents the exit of the public network.
Iptables-t nat-A POSTROUTING-s 10.150.2.0 Universe 24-o em2-j MASQUERADE
3.-- every represents the number of seconds it takes to re-select an IP, and generally fill in as many seconds as there are IP.
Iptables-t nat-I POSTROUTING-m state-- state NEW-p tcp-- dport 80-o em2-m statistic-- mode nth-- every 2-- packet 0-j SNAT-- to-source 1.1.1.1iptables-t nat-I POSTROUTING-m state-- state NEW-p tcp-- dport 80-o em2-m statistic-mode nth-every 2-packet 0-j SNAT-to-source 1.1.1.2
Configuration of the client:
The client only needs to point the default gateway to the server's private network IP.