Docs / Networking / How to Set Up a Basic Firewall with UFW

How to Set Up a Basic Firewall with UFW

By Admin · Feb 25, 2026 · Updated Apr 23, 2026 · 138 views · 1 min read

UFW (Uncomplicated Firewall) is the simplest way to manage firewall rules on Ubuntu and Debian.

Install and Enable

apt install ufw -y
ufw default deny incoming
ufw default allow outgoing
ufw allow ssh
ufw enable

Common Rules

# Allow HTTP and HTTPS
ufw allow 80/tcp
ufw allow 443/tcp

# Allow specific port
ufw allow 3306/tcp

# Allow from specific IP
ufw allow from 203.0.113.50

# Allow port from specific IP
ufw allow from 203.0.113.50 to any port 22

# Delete a rule
ufw delete allow 3306/tcp

Check Status

ufw status verbose
ufw status numbered

Important

Always allow SSH (port 22) before enabling UFW, or you'll lock yourself out. Use the VNC console to recover if this happens.

Was this article helpful?