The problem of invalid iptables configuration after restart

The solution to the failure of the iptables configuration after restarting

Time: 2016-02-11 15:31:04 Source: Internet
Guide: The solution to the failure of the iptables configuration under linux after restarting, only root users can access ports below 1024, and non-root users cannot log in to port 80. Use iptables-save to save the configuration to avoid restart failure.
 

The solution to the failure of the iptables configuration under linux after restarting

Only root users can access ports below 1024, and non-root users cannot log in to port 80.

Web services tend to start ports above 1024 and map to 80 through iptables.

1. Change the port in server.xml to 8080 
2. Then:

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080 
 

(If 443 is used, the above method is also executed accordingly)

At this point, although port 80 can be accessed, once the server is shut down or restarted, it can only be accessed through port 8080.

Solution:
After entering iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080, 
execute iptables-save

Note: iptables-save is connected together, it is a command, not a parameter
iptables-save is only to list the current settings, not to save the configuration.
If it is RedHat series, you should use service iptables save to save it, and use chkconfig iptables on to enable startup.
If it is not RedHat series, you can use the following method to manually save/restore the configuration
 

#Save
iptables-save > /root/iptables.conf #Restore
iptables
-restore < /root/iptables.conf

How to deal with iptables restart failure :

Use iptables-save to save the configuration.

Restart does not work:
 

service iptables save

To save, use:

service iptables restart

Restart the service, restart the machine iptables still works.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326712376&siteId=291194637