How to put the permanent entry in iptables?

Hi Guys,

Hope you all are doing good

I have centos server 6.5 in softlayer cloud server, and configured the VNC server for RDP.

The RDP Session is working fine, I can able to see from any network.

But the problem when the server need to reboot that the my iptables rules are erased after rebooting I dont know why ?

Its erased my entries alone, but the default entries are there Please help out this.

My Rules:

iptables -I INPUT -p tcp -m tcp --dport 5901 -j ACCEPT
iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT


Always save the iptables after adding rules from commandline or directly placing in iptables file under /etc directory. So, that at boot time these entries will never erased and load at system startup.

# iptables service save
1 Like

Below please find the good steps which needs to be followed for Firewall changes.

  1. Save the current Firewall rules to some file. (In case something goes wrong we can quickly revert the settings.
# iptables-save > /tmp/iptables
  1. Now edit the file /tmp/iptables and copy paste the below command for making the port public.
# iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
  1. The below command will write the new changes of iptables into the memory.
# iptables-restore < /tmp/iptables
  1. The below command will make the firewall changes permanent. After reboot also the new changes will not be lost.
# service iptables save
  1. Alternatively we can issue the below commands for making the ports public through terminal and we can save the iptables rules.
# iptables -I INPUT -p tcp -m tcp --dport 22 -j ACCEPT
# iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT