How to Enable and Disable UFW Ubuntu Firewall

In this tutorial, we will learn how to enable and disable UFW Ubuntu Firewall. The UFW Firewall is installed on Ubuntu out of the box, but by default, it is disabled.

Enable Ubuntu Firewall

It is easy to enable Ubuntu Firewall using the ufw enable command. But before that, we need to make sure we also add a Firewall rule to allow ssh connection to our Ubuntu Server. Otherwise, you will be locked out of your own server.

sudo ufw allow 22/tcp
sudo ufw enable

The first command allows ssh port 22 from the Ubuntu firewall. Then we enable the firewall using the ufw command.

You will receive the following message: Firewall is active and enabled on system startup.

You can view the UFW Firewall status using the following command:

sudo ufw status
Enable UFW Firewall

Disable Ubuntu Firewall

To disable ufw, run the ufw disable command:

sudo ufw disable

When you disable UFW, you should receive the following message on your terminal: Firewall stopped and disabled on system startup.