LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   IPtables rules flushed with reboot ? (https://www.linuxquestions.org/questions/linux-newbie-8/iptables-rules-flushed-with-reboot-907568/)

jonaskellens 10-11-2011 07:29 AM

IPtables rules flushed with reboot ?
 
Hello,

I notice that my firewall rules are flushed with a reboot. Is that some setting or so ?

fukawi1 10-11-2011 08:32 AM

Fedora (15 at least) will load saved iptables rules from /etc/sysconfig/iptables , so if you are loading your rules manually via a script, you need to save the rules using
Code:

iptables-save > /etc/sysconfig/iptables
(note this will overwrite any existing saved rules, so it may be worth taking a backup)and it should load them whenever the init script is called (ie: boot time, or via service)

theNbomr 10-11-2011 09:48 AM

It is common practice to use shell scripts to establish a functional set of iptables rules. The rules are edited in the shell script, and then the script is run to load the rules set. The script can be hooked into the system startup scripting in order to automatically load at boot-time. Usually, there is provision in the script to flush all of the rules, and then successively re-build the set of rules as the script runs. This allows you edit the script to add new functionality, and then run the script to install the new features.

--- rod.

rng 10-11-2011 11:49 AM

I think ufw (uncomplicated firewall- default in ubuntu) and firestarter firewall frontends, if installed, affect iptables at startup. They also change iptables rules when network is switched off or on. You may want to uninstall these if you have your own firewall iptables rules.

In ubuntu, following line inserted in file /etc/rc.local will load iptables rules at startup:

iptables-restore < myrules.saved

(no sudo needed in this file). File 'myrules.saved' is obtained by following command:

sudo iptables-save > myrules.saved

jonaskellens 10-11-2011 02:16 PM

Quote:

Originally Posted by fukawi1 (Post 4495500)
Fedora (15 at least) will load saved iptables rules from /etc/sysconfig/iptables , so if you are loading your rules manually via a script, you need to save the rules using
Code:

iptables-save > /etc/sysconfig/iptables
(note this will overwrite any existing saved rules, so it may be worth taking a backup)and it should load them whenever the init script is called (ie: boot time, or via service)

I use CSF (http://configserver.com/cp/csf.html). I don't really know if this "script" saves the rules...

I use CentOS 5.6

On another server I do not have this problem... And I can't find a difference...

jonaskellens 10-13-2011 03:23 AM

I have solved my problem by removing the file /etc/sysconfig/iptables

This file indeed had some basic firewall rules which were read on reboot.

Now, when I reboot, my firewall rules which I set through CSF are kept.


All times are GMT -5. The time now is 06:38 PM.