How to Install UFW Firewall on Ubuntu 16.04

r00t January 4, 2018

Install UFW Firewall on Ubuntu 16.04

In this tutorial we will show you how to install UFW Firewall on Ubuntu 16.04. We will also install and configure its prerequisites.The UFW (uncomplicated firewall) is a front-end for managing firewall rules and it is easy to utilize for host-based firewalls. The UFW is used through the command line interface and plans to make firewall configuration simple.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Ubuntu 16.04 minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install UFW Firewall on Ubuntu 16.04

Step 1. First, ensure your system and apt package lists are fully up-to-date by running the following:

apt-get update -y
apt-get upgrade -y

Step 2. Installing UFW Firewall.

UFW is installed by default with Ubuntu, if not installed then we will install them using the below command:

sudo apt-get install ufw

Check the install:

ufw --version

And that is it, not much to the install and setup here. Nothing to enable or restart with systemd since UFW is a wrapper for iptables and netfilters:

ufw enable

Once enabled, ufw will be active and will start on system boot. Please note that all the incoming connections will be denied by default while the outgoing connections will be allowed. To check the default configuration, you can use the following command:

sudo ufw show raw

Attention! The following are examples, please use only if you know what you are doing!

Allow connections to SSH:

sudo ufw allow ssh

Enable other services:

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 21/tcp

Allow connections from specific IP addresses:

sudo ufw allow from

For more usage commands you can use the –help flag:

sudo ufw --help

Most common uwf commands:

 enable                          enables the firewall
 disable                         disables the firewall
 default ARG                     set default policy
 logging LEVEL                   set logging to LEVEL
 allow ARGS                      add allow rule
 deny ARGS                       add deny rule
 reject ARGS                     add reject rule
 limit ARGS                      add limit rule
 delete RULE|NUM                 delete RULE
 insert NUM RULE                 insert RULE at NUM
 route RULE                      add route RULE
 route delete RULE|NUM           delete route RULE
 route insert NUM RULE           insert route RULE at NUM
 reload                          reload firewall
 reset                           reset firewall
 status                          show firewall status
 status numbered                 show firewall status as numbered list of RULES
 status verbose                  show verbose firewall status
 show ARG                        show firewall report
 version                         display version information

Application profile commands:
 app list                        list application profiles
 app info PROFILE                show information on PROFILE
 app update PROFILE              update PROFILE
 app default ARG                 set default application policy

Congratulation’s! You have successfully install and configured UFW Firewall on your Ubuntu 16.04 server. Thanks for using this tutorial installing UFW Firewall on Ubuntu 16.04 LTS (Xenial Xerus) system.

The Tags:

Leave a Comment

Comments are closed.