Created
September 12, 2020 18:40
-
-
Save gtrabanco/7d47e14240eeeb01b97c2101d3253efb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Delete all duplicate rules | |
/sbin/service iptables save | |
/sbin/iptables-save | awk '/^COMMIT$/ { delete x; }; !x[$0]++' > /tmp/iptables.conf | |
/sbin/iptables -F | |
/sbin/iptables-restore < /tmp/iptables.conf | |
/sbin/service iptables save | |
/sbin/service iptables restart | |
if [ -f /tmp/iptables.conf ] ; then /bin/rm -f /tmp/iptables.conf ; fi |
Yes, it would be enough. And it is nice to type in console but, as script, I prefer to flush before restore because we are doing a replacement of all rules.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How about just
iptables-save | awk '/^COMMIT$/ { delete x; }; !x[$0]++' | iptables-restore
?