I'm running a VPS, and would like to reset the iptables' rules to its fresh-out-of-the-box default state. These are the commands I've come up with:
#!/bin/sh echo "Resetting all iptables rules..." #Reset default table policies iptables -P INPUT ACCEPT iptables -P FORWARD ACCEPT iptables -P OUTPUT ACCEPT #Reset nat table policies iptables -t nat -P PREROUTING ACCEPT iptables -t nat -P POSTROUTING ACCEPT iptables -t nat -P INPUT ACCEPT iptables -t nat -P OUTPUT ACCEPT #Reset mangle table policies iptables -t mangle -P PREROUTING ACCEPT iptables -t mangle -P POSTROUTING ACCEPT iptables -t mangle -P INPUT ACCEPT iptables -t mangle -P OUTPUT ACCEPT iptables -t mangle -P FORWARD ACCEPT #Reset raw table policies iptables -t raw -P PREROUTING ACCEPT iptables -t raw -P OUTPUT ACCEPT #Flush all rules and delete empty chains iptables -F iptables -X iptables -t nat -F iptables -t nat -X iptables -t mangle -F iptables -t mangle -X iptables -t raw -F iptables -t raw -X
Are these rules comprehensive enough? I've messed with my iptables and I just want to start from a clean slate.
Will I be locked out of my VPS if I reboot?
Do I need to use the -Z command on every table to zero the packet and byte counters on all rules in a chain? E.g. "iptables -t nat -Z" (and repeat the same for all other tables)?