How to Set Up UFW Firewall on Ubuntu 24.04 (for Beginners)

Uncomplicated Firewall, or UFW, is a user-friendly interface for managing firewall settings in Ubuntu. Setting up a firewall is important for securing your system against potential threats and unauthorized access. In this article, we will guide you through the process of setting up UFW on Ubuntu 24.04, specifically tailored for beginners.

Step 1: Installing UFW
First, make sure that UFW is installed on your system. You can do this by running the following command in the terminal:

sudo apt install ufw

Enter your password when prompted, and wait for the installation to complete.

Step 2: Enabling UFW
Once UFW is installed, you need to enable it by running the following command:

sudo ufw enable

You will see a message confirming that the firewall is active.

Step 3: Setting Default Policies
By default, UFW denies all incoming connections and allows all outgoing connections. You can adjust these default policies by running the following commands:

sudo ufw default deny incoming
sudo ufw default allow outgoing

These commands set the default policies to deny all incoming connections and allow all outgoing connections.

Step 4: Allowing Specific Ports
If you need to allow specific incoming connections, you can do so by specifying the port number. For example, to allow SSH connections, you can run the following command:

sudo ufw allow ssh

This command allows incoming SSH connections on port 22. You can also specify a custom port by replacing ‘ssh’ with the desired port number.

Step 5: Checking UFW Status
To check the status of UFW and see a list of current rules, you can run the following command:

sudo ufw status

This will display a summary of the firewall status, including active rules and default policies.

Step 6: Disabling UFW
If you need to temporarily disable UFW, you can do so by running the following command:

sudo ufw disable

This will turn off the firewall until you re-enable it using the ‘sudo ufw enable’ command.

Setting up a firewall is an essential step in securing your system, and UFW provides an easy-to-use interface for managing firewall settings in Ubuntu. By following the steps outlined in this article, beginners can set up UFW on Ubuntu 24.04 and enhance the security of their system.