How do I remove all the ufw chains from iptables?
Solution 1:
Note: This has not aged well. Check out other answers for modern solutions first.
This two liner run as root will quickly find all the names and run them through a for loop that runs iptables -F
to flush references to the chain then iptables -X
to delete them.
for ufw in `iptables -L |grep ufw|awk '{ print $2 }'`; do iptables -F $ufw; done
for ufw in `iptables -L |grep ufw|awk '{ print $2 }'`; do iptables -X $ufw; done
Solution 2:
The answer from @flickerfly does not work in my situation. I run the following commands to get rid of all ufw roles and chains
for i in `iptables -L INPUT --line-numbers |grep '[0-9].*ufw' | cut -f 1 -d ' ' | sort -r `; do iptables -D INPUT $i ; done
for i in `iptables -L FORWARD --line-numbers |grep '[0-9].*ufw' | cut -f 1 -d ' ' | sort -r `; do iptables -D FORWARD $i ; done
for i in `iptables -L OUTPUT --line-numbers |grep '[0-9].*ufw' | cut -f 1 -d ' ' | sort -r `; do iptables -D OUTPUT $i ; done
for i in `iptables -L | grep 'Chain .*ufw' | cut -d ' ' -f 2`; do iptables -X $i ; done