Docs / Security / Configuring UFW Firewall on Ubuntu

Configuring UFW Firewall on Ubuntu

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

What is UFW?

UFW (Uncomplicated Firewall) is a user-friendly frontend for iptables/nftables. It simplifies firewall management while providing robust protection.

Installation and Basics

sudo apt install -y ufw

# Check status
sudo ufw status verbose

Default Policies

# Deny all incoming, allow all outgoing
sudo ufw default deny incoming
sudo ufw default allow outgoing

Allow Common Services

# SSH (CRITICAL: do this before enabling UFW!)
sudo ufw allow ssh
# Or specific port
sudo ufw allow 2222/tcp

# Web traffic
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

# Using application profiles
sudo ufw allow "Nginx Full"

Advanced Rules

# Allow from specific IP
sudo ufw allow from 198.51.100.10

# Allow from subnet to specific port
sudo ufw allow from 10.0.0.0/8 to any port 3306

# Allow port range
sudo ufw allow 6000:6010/tcp

# Deny specific IP
sudo ufw deny from 203.0.113.50

Enable the Firewall

sudo ufw enable

Warning: Make absolutely sure you have allowed SSH before enabling UFW, or you will lock yourself out.

Managing Rules

# List rules with numbers
sudo ufw status numbered

# Delete a rule by number
sudo ufw delete 3

# Delete by specification
sudo ufw delete allow 8080/tcp

# Reset all rules
sudo ufw reset

Was this article helpful?