How to configure firewall on Ubuntu using UFW?

Linux-LogoBefore setting up a server for any kind of use we need to protect it from the hackers. For this job we have several options and firewall is one of them. The Uncomplicated Firewall (ufw) is a frontend for iptables and is particularly well-suited for host-based firewalls. ufw provides a framework for managing netfilter, as well as a command-line interface for manipulating the firewall. ufw aims to provide an easy to use interface for people unfamiliar with firewall concepts, while at the same time simplifies complicated iptables commands to help an adminstrator who knows what he or she is doing. ufw is an upstream for other distributions and graphical frontends.

How to install UFW:

Before installing ufw we need to update our machine and then we will install ufw

How to check the status:

If you got inactive status like:

Then we have to enable ufw by issue below command

After enabling the service again check the status

Output will look like this

There are some default rules available like below:

Now we will configure some costume rules:
Allow Port 22 (SSH)

Allow port 80 (http)

Allow port 21 (FTP)

We can also configure a Port range to allow or deny

We can also configure IP address to allow or deny

Deleting Rules

How to reset UFW:

How to disable UFW

The following two tabs change content below.

Tapas Mishra

Sr. Engineer (DevOps)
Loves to work on Opensource products. Having experience on Linux environment. Knowledge on Public cloud services like AWS, Rackspace, DigitalOcean, Linode. Please don't hesitate to give a comment on the posts. Your comments are my strength.

Leave a Reply