Because deleting rules in UFW can be a little bit annoying this little trick will make your life much easier. Instead of using this syntax:

ufw delete allow 80/tcp

use this syntax:

ufw delete ####

where #### is the number of your firewall rule.

The numbers of your firewall rules can listed using:

ufw status numbered

A possible output could be:

Status: active

     To                         Action      From
     --                         ------      ----
[ 1] 80/tcp                     ALLOW IN    Anywhere
[ 2] 443/tcp                    ALLOW IN    Anywhere

9 comments so far

Add Your Comment
  1. Mischa ter Smitten

    Thank you that was helpful

    Just wondering if there is a way to delete multiple ports at the same time

  2. Mischa ter Smitten

    What do you mean with multiple ports, multiple rules?

  3. Mischa ter Smitten

    Very helpful!

  4. Mischa ter Smitten


  5. Mischa ter Smitten


  6. Mischa ter Smitten

    So helpful. Thank-you! I made a mistake entering a rule and could not figure out the syntax to remove the messed up rule. Using the number saved my day. Thanks again!

  7. Mischa ter Smitten

    Thanks, saved my day

  8. Mischa ter Smitten

    Very useful! Ansible has nice methods to add ufw rules but not to delete them 🙁

  9. Mischa ter Smitten

    Thank you. I need this article.