Skip to content

Instantly share code, notes, and snippets.

@gtrabanco
Created September 12, 2020 18:40
Show Gist options
  • Save gtrabanco/7d47e14240eeeb01b97c2101d3253efb to your computer and use it in GitHub Desktop.
Save gtrabanco/7d47e14240eeeb01b97c2101d3253efb to your computer and use it in GitHub Desktop.
#!/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
@nullromo
Copy link

How about just iptables-save | awk '/^COMMIT$/ { delete x; }; !x[$0]++' | iptables-restore?

@gtrabanco
Copy link
Author

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