How to: Clear All Firewall Rules

sshAfter (or before) installing CSF, APF or some other IPTABLES based firewall there is often a need to clear all existing rules before starting the firewall otherwise you wun the risk of locking yourself out of the server console.

The following suggestion will clear all IPTABLE firewall rules.

#!/bin/sh
echo "Stopping firewall and allowing everyone..."
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

You may find it helpful to have a script on your server ready to run.

Was this helpful?