UFW Firewall

Step 1 – Installing UFW
$ sudo apt install ufw

Step 2 — Using IPv6 with UFW (Optional)
$ sudo nano /etc/default/ufw
IPV6=yes

Step 3 — Setting Up Default Policies
$ sudo ufw default deny incoming
$ sudo ufw default allow outgoing

Step 4 — Allowing SSH Connections
$ sudo ufw allow ssh
$ sudo ufw allow 22
$ sudo ufw allow 2222
(the default 22, if you change the ssh port to 2222 you might wanna allow 2222)

Step 5 — Enabling UFW
$ sudo ufw enable

Step 6 — Allowing Other Connections
$ sudo ufw allow http or $ sudo ufw allow 80
$ sudo ufw allow https or $ sudo ufw allow 443

Specific Port Ranges
$ sudo ufw allow 6000:6007/tcp
$ sudo ufw allow 6000:6007/udp

Specific IP Addresses
$ sudo ufw allow from 203.0.113.4
$ sudo ufw allow from 203.0.113.4 to any port 22
$ sudo ufw allow from 203.0.113.0/24
$ sudo ufw allow from 203.0.113.0/24 to any port 22

Connections to a Specific Network Interface
$ ip addr
$ sudo ufw allow in on eth0 to any port 80
$ sudo ufw allow in on eth1 to any port 3306

Step 7 — Denying Connections
$ sudo ufw deny http
$ sudo ufw deny from 203.0.113.4

Step 8 — Deleting Rules
By Rule Number
$ sudo ufw status numbered
$ sudo ufw delete 2

By Actual Rule
$ sudo ufw delete allow http
$ sudo ufw delete allow 80

Step 9 — Checking UFW Status and Rules
$ sudo ufw status verbose

Step 10 — Disabling or Resetting UFW (optional)
$ sudo ufw disable
$ sudo ufw reset

Source: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-debian-10

Leave a Reply