Guide
Firewall basics with ufw
Default deny, allow SSH first, open only the service ports, rate-limit the obvious target and verify from outside.
1. Deny by default
ufw default deny incoming && ufw default allow outgoing. Nothing is reachable until a rule allows it, which is the correct starting state.
2. Allow SSH before enabling
ufw allow 22/tcp && ufw enable. Enabling first and allowing second is the standard way to lock yourself out of a remote host.
3. Open only the service ports
ufw allow 80,443/tcp for a web host. Review the result with ufw status numbered, which shows the order rules are evaluated in.
4. Rate-limit the obvious target
ufw limit 22/tcp drops an address that opens more than six connections in 30 seconds. That handles most brute-force attempts without a second tool.
5. Cover IPv6 as well
Set IPV6=yes in /etc/default/ufw. A rule set that covers only IPv4 leaves a fully open second path to the same services.
6. Verify from another machine
nmap -Pn -p 1-1000 203.0.113.10 from outside. Only the ports you opened should answer; anything else means a missing rule or another tool inserting its own.
FAQ
Questions we get on this page
Why does Docker bypass my ufw rules?+
Where are the rules stored?+
Ready when you are
Tell us what you need. A human answers.
Pilot stage: one facility in Reykjavík, plans confirmed by hand, payment in crypto. Write to the desk and you get a real person, not a queue.