In this tutorial, we will show you how to setup UFW Firewall on Debian 11. For those of you who didn’t know, UFW (Uncomplicated Firewall), is the most popular and easy-to-use command-line tool for configuring and managing a firewall on Debian-based distributions. Ufw protects the server by monitoring the incoming and outgoing traffic of the network connections of a server.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘
sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Setup UFW Firewall on a Debian 11 (Bullseye).
- A server running one of the following operating systems: Debian 11 (Bullseye).
- It’s recommended that you use a fresh OS install to prevent any potential issues
non-root sudo useror access to the
root user. We recommend acting as a
non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.
Setup UFW Firewall on Debian 11 Bullseye
Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following
apt commands in the terminal:
sudo apt update sudo apt upgrade
Step 2. Installing UFW Firewall on Debian 11.
By default, UFW Firewall is available on Debian 11 base repository. So, now run the following command below to install UFW on your Debian system:
sudo apt install ufw
Once the installation is complete, now enable UFW (to start automatically upon system boot) and verify the status using the commands below:
sudo ufw status sudo ufw enable
Step 3. Configure UFW Firewall Rules.
- Default policies of UFW
Allowing rules is quite simple from the command line, and it is sometimes necessary. For example, by default UFW denies all of the incoming connections, which will make it a problem if you are using SSH. Therefore, you must create a rule which allows SSH connections using the following command below:
sudoufw allow ssh
Other rules may be added in the same way by simply specifying the name of the program. UFW comes with preloaded defaults for some commonly used programs, and they are automatically activated when you make a rule by specifying the name of the program. If we want to display the list of the applications then we will run the following command:
sudo ufw app list
- Port Ranges
Port ranges may also be specified, a simple example for TCP would be:
sudoufw allow 2000:3000/tcp
and for UDP:
sudoufw allow 2000:3000/udp
- IP address
An IP address may also be used:
sudo ufw allow from 111.222.333.444
Step 4. Install a Graphical user interface for UFW firewall.
Those who are using Graphical Desktop Linux can install a graphical user interface for their UFW firewall called “GUFW” (Graphical Uncomplicated Firewall). Run the following command below to install it:
sudo apt install gufw
Congratulations! You have successfully configured UFW Firewall. Thanks for using this tutorial for installing the latest version of the UFW Firewall on Debian 11 Bullseye. For additional help or useful information, we recommend you check the official UFW website.