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 reset starts the firewall over and keeps a backup of your old rules

Ufw
~/tips/tip-ufw-reset-backup-rules

sudo ufw reset

Wipes all firewall rules back to the defaults and saves the old rule files first.

Sometimes a ufw rule list is past saving. Duplicates from old scripts, and an allow rule nobody can explain. I’d rather start clean than delete them one by one, and ufw reset does exactly that.

sudo ufw reset
ls /etc/ufw/*.rules.*

The man page says it disables the firewall and resets it to the installation defaults. It asks for confirmation first, and when you run it over SSH the prompt warns that it may disrupt existing SSH connections. --force skips the question, which I’d only use in a script.

What I like is that it doesn’t throw anything away. Before copying the default files into place, ufw renames your current rule files with a timestamp, so /etc/ufw/user.rules becomes something like /etc/ufw/user.rules.20261127_143005, and the same happens to before.rules, after.rules and their IPv6 versions. The output lists every backup it made. If you change your mind, those files are still there to compare with or copy back.

The caveat is the order of things on a remote server. After a reset ufw is disabled and every rule is gone, including the one for SSH. Your current session usually survives, but don’t run ufw enable again until you’ve added the SSH rule back:

sudo ufw allow OpenSSH
sudo ufw enable

Also note that a reset puts back the default before.rules, so any hand edits in there (a NAT block, a ping rule) are gone from the live config too. They’re only in the timestamped copy now.

Further reading: ufw manual page (Ubuntu), ufw source on Launchpad

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