In this article we will learn how to enable/disable firewall on Ubuntu 20.04 using graphic UI and command line. We will also learn how to flush firewall blocks.

Manage Firewall (ufw) via GUI

By default my Ubuntu 20.04 installation does not include firewall. So, first we will install firewall. Go to Ubuntu Software, find “ufw” and find “gufw” and install.

Install UFW Firewall

GUI

Install GUI for UFW

Next you can go straight to the Firewall Configuration program and disable/enable it with a click of a mouse in Ubuntu.

Enable/Disable Firewall via GUI

You can also create Rules in the same program to increase security of the server. Let’s create an example access rule so that this server’s SSH can be accessed only from certain IP.

Creating Rules in Firewall Configuration

Manage Firewall via Terminal

First of all, let’s check status of our firewall.

~$ sudo ufw status
Status: active

If you see status active, this means that firewall is installed and enabled. If you see something like “command ufw not found”, this means that firewall is not installed. You can install it via terminal using command:

$ sudo apt install ufw

To disable/enable firewall use the below commands:

~$ sudo ufw enable
Firewall is active and enabled on system startup

sudo ufw disable
Firewall stopped and disabled on system startup

As you can se, it’s quite easy to manage Ubuntu firewall via command line. Now let’s add a test rule via command line.

~$ sudo ufw allow from 5.252.152.238 proto tcp to any port 22
Rules updated

If you want to delete created rule, use command sudo ufw delete followed by the exact rule:

~$ sudo ufw delete allow from 5.252.152.238 proto tcp to any port 22
Rules updated

To block an IP, use this command:

~$ sudo ufw deny from 5.252.152.238
Rules updated

To allow IP:

~$ sudo ufw allow from 5.252.152.238
Rules updated

As you can see the commands are pretty simple and easy to remember. If you want to learn more rules and options with ufw firewall you can always read this wiki or type in the terminal man ufw to see the manual.