Configuring UFW (“uncomplicated firewall”) on Debian and Ubuntu.

UFW is a very easy to use firewall for Linux. Today I’ll show you how to install it on Debian (and Ubuntu).

First off, install UFW if you haven’t already.

sudo apt-get update -y && sudo apt-get install ufw -y

Allow the ports you would like to have open (add SSH as that’s probably what you’re using to talk to your server).

ufw allow 22

Some services like “http” and “ssh” can be added like this:

ufw allow http

Then we need to enable the firewall (make sure you’re not locking yourself out).

ufw enable

If you’re adding new rules, you will need to reload the firewall.

ufw reload

To delete a rule, you will need to see which number it has.

ufw status numbered

Delete the rule using the list of numbers on the left hand side.

ufw delete 2

(replace 2 with the number you would like to delete).

Don’t forget to reload the firewall.

That should be it! You know have a basic firewall!