UFW (Uncomplicated Firewall) is a simple frontend for iptables that significantly simplifies the management of your server firewall.
Install UFW
-
Update system
First, update the package lists:sudo apt update -
Install UFW
Install UFW with the following command:sudo apt install ufw -y
Configure UFW
-
Set default rules
Block all incoming connections and allow all outgoing:sudo ufw default deny incoming sudo ufw default allow outgoing -
Allow SSH port
Allow the SSH port so you can still connect:sudo ufw allow ssh -
Allow additional ports (optional)
Allow additional ports as needed:# Web server sudo ufw allow http sudo ufw allow https # Minecraft (default port 25565) sudo ufw allow 25565 # TeamSpeak 3 sudo ufw allow 9987/udp # Voice sudo ufw allow 10011/tcp # Query sudo ufw allow 30033/tcp # File Transfer -
Enable UFW
Activate the firewall:sudo ufw enableConfirm with
ywhen prompted. -
Check status
Verify that UFW is running correctly and which rules are active:sudo ufw status
Manage rules
Show all rules with numbers:
sudo ufw status numbered
Remove a rule (e.g. HTTP):
sudo ufw delete allow http
Block a specific port:
sudo ufw deny 8080
Disable UFW:
sudo ufw disable