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 statusStatus: inactive
sudo ufw app listprofiles of what's installed: Nginx Full, OpenSSH, …
sudo ufw allow OpenSSHthe same as: sudo ufw allow 22/tcp
sudo ufw enable
sudo ufw status verbose
sudo ufw allow httpa name from /etc/services: port 80/tcp
sudo ufw allow 443/tcpa port and its protocol
sudo ufw allow 'Nginx Full'an app profile: 80 and 443
sudo ufw status numbered
sudo ufw delete allow httprepeat the rule after "delete"
sudo ufw delete 3or give its number
sudo ufw allow from 192.168.1.0/24 to any port 22 proto tcp
sudo ufw delete allow OpenSSHthe rule for everyone goes
sudo ufw insert 1 deny from 203.0.113.7before everything else
sudo ufw limit from 192.168.1.0/24 to any port 22 proto tcpthe same rule, now with a limit
sudo ufw default deny incomingwhat isn't allowed stays out (the default)
sudo ufw default allow outgoingthe server may connect anywhere (the default)
sudo ufw logging onlow, 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