Skip to content

Instantly share code, notes, and snippets.

@webbgamers
Last active May 2, 2022 07:48
Show Gist options
  • Save webbgamers/1537eed3e2d907ad01a6455eb8224ad5 to your computer and use it in GitHub Desktop.
Save webbgamers/1537eed3e2d907ad01a6455eb8224ad5 to your computer and use it in GitHub Desktop.
UFW full removal script
#!/bin/sh
# This script completely removes all the iptables chains ufw creates and doesn't remove after install
if [ "${EUID:-$(id -u)}" -ne 0 ]; then
echo Run this as root.
return 1 2> /dev/null
exit 1
fi
if command -v ufw 2> /dev/null; then
echo Uninstalling ufw.
apt-get -qq remove ufw > /dev/null
fi
echo Removing leftover ufw rules.
iptables-save | grep -v ufw | iptables-restore
ip6tables-save | grep -v ufw | ip6tables-restore
echo Saving changes to persist after reboot.
if [ -f /etc/iptables/rules.v4 ]; then
echo Backing up /etc/iptables/rules.v4 to /etc/iptables/rules.v4.ufw
mv /etc/iptables/rules.v4 /etc/iptables/rules.v4.ufw
fi
if [ -f /etc/iptables/rules.v6 ]; then
echo Backing up /etc/iptables/rules.v6 to /etc/iptables/rules.v6.ufw
mv /etc/iptables/rules.v6 /etc/iptables/rules.v6.ufw
fi
iptables-save > /etc/iptables/rules.v4
ip6tables-save > /etc/iptables/rules.v6
echo Done! Have a great ufw free day!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment