Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Other Community Discussions > Tutorials & Tips
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

Ubuntu 9.10 is out!!!

When downloading Ubuntu 9.10 please consider using bittorrent to get your copy of Ubuntu.

The Ubuntu Developers Summit for Lucid Lynx will be held the week of 16-Nov-2009 till 20-Nov-2009 in Dallas, TX USA. Visit the the Ubuntu wiki for more information about UDS and how to participate remotely.

Tutorials & Tips
The place to find Ubuntu related Tips & Tricks.

 
Thread Tools Display Modes
Old June 9th, 2008   #1
cprofitt
Dark Roasted Ubuntu
 
cprofitt's Avatar
 
Join Date: Mar 2007
Location: Rochester, NY USA
Beans: 1,007
Ubuntu 9.10 Karmic Koala
How-To: UFW - Ucomplicated Firewall

I looked for a current how-to for UFW and when I did not see one I wanted to add one.

(important note: UFW is not the firewall. UFW just configures your iptables)

in most cases I recommend doing the following immediately:

Code:
sudo ufw default deny
sudo ufw enable
Then fine tuning can start:

Some basic commands are:

Turn on the firewall

Code:
sudo ufw enable
Turn off the firewall
Code:
sudo ufw disable


To add deny rules:

blocking a port
Code:
sudo ufw deny port <port number>

blocking an ip address

Code:
sudo ufw deny from <ip address>
blocking a specific ip address and port
Code:
sudo ufw deny from <ipaddress> to port <port number>
advanced deny example for denying access from an ip address range 10.120.0.1 - 10.120.0.255 for SSH port 22
Code:
sudo ufw deny from 10.0.0.1/24 to any port 22


To add allow rules:

to allow an ip address
Code:
sudo ufw allow from <ip address>
to allow a port
Code:
sudo ufw <port number>
allow a specific ip address and port
Code:
sudo ufw allow from <ipaddress> to any port <port number>
advanced allow example for allowing access from an ip address range 10.120.0.1 - 10.120.0.255 to port 22
Code:
sudo ufw allow from 10.0.0.0/24 to any port 22

To get the current status of your UFW rules

Code:
sudo ufw status
To remove a deny or allow rule
Code:
sudo ufw delete <rule type> from <ip address> to any port <port number>
(note: you basically match the syntax for the creation of the rule and add 'delete')

You need to be careful with setting up allow and deny rules that 'intersect' because the first rule matched is applied and the remaining are ignored.

SECNARIO:

you want to block access to port 22 from 192.168.0.1 and 192.168.0.7 but allow all other 192.168.0.x IPs to have access to port 22

Code:
sudo ufw deny from 192.168.0.1 to any port 22
sudo ufw deny from 192.168.0.7 to any port 22
sudo ufw allow from 192.168.0.0/24 to any port 22
if you do the allow statement before either of the deny statements it will be matched first and the deny will not be evaluated.

you can check this by checking ufw status
Code:
sudo ufw status
To                         Action  From
--                         ------  ----
22:tcp                     DENY    192.168.0.1
22:udp                     DENY    192.168.0.1
22:tcp                     DENY    192.168.0.7
22:udp                     DENY    192.168.0.7
22:tcp                     ALLOW   192.168.0.0/24
22:udp                     ALLOW   192.168.0.0/24
the allow is at the bottom and will be the last command evaluated if it appeared above the deny rules the deny rules would not be evaluated.

I hope this helps you use ufw to secure your computer.

Link to the documentation wiki

Last edited by cprofitt; June 9th, 2008 at 04:40 PM..
cprofitt is offline   Reply With Quote
Old June 30th, 2008   #2
Bakon Jarser
Skinny Soy Caramel Ubuntu
 
Join Date: Aug 2007
Beans: 692
Ubuntu Jaunty Jackalope (testing)
Re: How-To: UFW

Every time I restart my computer I have to restart ufw. Is there a way to make it enabled at startup?
__________________
I would rather die of thirst than drink from the cup of mediocrity.

Get better forum search results!
Bakon Jarser is offline   Reply With Quote
Old July 1st, 2008   #3
kevdog
I Want My $2!!
 
kevdog's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Beans: 7,058
Ubuntu 8.10 Intrepid Ibex
Re: How-To: UFW

Can you ICS with ufw as you can in iptables?
kevdog is offline   Reply With Quote
Old July 6th, 2008   #4
ugm6hr
Chai anyone?
 
