UFW is the handy and simple default firewall found on Ubuntu 20.04 Focal Fossa. As easy as it is to configure, you still need to know the proper syntax in order to edit it. In this guide, we'll show you how to list and delete individual firewall rules in UFW.

In this tutorial you will learn:
  • How to list UFW firewall rules
  • How to delete UFW firewall rules
Deleting a firewall rule in UFW on Ubuntu 20.04
Deleting a firewall rule in UFW on Ubuntu 20.04
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Installed or upgraded Ubuntu 20.04 Focal Fossa
Software UFW
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

List existing firewall rules

In order to delete firewall rules from UFW, we first need to get a numbered list of the rules that are currently configured. Open a terminal and enter the following command to list all the rules:

$ sudo ufw status numbered

UFW should output a numbered list of firewall rules, as seen in the screenshot below:

List of current firewall rules in UFW
List of current firewall rules in UFW

Remove a firewall rule

Take note of the number that corresponds to the firewall rule you'd like to delete. In our example, we're going to delete rule #2, which allows connections over HTTPS (port 443) on IPv4. The following command deletes rule #2:

$ sudo ufw delete 2

After running that command, you'll be asked to confirm that you want to delete the rule. Just enter y and press enter to continue. Now that it's been deleted, you can check UFW's list of rules once again to make sure that the rule no longer appears:

$ sudo ufw status numbered
Deleting the rule and confirming its removal
Deleting the rule and confirming its removal
DID YOU KNOW?
You can only delete one firewall rule at a time. Keep in mind that the numbering changes each time you remove a rule.

Conclusion

In this guide, we learned how to list and delete firewall rules in UFW. UFW (Uncomplicated Firewall) lives up to its name in this regard, as deleting rules is dead simple. The only thing to keep in mind is that you may also want to delete the corresponding IPv6 rule.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.