Installing and setting up UFW firewall on Ubuntu
Installing the UFW firewall package
sudo apt-get update sudo apt-get install ufw
Allowing SSH through the firewall
Important! After the firewall is installed, the first you should do is allow SSH access before enabling it. Big problem if you don’t!
Issue the following command:
sudo ufw allow ssh
If you have a web server such as Apache, you will also want to allow that to be accessed through the firewall. Note: this is not a full guide on what should and shouldn’t be allowed, but you can see how to allow Apache here.
Now to enable the firewall.
sudo ufw enable
That’s it. Simple.