How To Setup UFW (Uncomplicated Firewall) On Ubuntu 24.04 LTS

In this tutorial, we are going to show you the method to set up  UFW or Uncomplicated Firewall on Ubuntu 24.04 LTS. It is an user-friendly application that manages iptables-based firewalls on Ubuntu.

How To Setup UFW On Ubuntu 22.04 LTS

Let’s have a look at the step-by-step method to set up UFW on Ubuntu 24.04 LTS.

UFW  is already installed on Ubuntu 24.04 LTS By default. You can run the following command to see whether the UFW is installed or not.

which ufw

If it does not return the path to the command then run the following command to install UFW on Ubuntu 24.04 LTS.

Install UFW On Ubuntu 24.04 LTS

sudo apt install ufw

and run the following command to enable UFW as  the firewall is not enabled by default

sudo ufw enable

You can verify that UFW is running by running the following command:

sudo ufw status verbose

Run the following command to turn off or disable the UFW.

sudo ufw disable

Set Up default UFW policies On Ubuntu 24.04 LTS

Run the following command to block all incoming connections and only allow outgoing connections from the Ubuntu 24.04 LTS:

sudo ufw default allow outgoing
sudo ufw default deny incoming

Make sure IPv6 support enabled too. by running the following command:

grep IPV6 /etc/default/ufw

Open SSH TCP port 22 using the ufw On Ubuntu 24.04 LTS

Run the following command to allow incoming SSH connections on the default TCP port 22 as follows:

sudo ufw allow ssh

For example you are running the OpenSSH server on TCP port 1222, then run the following command :

sudo ufw allow 1222/tcp

You can limit ssh port access to combat bots:

sudo ufw limit ssh

UFW Allow Command To Allow Incoming Connections.

Run the following command to allow SSH access.

sudo ufw allow 22

Run the following command to deny the connection from port 80:

sudo ufw deny 80

Allow a specific IP Address

Run the following command to allow the specific IP address on Linux. The command below will allow the IP 192.168.1.117 to access all ports on the server:

sudo ufw allow from 192.168.1.117

Disable and Reset UFW on Ubuntu 24.04 LTS

Command to turn off or disable UFW on Ubuntu 24.04 LTS

sudo ufw disable

Deleting a UFW Firewall Rule On Ubuntu 24.04 LTS

If you want to delete UFW firewall rule then run the following command to delete a UFW firewall rule on Ubuntu 24.04 LTS.

sudo ufw delete allow ssh

Leave a comment

Your email address will not be published. Required fields are marked *