How to set up a firewall with ufw on ubuntu 22. 04

How to Set Up a Firewall with UFW on Ubuntu 22.04

For Linux users such as Ubuntu 22.04, Uncomplicated Firewall or UFW is utilized for the management of the machine’s network connections and web traffic. It is also used for controlling the traffic by setting up multiple rules for the incoming and outgoing network traffic on all or specific ports of a system.

This blog will discuss the procedure of setting up Firewall with UFW on Ubuntu 22.04:

  • using terminal
  • using GUI

Let’s get started!

Method 1: Setting up a Firewall with UFW on Ubuntu 22.04 using terminal

Before jumping into the procedure to set up a Firewall with UFW on Ubuntu 22.04, it is essential to install UFW in your Ubuntu 22.04.

Sponsored

Follow the given instructions for installing and setting up UFW in Ubuntu 22.04 using the terminal.

Step 1: Update system packages
First of all, hit “CTRL+ALT+T” and run the below-given command for updating the system packages:

$ sudo apt update

How to set up a firewall with ufw on ubuntu 22. 04 1

Step 2: Install UFW
Next, execute the provided command for the installation of UFW:

$ sudo apt install ufw -y

How to set up a firewall with ufw on ubuntu 22. 04 2

Step 3: Check UFW status
After successfully installing UFW, check out its status on your system:

$ sudo ufw status

The given output indicates that UFW is currently “inactive” on our Ubuntu 22.04:

How to set up a firewall with ufw on ubuntu 22. 04 3

Step 4: Enable UFW
Now, it’s time to enable UFW with the help of the following command:

$ sudo ufw enable

How to set up a firewall with ufw on ubuntu 22. 04 4

Step 5: Disable UFW
In case, if you want to disable UFW, then utilize the below-given command in your Ubuntu 22.04 terminal:

$ sudo ufw disable

How to set up a firewall with ufw on ubuntu 22. 04 5

Step 6: Allow traffic
Ubuntu 22.04 permits you to define UFW rules using service name or port number. For instance, to allow incoming connections for port “80”, we will execute the following command:

$ sudo ufw allow 80

How to set up a firewall with ufw on ubuntu 22. 04 6

Step 7: Check status
Again, verifying UFW status will let you know if the proceeding operation was successfully performed:

$ sudo ufw status

As you can see, port “80” is allowed to accept incoming connections from “Anywhere”:

How to set up a firewall with ufw on ubuntu 22. 04 7

Step 8: Deny traffic
Similarly, the “ufw” command with the “deny” option can be utilized for denying the traffic for port “80”:

$ sudo ufw deny 80

How to set up a firewall with ufw on ubuntu 22. 04 8

Step 9: Check UFW list
For the purpose of UFW application list, run the provided command:

$ sudo ufw app list

How to set up a firewall with ufw on ubuntu 22. 04 9

Step 10: Open UFW configuration file
We will now verify if the “IPv6” is working perfectly with UFW or not. To do so, open the UFW configuration file in “nano” editor:

See also  Security in the smart home: considerations for device makers
$ sudo nano /etc/default/ufw

How to set up a firewall with ufw on ubuntu 22. 04 10

Sponsored

Then look for the line stating “IPV6” and assign “yes” as its value:

How to set up a firewall with ufw on ubuntu 22. 04 11

Step 11: Restart UFW
After performing the required changes, restart UFW by writing out the following command:

$ sudo systemctl restart ufw

How to set up a firewall with ufw on ubuntu 22. 04 12

Lastly, check the status of UFW:

$ sudo systemctl status ufw

The given output shows that UFW is currently active and running on our Ubuntu 22.04 system:

How to set up a firewall with ufw on ubuntu 22. 04 13

Now, let’s head towards the method of setting up a Firewall using a GUI application.

Method 2: Setting up a Firewall with UFW on Ubuntu 22.0 using GUI

As an Ubuntu 22.04 user, you can also configure Firewall using UFW using its GUI application. Want to try it out? Hit “CTRL+ALT+T” and execute the provided command for the installation of the UFW GUI application named “gufw”:

$ sudo apt install gufw -y

How to set up a firewall with ufw on ubuntu 22. 04 14

After successfully installing “gufw”, launch it on your system by searching “Firewall Configuration” in the “Activities” menu and open it from there:

How to set up a firewall with ufw on ubuntu 22. 04 15

Then, specify your system password for the authentication purpose:

See also  How to install Bagisto on Ubuntu 20.04

How to set up a firewall with ufw on ubuntu 22. 04 16

The main interface of “gufw” GUI UFW application will look like this:

How to set up a firewall with ufw on ubuntu 22. 04 17

To enable the UFW Firewall, enable the highlighted “Status” toggle:

How to set up a firewall with ufw on ubuntu 22. 04 18

Similarly, select the required option for the “Incoming” and “Outgoing” connections:

How to set up a firewall with ufw on ubuntu 22. 04 19

In our case, we have denied all incoming connections and allowed UFW to accept outgoing connections:

How to set up a firewall with ufw on ubuntu 22. 04 20

How to uninstall UFW in Ubuntu 22.04

For the uninstallation of UFW in 22.04, write out the provided command in the terminal:

$ sudo apt purge gufw ufw -y

How to set up a firewall with ufw on ubuntu 22. 04 21

We have compiled the easiest method to set up a Firewall with UFW on Ubuntu 22.04 using the terminal and its GUI application.

Conclusion

For the purpose of setting up a Firewall with UFW on Ubuntu 22.04, firstly install UFW. Then, verify its status with command, enable it on your system, and allow or block incoming or outgoing connections. Furthermore, you can open the “UFW” configuration file and perform the required changes. Also, to use the “gufw” GUI UFW application, install and launch to configured UFW using GUI. This blog demonstrated the procedure of setting up a Firewall with UFW on Ubuntu 22.04.


Discover more from Ubuntu-Server.com

Subscribe to get the latest posts sent to your email.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply