If you need to remove outdated firewall settings, troubleshoot a blocked connection, or start over with a simpler setup, you may be wondering how to clear UFW rules. UFW, or Uncomplicated Firewall, is a command-line tool commonly used to manage firewall rules on Ubuntu and other Linux distributions. You can delete individual rules or reset UFW to its default configuration. The right method depends on whether you want to remove one entry or clear the entire UFW rule set.
What Clearing UFW Rules Does
UFW keeps track of rules that allow or deny network traffic. For example, a rule might allow SSH connections on port 22, permit web traffic on ports 80 and 443, or block a particular port. Clearing rules removes the relevant entries from UFW’s configuration, which can change which connections are allowed through the firewall.
There are two common ways to clear UFW rules:
- Delete specific rules while leaving the rest in place.
- Reset UFW to its installation defaults, removing the configured rules and disabling the firewall.
Resetting is the quickest way to clear all UFW-managed rules, but it is more disruptive. If you only need to remove one rule, deleting that rule individually is usually safer.
Before You Clear the Firewall
Check the current firewall status and review the rules before making changes. Open a terminal and run:
sudo ufw status verbose
This command shows whether UFW is active, the default policies, and a summary of configured rules. To see rules with numbers that you can use for deletion, run:
sudo ufw status numbered
If you are connected to the machine remotely, take extra care before removing rules. Deleting an SSH allowance can interrupt your session or prevent you from connecting again. Make sure you have console access or another way to recover the system. If you intend to keep remote access, confirm that the necessary SSH rule is in place before changing the firewall.
It is also sensible to save a record of the current setup. You can copy the output of sudo ufw status numbered into a secure note, or back up relevant UFW configuration files before making a broad change. A record makes it easier to recreate rules if you remove the wrong entry.
How to Delete a Specific UFW Rule
To remove just one rule, first list the rules with their numbers:
sudo ufw status numbered
You may see output similar to this:
Status: active
To Action From
-- ------ ----
[ 1] 22/tcp ALLOW IN Anywhere
[ 2] 80/tcp ALLOW IN Anywhere
[ 3] 443/tcp ALLOW IN Anywhere
To delete a rule by number, use sudo ufw delete followed by the number. For example, to remove rule 2, enter:
sudo ufw delete 2
UFW normally asks you to confirm the deletion. Review the prompt, then confirm if you are sure. After a rule is removed, the remaining rules may be renumbered. Run sudo ufw status numbered again before deleting another rule; do not assume the old numbers still apply.
You can also delete a rule by repeating its original rule specification with delete in front. For example:
sudo ufw delete allow 80/tcp
This method can be helpful when you know the exact rule but want to avoid relying on a changing rule number. Match the original protocol, port, direction, and other details as closely as possible. If UFW reports that it cannot find the rule, check the current numbered status and use the displayed rule as your guide.
How to Clear All UFW Rules with a Reset
If you want to remove all UFW-managed rules and return to the default setup, use the reset command:
sudo ufw reset
UFW asks for confirmation because the operation removes configured rules and disables the firewall. Read the confirmation message carefully before proceeding. To confirm, respond as prompted. When the reset finishes, UFW is generally inactive, so the system is no longer protected by the UFW firewall until you enable it again.
Check the result with:
sudo ufw status verbose
The status should indicate that UFW is inactive. A reset is useful when you want to rebuild a UFW configuration from scratch, but it should not be treated as a harmless cleanup command. Removing allow rules may interrupt services or change the system’s exposure to network traffic.
Resetting UFW and Enabling It Again
After a reset, add back only the rules your system needs. For example, if the machine runs a website, you might allow HTTP and HTTPS traffic. If you administer it over SSH, you may need an SSH allowance as well:
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
Use the correct SSH port if your server does not use port 22. If you connect remotely, verify that the SSH rule is correct before enabling UFW. Once your required rules are in place, enable the firewall:
sudo ufw enable
UFW may warn that enabling it could disrupt existing SSH connections. Do not ignore this warning if you are working remotely. Confirm that you have allowed the correct management port and, where possible, have a recovery method available.
Finally, review the active configuration:
sudo ufw status verbose
Make sure the status is active and that the expected rules appear. Testing access to the services you rely on is a useful final check.
Does Disabling UFW Clear Its Rules?
No. Disabling UFW and clearing UFW rules are different actions. The disable command turns off UFW’s firewall enforcement but normally leaves the configured rules available for later use:
sudo ufw disable
You can check the result with sudo ufw status. If the status says inactive, the firewall is disabled; that does not mean the saved rules have been deleted. You can usually re-enable UFW later with sudo ufw enable, and the existing configuration will apply again.
Use sudo ufw disable when you need to temporarily stop UFW, and use sudo ufw reset when you intend to remove UFW’s configured rules and start over. For a single unwanted entry, use the delete command instead.
Check Application Profiles and Default Policies
Some applications provide UFW profiles that make it easier to allow a group of related ports. To see available profiles, run:
sudo ufw app list
To inspect the ports and rules associated with a profile, use:
sudo ufw app info 'Profile Name'
If you allowed a profile and want to remove that allowance, you can delete it using the profile name, for example:
sudo ufw delete allow 'Profile Name'
Use the exact name shown by sudo ufw app list. You can also inspect or set UFW’s default policies. These determine how traffic is handled when no specific rule matches. For instance, a common configuration denies incoming connections by default while allowing outgoing connections. Check your actual policy with:
sudo ufw status verbose
Deleting a rule is not the same as changing a default policy. If traffic behaves unexpectedly after you remove an entry, review both the rules and the default policies rather than assuming the deleted rule was the only factor.
UFW, IPv6, and Rules Outside UFW
UFW can manage IPv4 and IPv6 traffic. Whether IPv6 rules are handled depends in part on the UFW configuration, including the IPV6 setting in /etc/default/ufw. If your system uses IPv6, check the status and configuration before and after changing rules. Do not assume that removing an IPv4 rule automatically addresses every IPv6 access path.
Also remember that UFW is not necessarily the only firewall mechanism on a Linux system. Manually configured iptables or nftables rules, cloud-provider firewalls, router access-control lists, and hosting-panel security settings may operate separately. A UFW reset affects UFW-managed configuration; it may not remove rules managed by those other tools.
Avoid flushing all system firewall rules with low-level commands unless you understand the full network configuration. Doing so can disrupt services or remove protections that another system component depends on. If a connection remains blocked after you clear a UFW rule, investigate other firewall layers and the service’s own network settings.
Common Mistakes When Clearing UFW Rules
- Using reset when you only need to delete one entry: Resetting removes the whole UFW rule configuration and disables the firewall.
- Confusing disable with reset: Disabling turns off UFW but does not normally erase its rules.
- Deleting by an outdated number: Rule numbers can change after a deletion. Check the numbered list again each time.
- Forgetting remote access: Removing an SSH allowance can lock you out of a remote server.
- Assuming a reset protects the system: UFW is inactive after a reset until you configure and enable it again.
- Ignoring other firewall layers: Rules managed outside UFW may continue to affect network traffic.
Conclusion
To clear UFW rules, choose the method that fits the change you need. Use sudo ufw status numbered to review the current setup, then delete an individual rule by number or by its original rule specification. Use sudo ufw reset when you want to remove the UFW configuration and start again, keeping in mind that the reset disables the firewall. Before making changes, protect remote access, record important settings, and check the final status. A careful review helps you clear the right UFW rules without accidentally interrupting services or leaving the system in an unexpected firewall state.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.