11

I was testing something and added a rule to my firewall to allow port 9000. in retrospect, I should have just disabled it temporarily. anyhow, I went to remove the rule and it wont let me, it says rule not found.

$ sudo ufw delete 9000
ERROR: Could not find rule '9000'

but clearly, the rule is still active:

$ sudo ufw status verbose
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip

To                         Action      From
--                         ------      ----
80                         ALLOW IN    Anywhere
443                        ALLOW IN    Anywhere
9000                       ALLOW IN    Anywhere
80 (v6)                    ALLOW IN    Anywhere (v6)
443 (v6)                   ALLOW IN    Anywhere (v6)
9000 (v6)                  ALLOW IN    Anywhere (v6)

I read the UFW help and it says you can delete a port number, but it doesn't happen. How can I remove the rule for port 9000 from UFW?

4 Answers 4

22

The correct syntax would be:

sudo ufw delete allow 9000

If you make a rule by the following:

sudo ufw allow 9000

Then the rule is allow 9000. Now if you want to delete the rule:

sudo ufw delete rule

i.e.

sudo ufw delete allow 9000
5
  • 1
    @j0h: Happy to help :)
    – heemayl
    Mar 7, 2015 at 16:40
  • 1
    You can also print the rules numbered from one and up(ufw status numbered?) . And then you can delete them by giving the number(ufw delete 3?). Don't forget to read the man page for ufw(8) if you don't remember the syntax.
    – Anders
    Mar 8, 2015 at 2:46
  • Good one! :-) Upvoted!
    – Fabby
    Mar 12, 2015 at 12:12
  • It didn't help me. I get the following message: "Could not delete non-existent rule Could not delete non-existent rule (v6)" But when checking the status it still appears Sep 16, 2016 at 19:26
  • I found it out. Type sudo ufw status numbered. Then "sudo ufw delete # (number of rule, ex. 'sudo ufw delete 3')" Sep 16, 2016 at 19:34
5

The first step you can list all current rules by number:

$ sudo ufw status numbered

Then base on the listed numbers, you can delete rule by number. The number of the rule is shown in the leftmost column.

$ sudo ufw delete 2

You can refer to link: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-14-04

0

I recommend using Gufw (A very user-friendly way to manage your Ubuntu Firewall, powered by ufw)

0

here's how you can delete all rules for a specific port number in ufw (Port 3000 in this case) :

while true; do rule_number=$(ufw status numbered | awk '/(ALLOW|DENY) IN/ && $0 ~ /\<(3000)\>/{gsub(/[\[\]]/, ""); print $1; exit}'); if [ -z "$rule_number" ]; then break; else sudo yes | ufw delete $rule_number --force; fi; done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .