↑ ↓ select, Enter open, Esc close

Restore iptables rules from a backup

Adjust the values, the command updates live
root@server
iptables-restore --test < /root/iptables-2026-10-09-1200.rules && iptables-restore < /root/iptables-2026-10-09-1200.rules

First checks the file with --test without changing anything, and only loads it if the syntax is valid. All rules of the tables contained in the file are replaced completely. Rules added since the backup, for example by Fail2Ban, are gone afterwards.

Note: If the backup does not allow SSH, the server is no longer reachable via SSH after loading it. Restart Fail2Ban afterwards so it recreates its chains.

Also searched as

  • how to restore iptables rules
  • iptables-restore from file
  • roll back firewall changes

Related one-liners

All in Firewall

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.