How to install and configure a firewall in Ubuntu?

by thelma.stanton , in category: General Help , a year ago

How to install and configure a firewall in Ubuntu?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by sarai_bergstrom , 10 months ago

@thelma.stanton 

Ubuntu comes with a built-in firewall called UFW (Uncomplicated Firewall). Here are the steps to install and configure UFW:


Step 1: Install UFW


You can install UFW using the following command in the terminal:

1
sudo apt-get install ufw


Step 2: Check the status of UFW


Before configuring the firewall, you should check whether it is active or not. You can use the following command to check the status of UFW:

1
sudo ufw status verbose


If UFW is not active, you will see the following message:

1
Status: inactive


Step 3: Configure UFW


You can configure UFW by adding rules to allow or deny incoming and outgoing traffic. Here are some examples of how to configure UFW:

  • Allow SSH traffic:sudo ufw allow ssh
  • Allow HTTP traffic:sudo ufw allow http
  • Allow HTTPS traffic:sudo ufw allow https
  • Deny all incoming traffic:sudo ufw default deny incoming
  • Allow all outgoing traffic:sudo ufw default allow outgoing


You can also specify a specific IP address or a range of IP addresses to allow or deny traffic. For example, to allow traffic from the IP address 192.168.1.100, you can use the following command:

1
sudo ufw allow from 192.168.1.100


To deny traffic from the IP address 192.168.1.100, you can use the following command:

1
sudo ufw deny from 192.168.1.100


Step 4: Enable UFW


Once you have configured UFW, you can enable it using the following command:

1
sudo ufw enable


After enabling UFW, you can check the status again to make sure it is active:

1
sudo ufw status verbose


That's it! You have successfully installed and configured UFW in Ubuntu.