If your new to linux, ufw is very useful tool. Really simple to install with ubuntu.
However, should you choose to get rid of it for some reason, it leaves behind quite a mess.
Here is a quick script to clean up the mess.
Here is the whole process as a bash script:
#!/usr/bin/bash
iptables -P INPUT ACCEPT
iptables -X ufw-user-outputiptables -X ufw-user-logging-outputiptables -X ufw-user-logging-inputiptables -X ufw-user-logging-forwardiptables -X ufw-user-limit-acceptiptables -X ufw-user-limitiptables -X ufw-user-inputiptables -X ufw-user-forwardiptables -X ufw-track-outputiptables -X ufw-track-inputiptables -X ufw-skip-to-policy-outputiptables -X ufw-skip-to-policy-inputiptables -X ufw-skip-to-policy-forwardiptables -X ufw-reject-outputiptables -X ufw-reject-inputiptables -X ufw-reject-forwardiptables -X ufw-not-localiptables -X ufw-logging-denyiptables -X ufw-logging-allowiptables -X ufw-before-outputiptables -X ufw-before-logging-outputiptables -X ufw-before-logging-inputiptables -X ufw-before-logging-forwardiptables -X ufw-before-inputiptables -X ufw-before-forwardiptables -X ufw-after-outputiptables -X ufw-after-logging-outputiptables -X ufw-after-logging-inputiptables -X ufw-after-logging-forwardiptables -X ufw-after-inputiptables -X ufw-after-forwardapt-get remove ufw#As a basic firewall I’d recommend the following:iptables -Fiptables -A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPTiptables -A INPUT -i lo -j ACCEPTiptables -A INPUT -p tcp -m tcp –dport 80 -j ACCEPTiptables -A INPUT -p tcp -m tcp –dport 443 -j ACCEPTiptables -A INPUT -p tcp -m tcp –dport 13160-j ACCEPTiptables -A INPUT -d XX_REPLACE_WITH_YOUR_SERVER_IP/32 -p icmp -m icmp –icmp-type 8 -m state –state NEW,RELATED,ESTABLISHED -j ACCEPTiptables -A INPUT -d XX_REPLACE_WITH_YOUR_SERVER_IP/32 -p icmp -m icmp –icmp-type 0 -m state –state RELATED,ESTABLISHED -j ACCEPTiptables -P INPUT DROPiptables -P FORWARD DROPiptables -P OUTPUT ACCEPT
This will:
Reset the default policy of INPUT to ACCEPT so we don’t get locked out of our box.
Then remove the custom ufw chains, flush all existing rules, accept established connections, accept all connections on loopback device, accept all connects to ports 80(http),443(https), and 22(sshd)
Then remove the custom ufw chains, flush all existing rules, accept established connections, accept all connections on loopback device, accept all connects to ports 80(http),443(https), and 22(sshd)
It will also accept pings from machines which have established a connection. With large packet support now enabled by default in the linux kernel, its important to allow some pings to be accepted. Then we set the default policys of input and forward to drop and output to accept.
Make sure you replace XX_REPLACE_WITH_YOUR SERVER_IP with your servers ip address.
4 responses to “The complicated process for removing the “uncomplicated firewall””
Extremely useful stuff, just had to clean up a confused UFW install and this saved me a bundle of time. Many thanks for sharing!
This saved me a lot of time too. I'm running Linux Mintz and I had to add:
iptables -X ufw-track-forward
Many thanks!
I use this:
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
iptables -t nat -P OUTPUT ACCEPT
iptables -F
iptables -t nat -F
iptables -X
iptables -t nat -X
To remove all rules in fw, put in a loop bash this:
ufw –force delete $(ufw status numbered |(grep 'on' | awk -F"[][]" '{print $2}'))
Regards.
At the time I didn’t have a lot of experience with bash. Your loop to remove looks like a better deal. Thanks for posting.