Solved

My LINUX UFW keeps resetting after reboot

Posted on 2009-03-31
17
611 Views
Last Modified: 2012-06-27
Everytime I ahve lsot power or rebooted my UFW rules reset and I am not able to SSH in.
I have to go log onto the server itself and sudo ufw allow 22, every time, any way to lock this in?
0
Comment
Question by:manelson05
  • 9
  • 5
  • 2
  • +1
17 Comments
 
LVL 29

Expert Comment

by:fosiul01
ID: 24030489
you need to add those rule in

rc.local file

in red hat/centos

cd /etc/rc.d/rc.local

in debin or ubuntu

it should be

/etc/rc.local

add the rule in rc.local file

so when server will boot, those rules will automaticaly added
0
 
LVL 29

Expert Comment

by:fosiul01
ID: 24030508
0
 

Author Comment

by:manelson05
ID: 24031971
I did the following below, no just change the file  $chmod +x FOO
Is this correct?

!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
ufw allow 22
exit 0
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:manelson05
ID: 24032438
Thats did not work what I just tried.
Unable to get back in.
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 24032929
have a startup script in /etc/rc5.d to run the command every time the system is booted or have a crontab job that run every say 5 min that runs the command
0
 
LVL 13

Expert Comment

by:WizRd-Linux
ID: 24033488
UFW is for Ubuntu and more to the point its a nice simple interface for iptables.

http://blog.controlunlimited.net/index.php/2008/05/13/iptables-aamp-ubuntu?blog=1

The main command you want is "iptables-save > /etc/iptables.rules", but add the rest of the iptables-save commands to the /etc/network/interfaces file.

As suggested by omarfarid you can do the above command in a cronjob similar to :

*/5 * * * * iptables-save > /etc/iptables.rules > /dev/null 2>&1

This will save the iptables setup every 5 minutes, and then when you reboot or loose power the above modifications to the interfaces file will bring the rules back automatically.

You will need to "test" this though by rebooting your server and see if UFW is able to list the rules after they have been restored.
0
 

Author Comment

by:manelson05
ID: 24033528
can I simply issue the command
ufw enable

?

How would I do this with cron job?
0
 
LVL 13

Expert Comment

by:WizRd-Linux
ID: 24033860
The quickest and laziest way is to put it in your /etc/rc.local file on ubuntu.

chmod +x /etc/rc.local
Edit /etc/rc.local with your favourite editor and add before the line exit 0
ufw enable
0
 
LVL 29

Expert Comment

by:fosiul01
ID: 24036672
Hi Good morning
Sorry due to night didnot able to reply

Ok have you tryed by just adding that rule in rc.local file as i said ??

ufw should be enable always , is not it ??

but if you thin you need to start ufw rules then  add the command in rc.local file directory..

just edit rc.local file by your hand and add those rules
0
 

Author Comment

by:manelson05
ID: 24040831
I have edited rc.local and it still is nto starting back up upon reboot.
0
 

Author Comment

by:manelson05
ID: 24040917
I think I am going to try to do a cron job.
0
 

Author Comment

by:manelson05
ID: 24041532
I have done the following sudo crontab -e and added */5 * * * * iptables-save > /etc/iptables.rules > /dev/null 2>&1

I dont want to be lazy, I am trying to learn as I go, all I can really do.
Unfortunately this is not working.
0
 

Author Comment

by:manelson05
ID: 24041853
I have also tried network interfaces and added

post-up iptables-restore < /etc/iptables.rules
post-down iptables-save > /etc/iptables.rules

auto eth0
iface eth0 inet static
address 10.0.0.1
netmask 255.255.255.0
network 10.0.0.0
broadcast 10.0.0.255
post-up iptables-restore < /etc/iptables.rules
post-down iptables-save > /etc/iptables.rules
gateway 10.0.0.254

0
 
LVL 29

Expert Comment

by:fosiul01
ID: 24047293
Ok let me try myself, i will come back
0
 

Author Comment

by:manelson05
ID: 24049622



I am going to remove firestarter and UFW then reinstall gufw to test then reboot.
If I am not mistaken ufw/gufw same thing front end for iptables.

Same cmd line works or so it seemed last night.
I did notice that if I enabled GUFW firewall on then issued the same cmd via ufw cmd line then checked GUFW the firewall was disabled.
Maybe the firestarter interface is conflicting with ufw cmd line on the server?
0
 
LVL 29

Accepted Solution

by:
fosiul01 earned 500 total points
ID: 24049819
i am failier with Redhat and centos

i know the fact if you add those rules in rc.local it will work, its 100% sure

so there might be something else is culprit.

if you have 2 firewall running, then you will have to  make sure, which one is the mail
disable one, and keep running another one see what happended
0
 

Author Closing Comment

by:manelson05
ID: 31564912
Changed firewall settings.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question