A beginner's guide to using UFW in Linux
How To Set Up And Configure Linux Firewall for Beginners.
UFW stands for "Uncomplicated Firewall." It is a powerful network security tool and one of my favorites because it is simple to use and incredibly powerful. In this article, I will explain how to set up UFW and manage firewall rules on a Linux system. Before we can learn how to use this fantastic tool, we must first understand what it is.
What Is UFW?
UFW is a network security tool that is used to protect your system from internet threats such as viruses, malware, and other cyber attacks. It works by monitoring incoming connections in the design and rejecting all traffic that does not originate from trusted sources. This way, no unauthorized programs can connect to your system without being detected by UFW.
UFW is available on most modern Linux distributions, including Ubuntu. UFW simplifies the process of configuring firewall rules, making it easy for beginners to set up a basic firewall on their system.
Installing UFW
The first step is to install UFW on your Linux system. UFW is usually pre-installed on most modern Linux distributions, but you can check if it is installed by running the following command:
sudo ufw status
If UFW is not installed, you can install it using your distribution package manager. For example, on a Debian-based system, you can use the following command:
sudo apt-get install ufw
Enabling and Disabling UFW
Once UFW is installed, you can enable it by running the following command:
sudo ufw enable
This will enable UFW and set the default policy to deny all incoming connections and allow all outgoing connections.
You can also disable UFW with the following command:
sudo ufw disable
To re-enable it, use the following command:
sudo ufw enable
Adding and Denying Firewall Rules
You can use UFW to allow or deny specific connections based on port number, protocol, and port range.
To allow or deny incoming connections, use the following commands:
Allow incoming connections:
sudo ufw allow <port number>
Deny incoming connections:
sudo ufw deny <port number>
For example, to allow incoming connections on port 80 (HTTP), you can run the following command:
sudo ufw allow 80
You can also allow connections based on the protocol and port range. For example, to allow all incoming TCP connections on ports 20-22, you can run the following command:
sudo ufw allow 20:22/tcp
Also, to deny incoming connections on port 25 (SMTP), you can run the following command:
sudo ufw deny 25
How to check the status of connections in UFW?
You can check the current firewall rules by running the following command:
sudo ufw status verbose
This will list out all the connections that are allowed and denied by your firewall.
Reset Firewall Rules
If you want to reset the firewall rules and start over, you can run the following command:
sudo ufw reset
This will reset the firewall rules to the default policy (deny all incoming connections and allow all outgoing connections).
Conclusion:
If you’re looking for a way to block incoming connections on your Linux machine, UFW is an excellent choice. It allows you to define rules for who can connect and when, as well as how many attempts are allowed before allowing the connection. This makes it easier than ever before to keep your computer secure while still allowing access through certain applications or services.
I hope you enjoy this article.
/