Linux SysAdmin & DevOps

UFW Firewall Configuration on Ubuntu - A Comprehensive Step-by-Step Guide

UFW Firewall- Comprehensive Guide: install & configuration


In today’s digital landscape, securing your Ubuntu system is of utmost importance. One effective method to enhance your system’s security is by setting up the Uncomplicated Firewall (UFW). This detailed guide will walk you through the step-by-step process of installing, configuring, and managing UFW on your Ubuntu machine, providing you with a robust defense against potential threats.

Installing UFW on Ubuntu

Checking UFW Status

Before diving into the installation process, it’s prudent to check the status of UFW on your system:

$ sudo ufw status

If the output indicates that the firewall is inactive, you’re ready to proceed.

Installing UFW

For systems where UFW is not installed, begin by updating your package list and installing UFW:

$ sudo apt-get update
$ sudo apt-get install ufw

This ensures that UFW is available on your system for configuration.

Basic Firewall Configuration with UFW

Enabling UFW

Activate UFW with the following command:

$ sudo ufw enable

This not only enables the firewall but also sets it to start at boot. Confirm the action by typing ‘y’ and pressing Enter.

Allowing Specific Ports

Enhance your system’s accessibility by allowing traffic on specific ports. For instance, to permit HTTP (port 80) and HTTPS (port 443) traffic, use the commands:

$ sudo ufw allow 80/tcp
$ sudo ufw allow 443/tcp

If your system relies on SSH, grant access to port 22:

$ sudo ufw allow 22/tcp

Advanced UFW Configuration

Denying Traffic

For an additional layer of security, deny traffic from specific IP addresses:

$ sudo ufw deny from <IP_Address>

Replace <IP_Address> with the actual IP address you want to block.

Setting Up Application Profiles

Simplify rule management by creating application profiles for UFW. Refer to the UFW documentation for in-depth information on configuring application profiles.

Monitoring and Managing UFW

Checking UFW Status

Keep a close eye on UFW’s status and rules with the following command:

$ sudo ufw status

This provides a comprehensive overview of the current UFW configuration.

Disabling UFW

Temporarily disable UFW when necessary:

$ sudo ufw disable

This halts UFW, leaving your system without an active firewall. Use caution when disabling UFW and only do so if required.

Testing Firewall Configuration

After configuring UFW, it’s crucial to validate its effectiveness. Attempt to access your server from a different machine or leverage online tools to verify the status of your open ports.


Congratulations! You’ve successfully set up a robust firewall using UFW on your Ubuntu system. Regularly review and update your firewall rules to adapt to changing security needs, ensuring your system remains secure.

By following this comprehensive guide, you’ve gained a deep understanding of UFW and its configuration options, empowering you to make informed decisions regarding your system’s security.