UFW Firewall cheatsheet
Protect a Linux machine with a few simple rules
How it works
- A connection arrives — Something tries to reach a port.
- Rules are checked — UFW looks for a matching allow or deny rule.
- Allowed passes — Trusted services work normally.
- Everything else stops — Default deny protects forgotten services.
First steps
sudo ufw default deny incoming- Block incoming by default
sudo ufw allow OpenSSH- Keep remote access
sudo ufw allow 443/tcp- Allow secure web traffic
sudo ufw enable- Switch the firewall on
sudo ufw status verbose- See the rules