I created the following temporary rule that I enable occasionally but I would like to remove it without the need of restarting the machine.

Can someone provide me the command?

sudo iptables -t nat -I PREROUTING -i eno1 -p TCP -d --dport 2020 -j DNAT --to-destination

I would recommend that you save your existing rules before making your adjustment, and then restoring those rules once you're done using the special rule.

  1. iptables-save > /etc/iptables.rules
  2. iptables -t nat -I PREROUTING -i eno1 -p TCP -d --dport 2020 -j DNAT --to-destination
  3. Do your thing.
  4. iptables --flush
  5. iptables-restore < /etc/iptables.rules

This would be especially useful if you have other iptables rules (such as those from fail2ban, etc).

Another option is to save your iptables to a file as described above, except instead of manually flushing and restoring, you could set up /etc/network/if-pre-up.d/ to restore, and have /etc/network/if-post-down.d/ flush. This way, you could just do something such as ifdown eth0 && ifup eth0 to get back to where you started.

This question may be helpful.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.