Solved

My LINUX UFW keeps resetting after reboot

Posted on 2009-03-31
17
603 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
Comment Utility
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
Comment Utility
0
 

Author Comment

by:manelson05
Comment Utility
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
 

Author Comment

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

Expert Comment

by:omarfarid
Comment Utility
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
Comment Utility
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
Comment Utility
can I simply issue the command
ufw enable

?

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

Expert Comment

by:WizRd-Linux
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 29

Expert Comment

by:fosiul01
Comment Utility
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
Comment Utility
I have edited rc.local and it still is nto starting back up upon reboot.
0
 

Author Comment

by:manelson05
Comment Utility
I think I am going to try to do a cron job.
0
 

Author Comment

by:manelson05
Comment Utility
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
Comment Utility
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
Comment Utility
Ok let me try myself, i will come back
0
 

Author Comment

by:manelson05
Comment Utility



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
Comment Utility
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
Comment Utility
Changed firewall settings.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now