How to Set Up UFW Firewall (Ubuntu/Debian)
How to Set Up UFW Firewall (Ubuntu/Debian)
Basic Setup
# Check current status
ufw status
# Set defaults
ufw default deny incoming
ufw default allow outgoing
# Allow SSH FIRST (critical!)
ufw allow 22/tcp
# Enable the firewall
ufw enable
Common Rules
# Web server
ufw allow 80/tcp
ufw allow 443/tcp
# MySQL (only from specific IP)
ufw allow from 10.0.0.5 to any port 3306
# PostgreSQL
ufw allow 5432/tcp
# SMTP
ufw allow 25/tcp
ufw allow 587/tcp
ufw allow 465/tcp
# Custom port
ufw allow 8080/tcp
# Delete a rule
ufw delete allow 8080/tcp
# View numbered rules
ufw status numbered
Warning: Always ensure SSH (port 22) is allowed before enabling UFW. If you lock yourself out, use the VNC Console in the DartNode dashboard to regain access.