Ubuntu Firewall (ufw) is an interpeter for Kernel’s Netfilter package. To make it easy to understand, is some kind of iptables but more “user friendly”, which does not mean that it has a GUI.
By default, ufw comes disabled so the first thing you have to do is enable it, like this:
$ sudo ufw enable
As you may know, firewall has something called ‘Default Policy’ which defines what to if no rule applies to a specific package. For example, if our default policy is deny, if a package does not match any rule access will be blocked. To set the default policy for ufw you have to edit /etc/default/ufw and edit DEFAULT_INPUT_POLICY and DEFAULT_OUTPUT_POLICY variables.
Example.
Let’s say we want to set a “deny all” default policy and we need HTTP and FTP incoming open for everybody, SMTP outgoing enable only for our 192.168.0.0/24 network and port 2222 TCP access granted only from 8.8.8.8.
First thing we need to do is edit our /etc/default/ufw with the following variables:
DEFAULT_INPUT_POLICY="DROP"
DEFAULT_OUTPUT_POLICY="DROP"
After that, we have to enable our ufw and start writing rules to ALLOW the access we need.
$ sudo ufw enable
$ sudo ufw allow httpd
$ sudo ufw allow ftp
$ sudo ufw allow proto tcp from 192.168.0.0/24 to port 25
$ sudo ufw allow proto tcp from 8.8.8.8 to port 2222
Tags: ubuntu, ubuntu firewall, ufw