UFW
General Info
By default, UFW is set to deny all incoming connections and allow all outgoing connections. This means anyone trying to reach your server would not be able to connect, while any application within the server would be able to reach the outside world.
So make sure to allow ssh before enabling UFW!!! UFW requires you to add / deny ports in a certain order, if you want to allow a certain ip access a port but deny access by everyone else, the ip must be allowed first then deny all after
Setup
sudo apt update && sudo apt install -y ufw
Basic Management
Turning UFW on:
ufw enable
Turning UFW off:
ufw disable
Check if UFW is enabled or disabled
sudo ufw status
Allowing access from a particular IP to ANY port
sudo ufw allow from IP_ADDRESS
Allowing access from a partiular IP to A SPECIFIED port:
sudo ufw allow from IP_ADDRESS to any port PORT_NUMBER
Allowing any access to a specified port:
sudo ufw allow PORT_NUMBER
Denying access to a specific port
sudo ufw deny PORT_NUMBER
List rule numbers
sudo ufw status numbered