When deploying any Linux server especially Debian 12 security should be your top priority. One of the first lines of defense is a well-configured firewall, helping control incoming and outgoing traffic and reducing exposure to attacks.
In this guide, you’ll learn how to install and configure a firewall on Debian 12 using two powerful tools: UFW (Uncomplicated Firewall) and iptables. Whether you’re running a personal project or a business-critical application, this tutorial will give you the confidence to lock down your system properly.
A firewall acts as a gatekeeper, filtering network traffic based on a set of rules. Without one, your server is left exposed to threats like:
Using a firewall helps you control access, minimize risks, and stay compliant with best security practices.
Before installing anything, always update your system:
sudo apt update && sudo apt upgrade -y
UFW simplifies firewall configuration with user-friendly commands.
Install UFW
sudo apt install ufw -y
Enable UFW
sudo ufw enable
Check UFW Status
sudo ufw status verbose
Allow SSH (Essential for Remote Access)
sudo ufw allow ssh
Or use port number:
sudo ufw allow 22/tcp
Allow HTTP & HTTPS
sudo ufw allow http
sudo ufw allow https
Deny All Incoming by Default, Allow All Outgoing
sudo ufw default deny incoming
sudo ufw default allow outgoing
Check Existing Rules
sudo ufw status numbered
Delete a Rule
sudo ufw delete [rule number]
If you need fine-grained control, you can use iptables
.
Install iptables-persistent
sudo apt install iptables-persistent
Example: Allow SSH with iptables
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
Save iptables Rules
sudo netfilter-persistent save
sudo netfilter-persistent save
sudo netfilter-persistent save
Use tools like nmap
from another machine to check open ports:
nmap your_server_ip
This helps verify that only necessary ports are exposed.
Securing your Debian 12 server with a firewall is simple yet powerful. Whether you're a beginner using UFW or an advanced user managing iptables, these tools can significantly reduce your attack surface.
Take a few minutes today to lock down your system it could save you from major headaches tomorrow.
At Technology Elevator, we offer professional Linux server setup, cloud security, and DevOps services to keep your infrastructure safe and scalable. Let our experts handle the technical heavy lifting so you can focus on growing your business.
👉 Contact us now and let’s elevate your security!