Remove Duplicate IPTables Rules
Duplicate entries may appear in your iptables configuration due to parallel efforts of various network security-related applications that may be running on your server. In most cases, having duplicate iptables rules is no big deal, but sometimes they may become an annoyance. Here’s a list of commands you can run on your RHEL/CentOS system to de-dupe your iptables configuration.
/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
Four years and it hadn’t been corrected…
awk command should be something like :
awk ‘/^COMMIT$/ { delete seen; }; !seen[$0]++’
Otherwise “COMMIT” lines are deleted, even worse (hopefully less common situation) if a line is in more than one table, it is just erased from them.
You’re correct. Nice to see someone’s paying attention.
Igor, is the script updated now?
it is