Setting Up a Firewall with UFW
UFW (Uncomplicated Firewall) makes managing firewall rules straightforward, even for beginners.
Install UFW
apt install ufw -y
Set Default Policies
ufw default deny incoming
ufw default allow outgoing
Allow Essential Services
ufw allow ssh # SSH (port 22)
ufw allow 80 # HTTP
ufw allow 443 # HTTPS
Enable the Firewall
ufw enable
View Current Rules
ufw status verbose
Common Operations
ufw allow 25565 # Allow a specific port
ufw delete allow 80 # Remove a rule
ufw allow from 203.0.113.100 # Allow a specific IP
ufw deny from 198.51.100.0 # Block a specific IP
ufw disable # Disable the firewall
ufw reset # Reset all rules
Note: Always allow SSH before enabling the firewall to avoid locking yourself out.