Software and Hardware Environment

  • Ubuntu 18.04 64 – bit
  • ufw

Introduction to the

The UFW is a firewall configuration tool in Ubuntu. Compared with the iptables of the original Linux firewall, it is easier to use. This article will share with you how to install, enable, and disable the UFW.

Installation and use

First, install using APT

sudo apt install ufw
Copy the code

After the UFW is installed successfully, the UFW is not started by default. You can run the following command to start and mask all ports, that is, disable all external access to the UFW, but the external access to the UFW is normal

sudo ufw enable
sudo ufw default deny
Copy the code

The firewall status is displayed, and all rules created are listed

sudo ufw status
Copy the code

Allow external access to a port, such as Web port 80

sudo ufw allow 80
Copy the code

To better tune the rules, TCP or UDP based packets can also be allowed. For example, the following example allows TCP packets on port 80

sudo ufw allow 80/tcp
Copy the code

Accordingly, external access to port 80 is prohibited, that is, the previously created rule is deleted

sudo ufw delete allow 80
Copy the code

In addition to using the port, we can also use the service name, for example

sudo ufw allow samba
sudo ufw deny telnet
Copy the code

Sometimes, to filter specific users, you can only allow access to specific IP addresses or subnets

Sudo ufw allow from 192.168.1.100 sudo Ufw allow from 172.21.2.10/24Copy the code

If you do not want to use the UFW, you can run the command to disable the SERVICE

sudo ufw disable 
Copy the code

To uninstall the UFW tool package, run the

sudo apt --purge remove ufw
Copy the code

The resources

  • Help.ubuntu.com/community/U…