How to Configure the UFW Firewall in Ubuntu?

UFW, or Uncomplicated Firewall, is an easy-to-use tool for managing the firewall in Ubuntu. In this article, we’ll look at how to configure the UFW firewall on an Ubuntu server.

Step 1: Installing UFW

The first step is to install the UFW firewall. To do this, execute the following command:

sudo apt-get install ufw

After installation, you can check the firewall status by running the command:

sudo ufw status

Step 2: Configuring Firewall Rules

To configure firewall rules, you need to specify the ports you want to allow. For example, if you want to allow traffic on port 80 (HTTP), run the following command:

sudo ufw allow 80

Similarly, if you want to allow traffic on port 443 (HTTPS), execute the command:

sudo ufw allow 443

You can also allow traffic from a specific IP address, for example:

sudo ufw allow from 192.168.1.1

Step 3: Enabling the Firewall

After you have configured the necessary firewall rules, enable it with the command:

sudo ufw enable

Now your UFW firewall is active and protecting your server from unwanted traffic. You can check the firewall status using the command:

sudo ufw status

Thus, setting up the UFW firewall in Ubuntu is a simple task. Follow these steps to ensure the security of your server.