UFW, or Uncomplicated Firewall, is a user-friendly frontend for the iptables firewall on Linux systems. It is a powerful tool that allows you to easily configure and manage the firewall on your system, helping to protect it from unwanted access and other security threats.
In this article, we will show you how to set up a firewall with UFW on Debian 11 (also known as “Bullseye”). We will be using the command line for this tutorial, so you will need to have a basic understanding of how to use the Linux command line.
Before we begin, there are a few prerequisites that you will need to have in place in order to set up a firewall with UFW on your system:
- A server running Debian 11
- A user account with sudo privileges
- The UFW firewall installed
To install UFW, run the following command:
sudo apt install ufw
Once you have these prerequisites in place, you can proceed with the tutorial.
Check the current status of the firewall
Before you begin configuring your firewall, it is always a good idea to check the current status of the firewall to see if it is already enabled or disabled. To do this, run the following command:
sudo ufw status
This will display the current status of the firewall, along with any rules that are currently in place.
Enable the firewall
To enable the firewall, run the following command:
sudo ufw enable
This will enable the firewall and apply any default rules that are configured.
Allow incoming connections
By default, UFW will block all incoming connections to your system. This means that your system will not be accessible from the internet unless you explicitly allow incoming connections for the services that you want to make available.
To set up firewall rules with UFW, you can use the “ufw allow
” and “ufw deny
” commands, followed by the name or port number of the service that you want to allow or deny. Here are a few examples of firewall rules that you might use with UFW:
- Allow incoming connections for the SSH service on port 22:
sudo ufw allow ssh
- Allow incoming connections for the HTTP service on port 80:
sudo ufw allow http
- Allow incoming connections for the HTTPS service on port 443:
sudo ufw allow https
- Allow incoming connections for the FTP service on port 21:
sudo ufw allow ftp
- Allow incoming connections for the SMTP service on port 25:
sudo ufw allow smtp
- Allow incoming connections for the IMAP service on port 143:
sudo ufw allow imap
Deny incoming connections
If you want to block incoming connections for a particular service, you can use the “ufw deny
” command followed by the name or port number of the service. For example, to block incoming connections on port 23
, 53
and 80
, you can use the following commands:
- Deny incoming connections for the Telnet service on port 23:
sudo ufw deny telnet
- Deny incoming connections for the DNS service on port 53:
sudo ufw deny domain
- Deny incoming connections for the HTTP service on port 80:
sudo ufw deny http
These are just a few examples of the types of firewall rules that you can create with UFW. You can use the “ufw allow
” and “ufw deny
” commands to allow or deny incoming connections for any service that uses a well-known port number. You can also specify custom port numbers to allow or deny connections for services that use non-standard ports.
Check the firewall rules
To view the current firewall rules that are in place, you can use the “ufw status
” command. For example, to view the rules for incoming connections, you can use the following command:
sudo ufw status verbose
This will display a list of the current firewall rules, including the default rules and any rules that you have explicitly added.
Conclusion
In this article, we showed you how to set up a firewall with UFW on Debian 11. We covered all of the necessary steps, including checking the current firewall status, enabling the firewall, allowing and denying incoming connections, and viewing the firewall rules. With UFW configured and enabled on your system, you can now easily manage and control incoming