How To Create And Add A Firewall On Ubuntu 18.04

Security is a extremely important part of using a Ubuntu 18.04 machine as its not uncommon to see attacks on machines daily.

Root is being used as the general yser for this tutorial | Also be sure that you have ran apt-update -f before following the instructions.

apt install ufw
By default all ports are blocked meaning you have to open them.

The firewall isn't active till later on

ufw allow ssh
This opens port 22 allowing you to SSH to the server

You can also type ufw allow 22 to manually allow the port

ufw reload
There you go, You just set the most basic firewall up for Ubuntu 18.04

Most applications will require you to open the ports and for example Nginx requires port 80 open so to do that its as simple as typing
ufw allow 80

You can also allow only certain packets through such as tcp/udp . To do that for example you type the same command but with /tcp or /udp on the end

Eg. ufw allow 80/tcp