IPTABLES won't keep changes on restart

ConfusedDeer asked:

I have a hostgator VPS that has a CENT OS. When I stop the VPS and start it again, the changes I’ve made to the IPTABLES won’t save I’ve tried to save the IPTABLES and to no avail. Every time I restart the server I have to run the following in order to get the IPTABLES how I need them:

iptables -I INPUT -p tcp --dport 3000 --syn -j ACCEPT
sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 3000

The first command opens port 3000 and the second command redirects port 80 traffic to port 3000.

When I restart or completely stop the VPS and start it again the IPTABLES startup as if I never saved them and go back to the default when I first got the VPS.

I’ve tried all these commands and still no joy.

I’m considering just writing a script to run the commands I need to configure the IPTABLES. Any suggestions?

FYI: I edited the /etc/sysconfig/iptables and did a service iptables save and no luck, once rebooted it went back to Host Gator’s configuration upon reset of the VPS.

My answer:

I found several references on the Internet that indicate that HostGator installs a custom firewall script on their VPS and dedicated servers. However I wasn’t able to find any instructions on how it was installed or how to get rid of it. I would contact HostGator for further information, or consider switching to another provider.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.