How to temporarily disable an iptables rule

If you want to temporarily disable an iptables rule, you need to edit it at the right point in the chain, since the rules are enforced in a specific order. Fortunately iptables lets you save and reload a list of rules, so the way to temporarily disable a rule is to save off the rule list, edit it, and then restore it:

iptables-save > ~/firewall-v1.rules
iptables-save > ~/firewall-v2.rules
vi ~/firewall.rules
iptables-restore ~/firewall-v1.rules

You can comment out lines with a “#”, then restore them when you’re finished with your task.

It seems that iptables-restore deletes the file, so having two copies allows you to revert if you wish.

Leave a Reply

Your email address will not be published. Required fields are marked *