Setting up a firewall using UFW

TL;DR

sudo ufw status
sudo ufw app list 
sudo ufw allow OpenSSH
sudo ufw allow 'nginx full' # App only available if you installed NGINX
sudo ufw enable
sudo ufw status

# After every change in rules:
sudo ufw reload

Notes

  • After you add/remove a new rule, to apply it, you need to reload the firewall: sudo ufw reload
  • It's paramount to remember to add OpenSSH BEFORE enabling the firewall, cause if you don't, after you log out, you won't be able to login again!

Other useful commands

sudo ufw status verbose

# Remove a rule (different from actually BLOCKING access to something)
sudo ufw status numbered
sudo ufw delete NUM

# Block access to an app by explicitly denying it
sudo ufw deny <app>