Skip to main content

UFW

Remove Rule from UFW Firewall

Added a wrong rule or no longer need one? Here's how to delete rules from UFW firewall in Ubuntu.

In the past, you may have add a rule to the UFW firewall and you no longer want those rules to be in effect.

So in that case, you can remove the rule from your firewall. In this quick guide, I will be showing easy steps to do so.

How to remove a rule from UFW Firewall

I have divided this guide into 3 simple steps so that you can have a clear idea.

Step 1: List available rules with numbers

You may be wondering why to list rules with numbers. Well, having numbers associated with a rule is helpful when one wants to remove a rule.

To list ufw rue with numbers, use the following command:

sudo ufw status numbered
list firewall rules with numbers

And it will present every firewall rule with a natural number.

From here, note a number that is related to the rule you want to delete.

Step 2: Delete the UFW Firewall rule

Once you know the number, all you have to do is follow the given command and the rule will be removed:

sudo ufw delete number_of_rule

So let's say I want to remove a rule that allows HTTP (one of the most common ports that use port 80 by default) on my network.

And in that case, I'm required to append the associated number with that rule (number 2 in my case):

sudo ufw delete 2
delete ufw rule in ubuntu

It will ask your permission before removing the rule. Press y and hit enter.

Step 3: Verify the rule deletion

To verify whether the rule was removed successfully, it is advised to check the status of ufw firewall and list available rules:

sudo ufw status
list availabe ufw firewall rules in ubuntu

And as you can clearly see, the rule no longer exists! You have successfully delete the rule from the UFW firewall.

More on UFW...

Here's a quick summary of useful UFW commands.

CommandDescription
ufw statusCheck the status of the UFW firewall.
ufw enableEnable the UFW Firewall.
ufw allow < rule >Allow port/service through the UFW firewall.
ufw deny < rule >Drop the connection from a specific port/service on the UFW firewall.
ufw status verboseGet the detailed (verbose) status of the UFW firewall, which also includes logging levels.
ufw status numberedShows UFW rules with numbers, which is helpful when you want to remove rules.
ufw reject < rule >Reject connection from specific port or service.
ufw logging < logging_level >Change the logging level of the UFW firewall.
ufw delete <rule/number>Delete the UFW firewall rule.
ufw reloadReload the UFW firewall.
ufw disableDisable the UFW firewall.

If you want, you can download the above table in PDF format for quick reference in the future.

If you want details on the UFW commands, refer to this guide 👇

Using UFW Firewall Commands in Ubuntu
A detailed beginner’s guide to using UFW firewall in Ubuntu command line. There is also a cheat sheet you can download for free.

I hope you will find this guide helpful and if you have any queries, let me know in the comments.