UFW - Uncomplicated Firewall on Linux: Quick and Easy Tutorial

Welcome to this easy-to-follow guide on using UFW (Uncomplicated Firewall) on Linux! UFW is designed to make managing your firewall settings a breeze, even if you’re not a network expert. It serves as a user-friendly front-end to iptables, simplifying the process so anyone can use it.

Installing UFW on Linux

Getting UFW up and running is simple since it’s included with most Linux distributions. You can install it using your package manager. Here are the commands for various distributions:

  • Ubuntu/Debian:

    sudo apt get install ufw
    
  • CentOS/RHEL:

    sudo yum install ufw
    
  • Fedora:

    sudo dnf install ufw
    
  • Arch Linux:

    sudo pacman -S ufw
    

Once installed, you can enable UFW with:

sudo ufw enable

This command turns on the firewall and ensures it starts automatically when your system boots up. To see the current status of your firewall, use:

sudo ufw status

This will show you whether the firewall is active and list any rules you’ve set up.

Basic UFW Commands

After installing UFW, the first thing you’ll want to do is enable it. You can do this with:

sudo ufw enable

This command turns on the firewall and ensures it starts automatically when your system boots up. To see the current status of your firewall, use:

sudo ufw status

This will show you whether the firewall is active and list any rules you’ve set up.

Adding Firewall Rules with UFW

Adding rules to your firewall is straightforward with the ufw command. For example, to allow incoming SSH traffic, simply run:

sudo ufw allow ssh

This command opens up port 22 for SSH traffic. If you need to allow traffic on a different port, just specify the port number. For instance, to allow traffic on port 80, use:

sudo ufw allow 80

You can also allow traffic on a range of ports or from a specific IP address. For example, to allow traffic on ports 80 and 443 from a specific IP address, use:

sudo ufw allow from <IP_ADDRESS> to any port 80,443

UWF Application Profiles

UFW comes with a set of application profiles that you can use to simplify the process of creating firewall rules. These profiles define the ports and protocols required for specific applications. To see a list of available profiles, use:

sudo ufw app list

This will show you a list of available profiles, such as OpenSSH, Apache, and Nginx. To enable a profile, use:

sudo ufw allow <PROFILE_NAME>

For example, to allow traffic for the OpenSSH profile, use:


sudo ufw allow OpenSSH

This will automatically open the ports required for SSH traffic. You can also specify a port number to allow traffic on a specific port. For example, to allow traffic on port 80 for the Apache profile, use:


sudo ufw allow Apache

This will open port 80 for HTTP traffic. Using application profiles can save you time and effort when setting up firewall rules for common applications.

Wrapping Up

UFW is a powerful yet easy-to-use tool for managing your firewall settings on Linux. Its intuitive interface makes it simple to add and manage rules. By following this guide, you should now have a good grasp of how to use UFW to secure your Linux system. If you have any questions or run into any issues, feel free to ask for help in the comments below. Happy firewalling!

Further Reading