Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 1 down vote accepted

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.

share|improve this answer

On Ubuntu from 12.04, the iptables configuration is permanently stored in /etc/default/iptables-rules

You should check if the saved iptables-rules still contains your rules and copy that file before stopping the iptables service or have a back-up of that file ready.

  1. Then you stop the iptables service: sudo service iptables stop
  2. restore the iptables-rules file in /etc/default sudo cp <my backup of iptables> /etc/default/iptables-rules
  3. and start the iptables service sudo service iptables start
share|improve this answer

Hm. Can't it have been saved before your flushed? http://www.centos.org/docs/5/html/5.1/Deployment_Guide/s1-iptables-saving.html ?

+= If not, it's near to impossible, unless there're some lost disk files with fw rules inside.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["                  <li><a href=\"//area51.stackexchange.com\" title=\"proposing new sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"//careers.stackoverflow.com\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &#169; 2015 stack exchange inc; user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a> \r\n                with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2015.2.26.2347\r\n            </div>\r\n            \r\n        </div>\r\n    </div>\r\n    <noscript>\r\n        <div id=\"noscript-warning\">Server Fault works best with JavaScript enabled<img src=\"http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif\" alt=\"\" class=\"dno\"></div>\r\n    </noscr"], "copyright__copyright__copyright": ["o service iptables start\nshare|improve this answer\n\nHm. Can't it have been saved before your flushed? http://www.centos.org/docs/5/html/5.1/Deployment_Guide/s1-iptables-saving.html ?\n\n+= If not, it's near to impossible, unless there're some lost disk files with fw rules inside.\n\nshare|improve this answer\n\nYour Answer\n\n\u00a0\ndiscard\n\nBy posting your answer, you agree to the privacy policy and terms of service.\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}