How to set up Uncomplicated Firewall (UFW) on Ubuntu 18.04 LTS - jbilander/HowTos GitHub Wiki

How to set up Uncomplicated Firewall (UFW) on Ubuntu 18.04 LTS

first become root:

jbilander@zeus:~$ sudo -s
[sudo] password for jbilander:
root@zeus:~#

Check UFW Status and Rules:

root@zeus:~# ufw status
Status: inactive

Allow for ssh connections:

root@zeus:~# ufw allow ssh
Rules updated
Rules updated (v6)

Enable UFW:

root@zeus:~# ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup

Check status:

root@zeus:~# ufw status
Status: active

To                         Action      From
--                         ------      ----
22/tcp                     ALLOW       Anywhere
22/tcp (v6)                ALLOW       Anywhere (v6)

Allow http and https

root@zeus:~# ufw allow http
Rule added
Rule added (v6)

root@zeus:~# ufw allow https
Rule added
Rule added (v6)

root@zeus:~# ufw status
Status: active

To                         Action      From
--                         ------      ----
22/tcp                     ALLOW       Anywhere
80/tcp                     ALLOW       Anywhere
443/tcp                    ALLOW       Anywhere
22/tcp (v6)                ALLOW       Anywhere (v6)
80/tcp (v6)                ALLOW       Anywhere (v6)
443/tcp (v6)               ALLOW       Anywhere (v6)

Check status with sytemctl:

root@zeus:~# systemctl list-unit-files | grep ufw
ufw.service                            enabled

ufw has it's own internal status for whether or not it is active, this is obvious when checking it with systemctl that says loaded active exited:

root@zeus:~# systemctl | grep ufw
ufw.service            loaded active exited    Uncomplicated firewall

root@zeus:~# systemctl status ufw
● ufw.service - Uncomplicated firewall
   Loaded: loaded (/lib/systemd/system/ufw.service; enabled; vendor preset: enabled)
   Active: active (exited) since Tue 2019-01-15 13:31:19 CET; 26min ago
     Docs: man:ufw(8)
  Process: 1805 ExecStart=/lib/ufw/ufw-init start quiet (code=exited, status=0/SUCCESS)
 Main PID: 1805 (code=exited, status=0/SUCCESS)

Disabling logging may be useful to stop UFW filling up the kernel (dmesg) and message logs:

root@zeus:~# ufw logging off
Logging disabled