UFW Firewall Commands


By default UFW firewall blocks all incoming ports by default unless
explictly opened, all outgoing is allowed unless explictly denied
This can be changed if required.

.

Set Default UFW Incoming Mode

ufw default [allow/deny] incoming

Default UFW Outgoing Mode

ufw default [allow/deny] outgoing

UFW Firewall Status

ufw status

Enable UFW Firewall : (Be sure you've first whitelisted ssh for your IP!)

ufw enable

Disable UFW Firewall :

ufw disable

Reset Firewall Rules :

ufw reset

Whitelist Incoming IP address on all ports :

 ufw allow from 123.123.123.123

Whitelist Incoming IP address on certain port (ie 22 SSH)

ufw allow from 123.123.123.123 to any port 22

Open Incoming Port (ie 80):

ufw allow 80

Open Incoming Port Range & Specify Protocol (ie 6000-6010 TCP):

ufw allow 6000:6010/tcp

Block Incoming Port (ie 25):

ufw deny 25

Block Outgoing Port (ie 25):

ufw deny out 25

Delete UFW Rule by number (ie delete rule 8) :

ufw status numbered
ufw delete 8

Supported By Cosmos Hosting