Linux – apply back firewall after iptables flush

centosfirewalllinux

yesterday i got my self locked from my own server. and than i try to flush iptables from another server to get it unlocked as this question response 3 times fail then lock

After that, i cannot login to the server. i ask support from the customer service and finally i can login as before.

he (customer service) reboot the server and execute iptables -A INPUT -p tcp –dport 22 -j ACCEPT and shutdown the firewall.

and now i want the firewall back as before it flushed.

is it possible to do that? and how to do that?

i read from other forum, they said with just reboot the machine it the ip table will restore to previous state. is it right?

Best Answer

The firewall as configured by iptables is ephermal. It's never saved and must be reloaded on each boot. Normally there is a script in init.d that loads the iptables rules on boot. When flushing the rules with iptables -F, that only flushes what the Kernel knew, but doesn't affect how the firewall will be setup on next boot. Every distribution is different. Fedora uses a init.d script called /etc/init.d/iptables that just runs iptables-restore /etc/sysconfig/iptables or something like that. Ubuntu uses ufw which calls a series of iptables commands based on local configuration. If all you did was run iptables commands and didn't store anything to a file, then a reboot should restore the firewall. If you know which init.d script, you can probably just reload that script to restore instead of a full reboot.

Related Topic