How to Enable Ubuntu Firewall in Ubuntu 20.04

Uncomplicated Firewall (UFW) is the default firewall application in Ubuntu 20.04 LTS. However, it is disabled by default.

Follow these steps to enable Ubuntu Firewall on Ubuntu 20.04:

Add a new Firewall rule to allow SSH port 22:

sudo ufw allow 22/tcp

After that, enable the firewall with the following command:

sudo ufw enable

As you can see, enabling Ubuntu Firewall is a Two-step process. First, we must open the SSH port. Otherwise, we will not be able to ssh to our server after enabling UFW because by default Ubuntu firewall blocks all incoming network traffic.

That is why we must open SSH port 22 before anything else. After that we can enable the firewall with ufw enable command.

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
How to Enable Ubuntu Firewall in Ubuntu 20.04