Firewall Linux Server, Security

If you want to delete active rules (filters) from UFW – Uncomplicated Firewall – , find out that it is very simple and there are two methods to do this, but first of all you have to make sure that UFW is installed and active (enabled):

@ sudo ufw status

If the displayed result is something like this:

Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
20/tcp                     ALLOW       Anywhere
21/tcp                     ALLOW       Anywhere
40000:50000/tcp            ALLOW       Anywhere
990/tcp                    ALLOW       Anywhere
9090/tcp                   ALLOW       Anywhere
80/tcp                     ALLOW       Anywhere
443/tcp                    ALLOW       Anywhere
8096/tcp                   ALLOW       Anywhere
1900/udp                   ALLOW       Anywhere

Then yes, ufw is active and you can delete the active rules from the firewall.

For this you have at hand two alternative commands,

  • by rule numbers
  • and by specification
1) Delete UFW rules/filters by rule number

To delete a “rule” you must first display the active rules associated with a number, by the following command:

@ sudo ufw status numbered

The result will be something similar with next:

Status: active

     To                         Action      From
     --                         ------      ----
[ 1] OpenSSH                    ALLOW IN    Anywhere
[ 2] 20/tcp                     ALLOW IN    Anywhere
[ 3] 21/tcp                     ALLOW IN    Anywhere
[ 4] 40000:50000/tcp            ALLOW IN    Anywhere
[ 5] 990/tcp                    ALLOW IN    Anywhere
[ 6] 9090/tcp                   ALLOW IN    Anywhere
[ 7] 80/tcp                     ALLOW IN    Anywhere
[ 8] 443/tcp                    ALLOW IN    Anywhere
[ 9] 8096/tcp                   ALLOW IN    Anywhere
[10] 1900/udp                   ALLOW IN    Anywhere

After locating the rule you want to delete and the associated number, use the following ufw command

@ sudo ufw delete 6

you will have to confirm that you agree with deleting the selected filter by pressing the y and Enter keys:

Deleting:
 allow 9090/tcp
Proceed with operation (y|n)?
...
Rule deleted

Each time you delete a rule you will have to check the number assigned to the remaining active ones using the reminder command:

@ sudo ufw status numbered, because their order can change!

2). Remove UFW rules by specification

The second solution is by using the ufw delete command followed by the desired rule, as it was added. So, if you have added such a rule:

@ sudo ufw allow 9090/tcp

then you can delete it like this:

@ sudo ufw delete allow 9090/tcp

Warning: after this command, ufw firewall will not ask for confirmation!

At the end you can check the active rules in the firewall:

@ sudo ufw status numbered to make sure they have been deleted:

ipFail-ufw-firewall-status-numbered
ufw-firewall-status-numbered

 

 

Tags: , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *