UFW (Uncomplicated Firewall) is the simplest way to filter traffic on Ubuntu. Allow SSH before enabling it or you will lock yourself out.
Steps
Install UFW if needed:
sudo apt updatesudo apt install -y ufwAllow SSH (port 22 or your custom port) before enabling:
sudo ufw allow OpenSSHIf you serve a website, open HTTP and HTTPS:
sudo ufw allow 80/tcpsudo ufw allow 443/tcpEnable the firewall and check status:
sudo ufw enablesudo ufw status verbose
Tips
- If you changed the SSH port, use
sudo ufw allow 2222/tcp(or yours) instead of OpenSSH. - To remove a rule:
sudo ufw status numberedthensudo ufw delete N.
ext step
Firewall ready on a clean VPS: Deploy your Cloud VPS.