082 | Firewall Basics: UFW — Simple and Powerful Protection
Published on 2025-08-14
Introduction: The First Line of Defense for Your Server
Before thinking about complex intrusion detection systems such as Fail2ban or CrowdSec, you need to build the first and most reliable line of defense—a firewall. A firewall controls all network traffic entering and leaving your server and blocks unauthorized connection attempts.
Traditionally, Linux servers have used iptables to manage firewalls, but its syntax can be complicated and confusing. Fortunately, there is a simpler and more intuitive tool — UFW (Uncomplicated Firewall).
What Is UFW and Why Is It Important?
UFW is a user interface for managing iptables (or nftables on modern systems). Its main purpose is to make firewall configuration as simple and accessible as possible, even for beginner system administrators. UFW is not a new firewall but a convenient “wrapper” around Linux’s built-in mechanisms, allowing you to quickly and accurately set up basic security rules.
Why UFW is important:
- Principle of least privilege: By default, a server should be closed to all external traffic except explicitly allowed services (e.g., SSH or HTTP/HTTPS). UFW makes it easy to enforce this principle.
- Reducing the attack surface: Closing unnecessary ports and services minimizes potential “entry points” for attackers.
Key Features and Benefits of UFW
Simplicity and intuitiveness: This is the main advantage. Instead of long and complex
iptablescommands, UFW uses simple and logical syntax:# Allow incoming traffic on port 22 (SSH) sudo ufw allow 22/tcp # Deny incoming traffic on port 8080 sudo ufw deny 8080/tcpSecure default rules: UFW allows you to easily configure default rules, which is a best security practice.
# Deny all incoming traffic by default sudo ufw default deny incoming # Allow all outgoing traffic by default sudo ufw default allow outgoingThis creates a strong foundation on which you can then add specific service rules.
Support for application profiles: UFW can manage rules for popular applications by name. If you have, for example, installed an Apache web server, you can allow access to it with one command.
# Allow traffic for Apache sudo ufw allow 'Apache'This command automatically opens ports 80 (HTTP) and 443 (HTTPS), which is very convenient.
Easy management and logging: You can check the current firewall status and list of rules with one command:
sudo ufw status verboseYou can also enable logging to track blocked access attempts:
sudo ufw logging on
Limitations and Considerations of UFW
Limited flexibility for complex tasks: For most typical tasks, UFW is ideal. However, if you need very complex routing, NAT, or other specific rules, UFW may not be enough. In such cases, you may need to work directly with
iptablesornftables.Backend dependency: UFW is just a “wrapper.” All its commands are ultimately translated into
iptablesornftablesrules. If you are already using complex manually configured rules, they may conflict with UFW.
Conclusion
UFW is an essential tool for anyone managing a Linux server. It provides a simple and effective way to set up a firewall, ensuring basic but critical protection.
You should not rely solely on Fail2ban or CrowdSec to block attacks; first, close all ports and only open those that are truly necessary. This is where UFW proves to be indispensable.
In the final article of this series, we will discuss Lynis — a tool that allows you to proactively detect vulnerabilities and harden your server.
Related reviews
Huge thanks to Mikhail for the work — I'm very pleased with the result. Special thanks for his recommendations during setup: from my rather muddled brief (I know little about servers), Mikhail, through clarifying questions and suggestions, formed a clear understanding of what the final build would accomplish and how best to organize everything. I recommend him!
ladohinpy · MikroTik hAP router setup. I'll set up a MikroTik Wi‑Fi router for you.
2025-07-21 · ⭐ 5/5
Many thanks to Mikhail for the work, I am very pleased with the result. I especially thank him for the recommendations during the setup process — from my rather muddled brief (and I know little about servers) Mikhail, with clarifying questions and suggestions of his own, formulated a clear understanding of what tasks the final build will solve and how to organize everything in the best way. I recommend!
An excellent specialist, a savvy expert, and a wonderful person. In an hour he fixed what we'd been racking our brains over for days! I'm sure this won't be the last time we rely on his boundless professionalism.
Ravenor · MikroTik hAP router setup. I'll configure a MikroTik Wi-Fi router for you.
2025-05-28 · ⭐ 5/5
An excellent specialist, a savvy expert, and a wonderful person. In an hour he fixed for us what we had been scratching our heads over for days! I'm sure this won't be the first time we make use of his boundless professionalism.
A professional approach to the job!
ErlikZ · MikroTik hAP router setup. I'll set up a MikroTik Wi-Fi router for you.
2025-03-31 · ⭐ 5/5
Professional approach to the job!
Knows their stuff, gets things done. Everything was prompt and to the point; I was satisfied with the collaboration.
Soveni4 · MikroTik hAP router setup. I'll set up a MikroTik Wi‑Fi router for you.
A customer who has settled in2025-03-14 · ⭐ 5/5
Knows, can, does. Everything was prompt and to the point; I was satisfied with the collaboration.
Thanks! We set up the router according to my technical specification, with a full explanation of what we're doing.
GFSoft · MikroTik hAP router setup. I'll configure a MikroTik Wi‑Fi router for you.
Savvy shopper2025-03-09 · ⭐ 5/5
Thank you! The router was configured according to my technical specification, with a full explanation of what we are doing
Everything's great! Thanks! I recommend it.
NekMiha · Help with a MikroTik router
Powerful buyer2024-11-16 · ⭐ 5/5
Everything's great! Thank you! I recommend it