November 19, 2024
Tutorials

How to Install UFW on Ubuntu 22.04

How to Install UFW on Ubuntu 22.04

UFW stands for “Uncomplicated Firewall,” and it is a user-friendly command-line interface for managing iptables, which is a firewall management tool in Ubuntu and many other Linux distributions. UFW is designed to make it easier for users, especially those who are not well-versed in firewall configuration, to set up and manage network filtering rules to enhance system security.

If you have installed the complete version of Ubuntu 22.04, then you will get it by default. However, in some cases, if you haven’t been able to find UFW on your Ubuntu 22.04, then stick with this write-up; we have covered it all here.

In this guide, we will elaborate on the installation methods of UFW on Ubuntu 22.04  (The latest LTS of Ubuntu at the time of writing this guide).

How to Install UFW on Ubuntu 22.04?

UFW, as mentioned earlier, is usually used as a gateway for Linux-based systems. It allows the administrators to manage the incoming and outgoing traffic. Let us dig into the methods to install UFW on your Ubuntu 22.04:

Method 1: Install UFW Using apt

The apt method is the most recommended and the easiest way to get UFW on Ubuntu 22.04. Let us drill down the method in a step-by-step procedure:

Step 1: Update the Packages List

Let us first load the updated packages into our repository using the command:

$ sudo apt update

Step 2: Install UFW

Use the apt install command to install UFW on your Ubuntu 22.04. This can be done using the command:

$ sudo apt install UFW

The successful execution of the command ensures that the UFW has been installed.

Method 2: Install UFW Using the Snap

Snap is another useful utility in Linux-based systems. It offers a wide range of utilities that the official repository of your distribution may not offer. Let us see how this method works:

Step 1: Install Snapd

Usually, snapd (the service that manages the snap) is available on Ubuntu 22.04. If not, you can use the following command to get it on your system:

$ sudo apt install snapd

It is mandatory to enable and start the snapd service on your system as well. For this, you can use the following command (it is the combination of two commands):

$ sudo systemctl enable snapd && sudo systemctl start snapd

Step 2:  Install UFW Via Snap

Once the snapd service is installed and configured, you can now install UFW via a snap in the following manner:

$ sudo snap install ufw

How to Configure UFW on Ubuntu 22.04?

Once the user has installed the UFW utility using any of the abovementioned methods. Now, it’s time to configure it. UFW utility offers a list of useful commands to handle the traffic. Let’s list a few important ones:

Activate the Firewall

$ sudo ufw enable

Check the Current Status of the UFW

$ sudo ufw status

Allow Any Protocol/Port Through the Firewall

$ sudo ufw allow <port>/<protocol>.

Let’s allow SSH connections via UFW by using the keyword “ssh”:

$ sudo ufw allow ssh

Block Any Protocol/Port Through the Firewall

$ sudo ufw deny <port>/<protocol>.

Let’s say you want to deny the SSH over UFW. You can do it as:

$ sudo ufw deny ssh

Deactivate/Disable the Firewall

$ sudo ufw disable

These were most of the commands used to manage the traffic using the UFW utility on Ubuntu 22.04.

How to Remove UFW From Ubuntu 22.04?

UFW is a useful utility for your Ubuntu 22.04. However, if you do not need it anymore after its use. We are here to help you out and demonstrate the methods to remove it from Ubuntu 22.04. The uninstallation method depends on the method you used for installation. Let’s discuss both removal methods:

Remove UFW Using the apt

The command to remove UFW, if installed via snap, is as follows:

$ sudo apt autoremove ufw

Remove UFW Using the Snap

The users can exercise the following command in the terminal to remove the UFW installed from snap:

$ sudo snap remove ufw

That’s all about the installation methods and details of UFW for Ubuntu 22.04 users.

Bottom Line

There are two potential methods to install UFW on Ubuntu 22.04, i.e., using the apt and snap. The apt method is used mostly and is recommended for Ubuntu 22.04. The command to install UFW via apt is “sudo apt install ufw”. Moreover, the second method uses the snap store to get the UFW utility on the user’s system. The users can use the command “sudo snap install ufw” to get it.

This post has provided two methods to install UFW on Ubuntu 22.04. Moreover, some useful commands to manage a firewall via UFW are also discussed.