UFW: Dealing with 'Chain already exists' error

Recently when whitelisting a number of IP addresses through UFW, I received this wonderful error that left me scratching my head...

ERROR: initcaps [Errno 2] ip6tables: Chain already exists.

Through some research, I have found that UFW tends to freak out if multiple `ufw allow from x` commands are run in quick succession and can end up in a shitty state with duplicate entries. Running the following command should resolve those issues and allow you to add in your entries. I'd recommend you allow 1 second between each command when adding entries to your firewall in the future!

sudo ufw disable 
sudo iptables -F 
sudo iptables -X 
sudo ip6tables -F 
sudo ip6tables -X 
sudo ufw enable
Show Comments