The ufw command

program for managing a netfilter firewall 23 examples from the lessons of the IVski Linux Playground — try them in the terminal next to them.

Examples

sudo ufw status

Status: inactive

sudo ufw app list

profiles of what's installed: Nginx Full, OpenSSH, …

sudo ufw allow OpenSSH

the same as: sudo ufw allow 22/tcp

sudo ufw enable
sudo ufw status verbose
sudo ufw allow http

a name from /etc/services: port 80/tcp

sudo ufw allow 443/tcp

a port and its protocol

sudo ufw allow 'Nginx Full'

an app profile: 80 and 443

sudo ufw status numbered
sudo ufw delete allow http

repeat the rule after "delete"

sudo ufw delete 3

or give its number

sudo ufw allow from 192.168.1.0/24 to any port 22 proto tcp
sudo ufw delete allow OpenSSH

the rule for everyone goes

sudo ufw insert 1 deny from 203.0.113.7

before everything else

sudo ufw limit from 192.168.1.0/24 to any port 22 proto tcp

the same rule, now with a limit

sudo ufw default deny incoming

what isn't allowed stays out (the default)

sudo ufw default allow outgoing

the server may connect anywhere (the default)

sudo ufw logging on

low, medium, high — or off

sudo ufw show added
ufw deny from 203.0.113.7
ufw limit from 192.168.1.0/24 to any port 22 proto tcp
sudo ufw allow from 198.51.100.0/24 to any port 22 proto tcp
sudo ufw delete allow 8080/tcp

Lessons that use ufw