How to Setup UFW Firewall on Ubuntu 20.04

Setup UFW Firewall on Ubuntu 20.04

In this article, we will have explained the necessary steps to install and setup UFW Firewall on Ubuntu 20.04. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

UFW (Uncomplicated Firewall) is a tool available in Ubuntu distribution to configure iptables. In other words, it is a front-end for iptables. The tool enables us to set up a host-based firewall. A host-based firewall is best suited for individual devices which are connected to internet. With host-based firewalls we could protect our devices from potential threats like viruses, malware, hackers etc. Although, the package for UFW is available in Ubuntu distributions but it is not enabled by default.

Setup UFW Firewall on Ubuntu

Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.

sudo apt update
sudo apt upgrade

Step 2. Install UFW on Ubuntu system.

Installing Uncomplicated Firewall (UFW) is pretty straight-forward:

sudo apt install ufw

Step 3. Configure UFW Firewall.

Now we got basic configuration enabled. In other words, the firewall will drop all incoming traffic except for ssh TCP port 22. Let us true it on the UFW, enter:

sudo ufw allow 22/tcp

After that, enable the firewall with the following command:

sudo ufw enable

To see a quick summary of your firewall configuration, run the status command:

sudo ufw status

If you are running a web server, you also need to open both http and https ports:

sudo ufw allow http
sudo ufw allow https

That’s all you need to do to setup UFW Firewall on Ubuntu 20.04 LTS Focal Fossa. I hope you find this quick tip helpful. Don’t forget to share your valuable queries/suggestions in the below comment box & also drop your worthwhile feedback.