brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ufw status numbered lets you delete a rule by its number

Ufw
~/tips/tip-ubuntu-ufw-delete-numbered

sudo ufw status numbered

Removes a firewall rule by its number from the numbered status list.

Removing a ufw rule by retyping it exactly is annoying. You do not have to.

sudo ufw status numbered
sudo ufw delete 3

The first command prints every rule with a number in square brackets. The second removes the rule with that number. Per the man page, that is the documented way to do it.

Two things trip people up. First, the numbers shift. Delete rule 3 and the old rule 4 is now 3, so run the status command again before the next delete, or you remove the wrong one. Second, with IPv6 enabled each rule shows up twice, a v4 line and a v6 line. Deleting by number removes only the line you named. The man page notes that to remove both, you prefix the original rule with delete:

sudo ufw delete allow 8080/tcp

That second form is the one I prefer when I know the rule. The numbered one is for when I do not remember what I typed three months ago.

Caveat: do not delete your SSH rule on a remote machine. Check which number is which before you press Enter.

Further reading: ufw(8) man page (Ubuntu 24.04), On this site: ufw show added lets you check your rules before you enable the firewall, On this site: ufw limit slows down anything hammering your SSH port

More Ufw tips sudo ufw app update all sudo ufw show raw sudo ufw allow to 10.0.0.1 proto esp sudo ufw allow to 224.0.0.0/24 from 10.0.0.1 proto vrrp sudo ufw show listening All Ufw tips (32) All topics

Link