Uncomplicated Firewall (ufw) is a tool for managing firewall designed to be easy to use. It uses a command-line interface and uses iptables for configuration.
Installation
sudo apt-get install ufw
Setup
-
Allow main ports and ports you need to expose:
sudo ufw allow 22 sudo ufw allow 80 sudo ufw allow 443
-
Deny all other ports and allow outgoing connections:
sudo ufw default deny incoming sudo ufw default allow outgoing
-
To delete a rule you can use:
ufw delete allow 80
-
Before enable the firewall, remember to allow connections from ssh port if you are connecting remotely to your vps:
sudo ufw enable
-
To verify the firewall is running you can use the command:
sudo ufw status
If you are interested in learning more about how to set up a vps from scratch, you can check out my new handbook where you will learn how to configure your server, secure it, install a reverse proxy and deploy all your projects