How to use UFW in ubuntu 20.04

UFW (uncomplicated firewall) is a firewall configuration tool pre-installed in Ubuntu 20.04 that runs on top of iptables. It is easy-to-use and reliable firewall interface. It supports IPv4 and IPv6 versions of Ubuntu.

Installation of UFW

If UFW is not available in your machine. Install it fir by running this command.

sudo apt install ufw

You can enable/disable the UFW service every time the system boots up via the following command:

sudo ufw enable

sudo ufw disable

sudo ufw status

Block Incoming and Allow Outgoing Data Traffic

To block any incoming and allow outgoing data traffic, type this command:

sudo ufw default allow outgoing

sudo ufw default deny incoming

Add, Modify, and Delete Firewall Rules

You can add, modify, and delete firewall rules using two different methods, port number or service name. Type this commands:

To view the list of rules in ufw

To allow a specific rule

sudo ufw allow http

To allow a specific rule

sudo ufw deny http

To delete a specific rule

sudo ufw delete allow http

Advanced UFW Rules

You can grant or prohibit access to a certain IP address. To authorize the IP address to access the services, run the following command:

To allow specific ip address

sudo ufw allow from 162.197.1.100

To deny or block specific ip address

sudo ufw deny from 162.197.1.100

When properly configured, UFW is a powerful tool that may dramatically improve the security of your servers. This reference guide goes over some of the most frequent UFW rules for configuring a firewall on Ubuntu.

By modifying parameters like the source IP address and/or destination port, most of the instructions in this book can be customized to match different use cases and scenarios.

Reference
https://www.digitalocean.com/community/tutorials/ufw-essentials-common-firewall-rules-and-commands
https://linuxhint.com/advanced_ufw_firewall_configuration_ubuntu/
https://www.cyberciti.biz/faq/how-to-configure-firewall-with-ufw-on-ubuntu-20-04-lts/

Leave a Comment

Your email address will not be published. Required fields are marked *