UFW: Dealing with 'Chain already exists' error

Published on May 24th, 2017

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.

<div style="text-align: center; padding: 20px;">
    <img src="https://tomschlick-screenshots.s3.amazonaws.com/3CLxv2Qz">

    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. <strong>I'd recommend you allow 1 second between each command when adding entries to your firewall in the future!</strong>


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