ugm6hr's Avatar
 
Join Date: Apr 2006
Location: UK
Beans: 5,949
Ubuntu 9.04 Jaunty Jackalope
Send a message via Yahoo to ugm6hr
Re: How-To: UFW

Quote:
Originally Posted by Bakon Jarser View Post
Every time I restart my computer I have to restart ufw. Is there a way to make it enabled at startup?
I would like to understand this too. I can't find any documentation that clarifies the situation.

I presume iptables boots at startup. And ufw is a "frontend" for iptables.

So does ufw need to be running to enable the open ports that I have defined with ufw?

ufw does not boot at startup:
Code:
sudo ufw status
[sudo] password for xxxxx: 
Firewall not loaded
I thought this was where the bootup setting was (default):
Code:
cat /etc/ufw/ufw.conf
# /etc/ufw/ufw.conf
# 

# set to yes to start on boot
ENABLED=yes
Any help?
__________________
Beginners: Enter Code entries in Terminal | Wifi help? | Multimedia | How to get help here | Enable Repos
My sites: Lightweight LXDE-Ubuntu | FreeNAS Home Server| DropBox

If you are a beginner - look at the Start here sticky in the Absolute Beginners Forum
Get Ubuntu
ugm6hr is offline   Reply With Quote
Old July 13th, 2008   #5
glitch32
First Cup of Ubuntu
 
Join Date: Jul 2008
Beans: 5
Re: How-To: UFW

I would also like to know, I'm a little confused with this.
glitch32 is offline   Reply With Quote
Old July 14th, 2008   #6
kevdog
I Want My $2!!
 
kevdog's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Beans: 7,058
Ubuntu 8.10 Intrepid Ibex
Re: How-To: UFW

Im curious also -- I know for example iptables does not by default store settings between boots unless the settings are exported and then imported at boot, or a startup script is launched that re-enters the settings back into iptables. (iptables-save, iptables-restore). I thought Network Manager had the iptables-save, restore code calls built in, however if you are not using network manager, then that's another issue). In theory however, since ufw uses iptables, it would be possible manually to save and restore the settings using the save/restore commands by calling iptables directly rather than ufw.
kevdog is offline   Reply With Quote
Old July 16th, 2008   #7
clio
First Cup of Ubuntu
 
Join Date: Jul 2007
Beans: 2
Re: How-To: UFW

Quote:
Originally Posted by Bakon Jarser View Post
Every time I restart my computer I have to restart ufw. Is there a way to make it enabled at startup?
i had the same problem before,when i find this gui -->> gufw link http://gufw.tuxfamily.org/screenshots.html

works all time after reboot,and very easy to use
clio is offline   Reply With Quote
Old July 16th, 2008   #8
glitch32
First Cup of Ubuntu
 
Join Date: Jul 2008
Beans: 5
Re: How-To: UFW

Finally a link that works! I tried downloading that from ubuntu-unleashed, (and quite a few others), but I could never get the link to work. Google always said forbidden. Thank you for that!
glitch32 is offline   Reply With Quote
Old August 24th, 2008   #9
bullgr
Gee! These Aren't Roasted!
 
bullgr's Avatar
 
Join Date: Apr 2006
Location: Greece
Beans: 198
Ubuntu 9.04 Jaunty Jackalope
Send a message via ICQ to bullgr Send a message via AIM to bullgr
Re: How-To: UFW

Quote:
Originally Posted by Bakon Jarser View Post
Every time I restart my computer I have to restart ufw. Is there a way to make it enabled at startup?
try this (from ubuntu wiki: https://wiki.ubuntu.com/UbuntuFirewall)
Code:
Toggle logging:
# ufw logging on|off
__________________
10 PRINT "HELLO WORLD!"
20 GOTO 10
bullgr is offline   Reply With Quote
Old August 30th, 2008   #10
nvteighen
Chocolate-Covered Ubuntu Beans
 
nvteighen's Avatar
 
Join Date: Apr 2007
Location: (X,Y,Z) = (0,0,0)
Beans: 2,363
Re: How-To: UFW

Ehm... My ufw doesn't reset itself after reboot.
__________________
Projects: FreeTruco|PycTacToe
nvteighen is online now   Reply With Quote

Bookmarks

Tags
firewall, ufw

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:06 AM.


vBulletin ©2000 - 2009, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. lingonberry