Quick Reference

Cheatsheets

Practical command references for Linux, networking, servers, containers, databases, and more.

Cheatsheet#ufw-cheatsheet

UFW (Uncomplicated Firewall) Cheatsheet

UFW (Uncomplicated Firewall) provides a user-friendly way to manage IPv4 or IPv6 host-based firewalls. It acts as a frontend for iptables or nftables.

Basic Commands

sudo ufw status                # Check firewall status
sudo ufw status verbose        # Check status with more details
sudo ufw status numbered       # Show rules with ID numbers
sudo ufw enable                # Enable the firewall (starts on boot)
sudo ufw disable               # Disable the firewall
sudo ufw reload                # Reload configuration

Setting Defaults

sudo ufw default deny incoming # Deny all incoming traffic
sudo ufw default allow outgoing # Allow all outgoing traffic

Allowing and Denying Connections

sudo ufw allow 22              # Allow SSH (Port 22)
sudo ufw allow ssh             # Allow SSH (by service name)
sudo ufw deny 23               # Deny Telnet (Port 23)
sudo ufw allow 80/tcp          # Allow HTTP (TCP only)
sudo ufw allow 53/udp          # Allow DNS (UDP only)

Advanced Rules

# Allow from specific IP
sudo ufw allow from 192.168.1.100
 
# Allow from specific subnet
sudo ufw allow from 192.168.1.0/24
 
# Allow specific IP to specific port
sudo ufw allow from 192.168.1.100 to any port 22
 
# Rate limiting (useful for SSH to prevent brute force)
sudo ufw limit ssh

Deleting Rules

# Delete by rule specification
sudo ufw delete allow 80/tcp
 
# Delete by rule number (Recommended)
sudo ufw status numbered
sudo ufw delete 3              # Deletes rule number 3