UFW Firewall cheat-sheet

What do we want to archive

Install and activate the Uncomplicated firewall (UFW) and list some basic commands for adding and removing rules


Debian, Ubuntu, etc

How do we get there


#sudo apt install ufw

Default rules

The following defaults will allow all outgoing traffic, and block all incoming traffic, which will make for a nice set of defaults to start out secure:

# ufw default deny incoming
# ufw default allow outgoing

Doing this remote ? then you just might want to allow ssh before enabling these rules and locking yourself out.

#ufw allow ssh

Finaly, activate the firewall:

#ufw enable

Some handy commands

ufw status numberedlist the active set of rules, in a numbered format
ufw allow 80/tcp Allow specific port and protocol access
ufw allow 53Allow all protocols on port
ufw allow from to anyAllow all traffic from a specific subnet (handy for local network)
ufw delete 7Delete configured rule number 7