A firewall is a security system that monitors and controls incoming and outgoing network traffic based on predetermined security rules. By implementing a firewall, you can reduce the risk of unauthorized access to your server.
UFW is a simple and uncomplicated firewall that makes it easy to secure your Linux server.
UFW is already installed on most Linux distributions, but if it’s not, you can install it using the package manager for your distribution. For example, on a Debian-based system, you can use the following command:
To check the status of UFW, you can use the following command:
You can use UFW to allow or deny incoming traffic based on ports and protocols.
For example, to allow incoming SSH traffic, you can use the following command:
Note that by specifying ssh above, ufw assumes you want to allow port 22 which is the default ssh port, however if you have followed by previous guide on securing the ssh on your linux servers then the above command won’t be much of an help because you would’ve changed your default ssh port to something else
You can also specify a specific port to allow or deny in ufw by following this command:
Once you have created your firewall rules, you can start UFW using the following command:
To verify that UFW is running and your rules are in place, you can use the following command:
A good practice in terms of security is to deny all incoming traffic and selectively open ports/services using the allow rule
To do this, we will use the following commands:
This basically denys all incoming traffic so your servers are not accessible from outside world and allows all outgoing traffic so you can connect to anything on the outside world.
Make sure you allow SSH as incoming traffic else even you won’t be able to connect your server via SSH.
So allow the SSH rule before enabling ufw with the above default rules.
UFW is a user-friendly firewall that makes it easy to secure your Linux server. By following the steps outlined in this guide, you can install and set up UFW, create firewall rules, and manage firewall rules in Linux.
Don’t wait – start securing your Linux server with UFW firewall today!