Mastering UFW : Tricks and Tips

Mastering UFW : Tricks and Tips
Photo by FLY:D / Unsplash


Uncomplicated Firewall (UFW) is a user-friendly interface for managing iptables on Ubuntu and other Linux distributions. It simplifies firewall management for both beginners and experienced users.

This tutorial will delve into various UFW tricks and tips to help you harness the full potential of this powerful firewall management tool.

Tip 1: Installing UFW

If UFW isn't already installed on your system, you can install it using the following command:

sudo apt-get install ufw

Tip 2: Enabling UFW

To enable UFW and ensure that it starts on boot, use the following command:

sudo ufw enable

Tip 3: Disabling UFW

To disable UFW, you can use the following command:

sudo ufw disable

Tip 4: Checking UFW Status

To check the status of UFW and see which rules are currently active, run:

sudo ufw status verbose

Tip 5: Adding Firewall Rules

Use ufw allow to create rules to allow specific services or ports. For example, to allow SSH (port 22), use:

sudo ufw allow 22/tcp

Tip 6: Denying Firewall Rules

To deny specific ports or services, use ufw deny. For example, to deny HTTP (port 80), use:

sudo ufw deny 80/tcp

Tip 7: Deleting Firewall Rules

If you need to remove a rule, use ufw delete. Specify the rule's number (shown in ufw status verbose):

sudo ufw status numbered
sudo ufw delete <rule_number>

Tip 8: Allowing Specific IP Addresses

To allow connections from a specific IP address, use ufw allow from. For instance:

sudo ufw allow from

Tip 9: Enabling or Disabling UFW Logging

You can enable or disable UFW logging to track blocked connections. To enable logging, use:

sudo ufw logging on

To disable logging:

sudo ufw logging off

Tip 10: Resetting UFW Rules

If you want to start over or reset UFW to its default settings, use:

sudo ufw reset

Tip 11: Application Profiles

UFW includes application profiles that simplify rule management. List available profiles with:

sudo ufw app list

To allow or deny a specific application, use:

sudo ufw allow <app_profile>
sudo ufw deny <app_profile>

Tip 12: Limiting Connection Rates

You can limit the rate of incoming connections to prevent abuse. For example, to limit SSH to five connections per minute:

sudo ufw limit OpenSSH

Tip 13: Advanced Rule Syntax

UFW allows for complex rule definitions. For example, to allow incoming SSH connections only from a specific IP range:

sudo ufw allow from to any port 22

Tip 14: IPv6 Support

UFW supports IPv6 alongside IPv4. To add a rule for IPv6, simply specify the protocol:

sudo ufw allow 80/tcp6

Tip 15: Customizing UFW Before.rules and After.rules

For advanced users, you can customize the before.rules and after.rules files in /etc/ufw. Be cautious when modifying these files, as it can impact UFW's behavior.


With these UFW tricks and tips, you can effectively manage your firewall, secure your Linux system, and control network traffic.

Always exercise caution when configuring firewall rules, especially when dealing with remote access, to avoid locking yourself out of your system.