Site icon Linux Genie

How to Set Up a Firewall with UFW on Ubuntu 24.04?

Setup firewall

Setting up a firewall is an important step in securing your Ubuntu server. A firewall works as a hurdle between your server and the internet. In addition, it controls incoming as well as outgoing traffic depending on a set of rules. One of the most user-friendly firewalls for Ubuntu servers is UFW, which stands for Uncomplicated Firewall. It provides a more accessible interface for managing iptables rules, making it an excellent choice for those who may not be as comfortable with the command line.

The supported guideline is given below:

Let’s start the guide using the terminal interface.

Setting Up a Firewall with UFW on Ubuntu 24.04

Ubuntu 24.04 has a built-in solution called Uncomplicated Firewall (UFW), which provides a user-friendly way to manage your firewall settings. Let’s go to the step-by-step instructions for setting up UFW on Ubuntu 24.04:

Step 1: Update System Packages

Before users begin, ensure the system is up-to-date with the most recent packages:

sudo apt update
sudo apt upgrade

Step 2: Install UFW (If Not Installed)

If UFW is not pre-installed on the Ubuntu system, users can install this one with the apt command:

sudo apt install ufw

Step 3: Check UFW Status

To check whether UFW is active, use the “status” utility. It shows users the current status of UFW and any rules that are already configured:

sudo ufw status

Step 4: Set up Default Policies

By default, UFW allows all outgoing traffic and blocks all incoming traffic. For setting up policies, execute the below commands:

sudo ufw default allow outgoing
sudo ufw default deny incoming

Step 5: Allow SSH Connections

Allowing SSH connections is vital for the remote management of the server. Let’s enable SSH access (assuming default port 22):

sudo ufw allow ssh

If you’re using a custom SSH port (e.g., 4242), allow it:

sudo ufw allow 4242/tcp

Allow Other Services (Optional)

Users may need to allow traffic for them depending on the services running on the server. For example, to allow web traffic on HTTP and HTTPS, use the below “ufw” utility:

sudo ufw allow http
sudo ufw allow https

Step 6: Enable UFW

After setting up rules, enable UFW with the “sudo” privileges. It activates the firewall and applies the rules you’ve set:

sudo ufw enable

Step 7: Verify Configuration

Finally, verify that UFW is active and the rules are applied as intended. In this way, users can verify the firewall status:

sudo ufw status
sudo ufw status verbose # For Extensive Information

By following these steps, users have a basic firewall setup on their Ubuntu 24.04 server.

Setting Up a Firewall with UFW on Ubuntu 24.04 Using GUFW

GUFW is a powerful GUI for managing UFW that simplifies the process of configuring your firewall. It’s a straightforward process that offers an extra layer of security for the system.

Here’s a step-by-step guide to setting up your firewall with GUFW on Ubuntu 24.04:

Step 1: Install GUFW

Before users can use GUFW, install it. For instance, use the “gufw” package name with the “apt” command:

sudo apt install gufw

Remember, a firewall is an essential part of the system’s defense strategy, and GUFW makes it accessible to everyone.

Step 2: Access GUFW

Once GUFW is installed, users can access it through the desktop environment. For this, search for GUFW in the application menu and open it from the Activities menu:

Step 3: Configure Your Firewall

With GUFW open, users can now configure their firewall settings. It presents a simple interface for managing your UFW firewall settings:

Enable or Activate GUFW

Toggle the switch to enable or disable the firewall. If your firewall is disabled, users can turn it on from the Status option:

GUFW Rules

Users can manage their UFW rules from the Rules section. They can also define rules in three different sections: preconfigured, simple, and advanced:

GUFW Profiles

Users can manage firewall settings through different profiles based on their network environment or usage scenarios. Typical profiles include Home, Office, Public, and Custom:

By following these steps, users can easily set up a firewall on the Ubuntu 24.04 system using GUFW.

Remember, managing a server’s firewall requires careful consideration of the services you need to be accessible and the level of security you wish to enforce.

Conclusion

UFW is ideal for beginners who simplify the process of setting firewall rules. To set up a firewall with UFW on Ubuntu 24.04, set the default UFW policies to deny incoming and allow outgoing connections, and configure UFW to allow SSH connections. Then, enable UFW with the “sudo ufw enable” command. Finally, check the status of UFW with the “sudo ufw status” command to ensure that it’s active and running as expected.

Alternatively, GUFW makes it easy to set up rules for incoming as well as outgoing traffic depending on IP addresses, ports, and protocols. It also allows for the creation of custom rules, enabling or disabling the firewall, and monitoring active connections.

This article has explained CLI as well as GUI methods for setting a Firewall with UFW on Ubuntu 24.04.

Exit mobile version