Wednesday, September 9, 2015

Linux: iptables: Removing a collection of iptables rules at once

Here is a small trick for removing several iptables rules at once,

Let's assume we would like to add some rules:
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
I can use the comment match and add a comment to this line:
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE -m comment --comment "SOME_COMMENT"

Now, cleaning all the relevant rules in a simple command would be:

# iptables-save | grep -v SOME_COMMENT | iptables-restore

 Probably not the best way to do it, but it's simple and fast.


Have fun,
-Tal Kain

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.