How to Enable/Disable Firewall on Ubuntu 22.10/22.04/20.04

When it comes to firewall protection for your system, the default Ubuntu UFW program is a great option. For newer users of Ubuntu and Linux, UFW is short for “uncomplicated firewall.” UFW allows users with little knowledge of how Linux IPTABLES can secure their home network or server without the need to learn complicated long-tail commands that are more for the sysadmin side of things, where most users want to add and remove rules. The UFW program was designed with the home user in mind but can be used by any user for a home network or server and can be easily extended if more advanced features are needed.

The following tutorial will teach you how to check, enable and disable the UFW firewall and, for desktop users, install the firewall GUI to better control UFW for users that do not want to use the terminal in the future.

Important Notice

The following tutorial was done with a Ubuntu 22.04 Jammy Jellyfish release, and example images were taken. Still, it was tested on Ubuntu 20.04 Focal Fossa and Ubuntu 22.10 Kinetic Kudu. In the future, if Ubuntu makes any changes to break the tutorial for one of the distribution versions, please place a comment for me to investigate so I can update the tutorial.

Check UFW Firewall Status on Ubuntu Linux

For users new to Ubuntu, you can open the command terminal, which you can open following the top right-hand corner Activities > Show Applications > Terminal.

Example:


launch terminal on ubuntu linux

Next, find out the status of your UFW firewall using the command.

sudo ufw status

Example output:

check ufw status on ubuntu linux

The firewall is inactive, as Ubuntu does not enable this by default for new installations.

Enable UFW Firewall on Ubuntu Linux

The next step is to enable the firewall, which will block all incoming connections and allow all outgoing connections. This will immediately help secure your system.

You may lock yourself out for server users or any other user using an SSH remote connection session. You can add UFW rules while the service is inactive, allowing the SSH service.

sudo ufw allow ssh

Desktop users that do not use or know what SSH is, skip the command above.


Example output:

 add a rule on ubuntu linux

Using the following command, enable the firewall.

sudo ufw enable

Example output:

enable ufw on ubuntu linux

Next, recheck your Ubuntu firewall by re-using the ufw status command.

sudo ufw status

Example output:

ufw status on ubuntu linux

As mentioned above, the firewall is enabled, and for users that had to allow SSH, you can see this is now in the allowed action.


Additionally, you can run the ufw status command with verbose attached for an even more detailed view.

sudo ufw status verbose

Example output:

disable ufw on ubuntu linux

Besides the allow and deny actions (rules), you can see the default firewall settings to deny all incoming and allow all outgoing.

Disable UFW Firewall on Ubuntu Linux

Next, you can use the following command for users wishing to disable their firewall.

sudo ufw disable

Example output:

How to Enable/Disable Firewall on Ubuntu 22.04 LTS

Install UFW Firewall GUI on Ubuntu Linux

For users new to Linux, while in the terminal, you can install a software package that will control UFW with a graphical interface with the following command if you do not fancy using the terminal.


sudo apt install gufw -y

Next, go to the top left-hand corner and follow Activities > Show Applications > Firewall Configuration to bring up the GUI.

Example:

install gufw on ubuntu linux

Next, you can enable or disable the UFW firewall and other more manageable settings.

Example GUI:

launch and use gufw on ubuntu linux

As mentioned above, you can now adjust connections of default incoming and outgoing connections, check status, create rules, see logs and reports, and more, making using a firewall a much more enjoyable task for non-terminal users.


Not what you were looking for? Try searching for additional tutorials.

Leave a Comment