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

Setting up a firewall on your Ubuntu 24.04 system is an essential step in securing your computer from potential threats and attacks. The Uncomplicated Firewall (UFW) is a user-friendly tool that allows you to easily manage your firewall settings without having to delve into complex configurations. In this article, we will guide you through the process of setting up UFW on your Ubuntu 24.04 system, perfect for beginners who are new to firewall management.

Step 1: Installing UFW

The first step is to ensure that UFW is installed on your Ubuntu system. To do this, open a terminal and type the following command:

sudo apt-get install ufw

Enter your password when prompted, and UFW will be installed on your system.

Step 2: Configuring UFW

Once UFW is installed, the next step is to configure the firewall settings. By default, UFW is disabled, so you will need to enable it. To do this, type the following command in the terminal:

sudo ufw enable

You will be prompted to confirm the action. Press ‘y’ and hit Enter to enable the firewall.

Step 3: Allowing SSH Access

If you are using SSH to remotely access your Ubuntu system, it is important to allow SSH traffic through the firewall. To do this, type the following command in the terminal:

sudo ufw allow ssh

This will allow incoming SSH connections to your system.

Step 4: Allowing Other Services

If you have other services running on your system that you want to allow through the firewall, you can use similar commands to allow traffic for those services. For example, if you are running a web server, you can allow traffic on port 80 by typing:

sudo ufw allow 80

You can check the status of UFW and see a list of allowed services by typing:

sudo ufw status

This will show you a summary of the firewall settings and the status of UFW.

Step 5: Denying Traffic

If you want to block specific traffic, you can deny it using UFW. For example, if you want to block traffic on port 22, you can type:

sudo ufw deny 22

This will block incoming traffic on port 22.

Step 6: Disabling UFW

If you ever need to disable UFW, you can do so by typing:

sudo ufw disable

This will turn off the firewall and allow all traffic through.

By following these simple steps, you can set up and configure UFW on your Ubuntu 24.04 system to enhance the security of your computer. Remember to regularly review and update your firewall settings to ensure that your system is protected from potential threats.