/commands/ufw/ufw-reset-all-rules
sudo ufw reset: delete all ufw rules and start over
- tool
- ufw
- versions
- ufw 0.36
- os
- linux
sudo ufw reset disables ufw and replaces its rules files with the versions shipped with the package, removing every rule you added. It asks for confirmation; sudo ufw --force reset skips the prompt for scripts. The old files are not deleted: each one is renamed with a timestamp suffix, and ufw prints a Backing up 'user.rules' to '/etc/ufw/user.rules.YYYYMMDD_HHMMSS' line for each.
sudo ufw status numbered # see what you are about to remove
sudo ufw reset # asks, then disables ufw and restores the default files
sudo ufw --force reset # no prompt
ls /etc/ufw/*.rules.* # the timestamped backupsWhat happens, step by step
- ufw prints
Resetting all rules to installed defaults. Proceed with operation (y|n)?. Over SSH the prompt addsThis may disrupt existing ssh connections. - If the firewall is enabled, it is disabled first.
- For every
.rulesfile ufw manages (such asuser.rules,user6.rules,before.rules,after.rulesand their IPv6 versions), ufw renames the current file toNAME.rules.YYYYMMDD_HHMMSSand copies the packaged default in its place. - ufw stays disabled. Nothing is filtered until you run
ufw enableagain.
Because before.rules and after.rules are reset too, custom NAT or forwarding rules you placed there (for a VPN or a router) are gone after the reset, not only the rules you added with ufw allow.
Rebuild safely
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH # or: sudo ufw allow 22/tcp
sudo ufw enable
sudo ufw status verboseAdd the SSH rule before ufw enable on a remote machine. Then re-add the other rules, using the backup user.rules.* file as a list of what you had.
Related commands
| Command | Effect |
|---|---|
| ufw reset | Remove all rules, restore the packaged rules files, disable ufw. |
| ufw --force reset | Same without the confirmation prompt. |
| ufw disable | Stop filtering but keep every rule for the next enable. |
| ufw delete NUM | Remove a single rule by its number from ufw status numbered. |
| ufw reload | Re-read the rules files after editing them by hand. |
Errors
ERROR: You need to be root to run this script: addsudo. See You need to be root.ERROR: '/etc/ufw/user.rules.20261023_101500' already exists. Aborting: two resets ran within the same second; wait and run it again.ERROR: problem running ufw-initon the nextufw enableusually means a rules file you restored or edited is invalid. See problem running ufw-init.
FAQ
Does ufw reset delete my backups?
No. It renames each rules file it replaces with a timestamp suffix such as user.rules.20261023_101500 in the same directory, so the previous rules stay on disk. Old backups from earlier resets are not removed either.
Can I restore the rules after a reset?
Yes, by copying the timestamped backups back over the rules files in /etc/ufw (user.rules, user6.rules and the others it lists) and running ufw enable or ufw reload. Check the files first; they hold the rules exactly as they were before the reset.
Does ufw reset change /etc/default/ufw?
The reset code replaces the .rules files with the copies shipped with the package. Settings in /etc/default/ufw, such as IPV6 or DEFAULT_FORWARD_POLICY, are a separate file; review it after a reset if you changed it before.