Ubuntu’s Uncomplicated Firewall (UFW)
Introduced first in Ubuntu 8.04, UFW is Ubuntu’s “uncomplicated firewall”, a remarkably easy to use tool for creating simple iptables firewall rules. The goal behind UFW is to make it easy for administrators and even third party packages to work with firewall rules in a clean and consistent manner. When UFW is enabled, the default set of rules work very well for the average server or desktop platform, as it blocks all non-essential inbound network access without hobbling certain types of useful protocols and return traffic.
In the following example, we will set up a very simple firewall adequate for almost anyone.
First, let’s check the status of UFW, and the currently installed iptables rule set. The following displays that UFW is disabled and that there are no rules for iptables INPUT chain.
Check firewall status
sudo ufw status Firewall not loaded sudo iptables -L INPUT -n | column -t Chain INPUT (policy DROP) target prot opt source destination
Enable UFW
Now, let’s enable UFW and examine the change to iptables’ INPUT chain.
sudo ufw enable Firewall started and enabled on system startup sudo iptables -L INPUT -n | column -t Chain INPUT (policy DROP) target prot opt source destination ufw-before-input all -- 0.0.0.0/0 0.0.0.0/0 ufw-after-input all -- 0.0.0.0/0 0.0.0.0/0
The default policy was changed to drop all traffic, and two new chains are referenced. For a much better understanding of what the default rules are, take a look at the files “/etc/ufw/before.rules” and “/etc/ufw/after.rules“.
Connection Tracking
For your convenience, UFW also enables some very useful connection tracking rules, which intelligently inspect outbound application traffic and dynamically allows the return traffic for you. By default, TCP, UDP, FTP and IRC connection tracking modules are loaded, but others may be added to the IPT_MODULES variable in the file “/etc/default/ufw“.
For example, I sometimes need to use TFTP for sending and receiving firmware to and from routers. So I typically add “nf_conntrack_tftp” to the variable IPT_MODULES.
IPT_MODULES="nf_conntrack_ftp nf_nat_ftp nf_conntrack_irc nf_nat_irc nf_conntrack_tftp"
Remember to reload UFW so that the conntrack module is loaded.
sudo /etc/init.d/ufw restart
Allowing inbound services
If your system runs server applications such as DNS, SSH, TFTP and web, then you can add them to your firewall rules using these very simple commands. If you don’t run servers on your machine, this step can be skipped.
sudo ufw allow 53 sudo ufw allow 22/tcp sudo ufw allow 69/udp sudo ufw allow 80/tcp
Notice that the first command I used did not specify UDP or TCP. When omitted, UFW adds both protocols. DNS uses TCP for larger DNS exchanges like zone transfers and huge replies, so you’ll probably want both.
UFW displays the results very nicely.
sudo ufw status Firewall loaded To Action From -- ------ ---- 53:tcp ALLOW Anywhere 53:udp ALLOW Anywhere 22:tcp ALLOW Anywhere 69:udp ALLOW Anywhere 80:tcp ALLOW Anywhere
SYN cookies and more
UFW can be used to load kernel options, too. These are defined in “/etc/ufw/sysctl.conf“. For example, I wanted to enable SYN cookies which was added to thwart certain TCP DoS attacks. Modify the following line to 1 in order to enable the feature.
net/ipv4/tcp_syncookies=1
Logging can suck
Okay, if you’re on a busy network and don’t want to fill up your syslog, you might want to disable UFW’s logging.
sudo ufw logging off
And really that’s all there is to it. Be sure to check out the man page for some more examples and features you may be interested in.
Comments
GAW said,
Um … Uncomplicated??? Someone needs to look the word up in a dictionary.
gmendoza said,
LOL… well, the entire explanation wasn’t overly complicated… for savvy admin’s. :-P
In all seriousness, though, for the average person, unless you need a ton of services open, how hard is one command? This is appropriate for just about anyone.
On a side note, other front end tools will begin to use UFW on the back end so things are always done the same way.
orangecrush said,
(Um … Uncomplicated??? Someone needs to look the word up in a dictionary.) keep in mind people that this is a iptables firewall and if you want simple stick with windoze as far as iptable firewalls go ufw is Uncomplicated
funney said,
The aim of a joke is not to degrade but to ramind him that he is alrady degraded
Securing an Ubuntu Server « andrewault.net said,
[...] nice article: http://savvyadmin.com/ubuntus-ufw/ [...]
Leila said,
I happen to think anything linux is just perfect! I really think the people who put all the work into it need to be commended, I personally do not miss the Blue Screen Of Death. I do have a problem though, may someone knows the answer: When I start up my machine I cannot get ufw to enable and I typed the following into the terminal:
sudo ufw enable
then
sudo ufw status
everything worked fine, I tried disable and re-enable after reboot, then shut it down and same problem.
Can not figure out what is wrong, still wont boot on start up, I have to do it manually every time.
우분투 서버를 좀 더 안전하게 만들기 « turtle9 said,
[...] 참고: wikipedia Ubuntu UFW Uncomplicated Firewall Examples community documentation server guide ufw manual project wiki nice article [...]
Securing an Ubuntu Server « BioLounge – TechBlog said,
[...] nice article: http://savvyadmin.com/ubuntus-ufw/ [...]
Securing an Ubuntu Server | toombaloomba said,
[...] nice article: http://savvyadmin.com/ubuntus-ufw/ [...]
우분투 서버를 좀 더 안전하게 만들기 « Blacky said,
[...] 참고: wikipedia Ubuntu UFW Uncomplicated Firewall Examples community documentation server guide ufw manual project wiki nice article [...]
Add A Comment