Step-1 (Installing UFW firewall)
The UFW firewall comes pre installed with Ubuntu 16.04 but in the case it is missing you can install it.
$ sudo apt-get install ufw -y
Step-2 (Enabling the UFW firewall)
$ sudo ufw enable
Step-3 (Adding UFW Firewall Rules)
The UFW firewall rules is set according to the port numbers and additional port based rules.
For Enabling Firewall Rules on various default ports
On HTTP (80) Port
$ sudo ufw allow http
On HTTPS (443) Port
$ sudo ufw allow https
On SSH (22) Port
$ sudo ufw allow ssh
For Enabling Firewall Rules on various custom ports
On Custom port like 3360
$ sudo ufw allow 3360/tcp
$ sudo ufw allow 3360/tcp6
Step-4 (Remove the UFW firewall rules)
You can easily remove those already added rules by typing
To Remove Firewall Rules on various default ports
Remove default HTTPS Rules
$ sudo ufw delete allow https
To Remove Firewall Rules on various custom ports
Remove custom 3360 rules
$ sudo ufw delete allow 3360/tcp
$ sudo ufw delete allow 3360/tcp6
Step-5 (Check status of UFW firewall)
To check the UFW firewall whether it is running or not and which rules has been integrated to UFW firewall.
$ sudo ufw status
Step-6 (Reset all the UFW firewall rules)
If anything got wrong then you can reset the UFW firewall by typing
$ sudo ufw reset
Step-7 (Disable UFW firewall)
If you want to setup another firewall rather than UFW then to avoid conflicts between two firewall it is possibility to disable the UFW firewall first.
Note: After disabling UFW firewall it no longer works for you so think twice before doing this step. If you have another firewall ready to integrate on your distro then please proceed for further steps.
$ sudo ufw disable
The UFW firewall is easy to integrate so you have to setup the UFW firewall on your respective distro with ease. If you have any additional queries or questions then go ahead and use the comment section below for help and support.