Cannot connect after iptables -F

the chain policy for INPUT is set to DROP.

In absence of any rules, everything gets discarded.

before nuking all the chains, ensure all chains have a policy of ACCEPT a la iptables -P INPUT ACCEPT


In addition to the correct and helpful anwer of Olipro I would recommend something to

avoid the risk of being locked out by your firewall

Use a crontab-bound script which re-opens the firewall in case something went wrong; as you know you can make a mistake in your sshd_config whicht does not do real harm as long as you are still logged in. Not so with iptables: one mistake could be enough, and you are out. Therefor:

#!/bin/bash
# openFW.sh

IPT=$(which iptables)
$IPT -P INPUT ACCEPT
$IPT -P FORWARD ACCEPT
$IPT -P OUTPUT ACCEPT
$IPT -F

NOW=$(date +"%H:%m")
echo "FW opened on %h at $NOW" | mail -s "FW reset cron job jh1" \
[email protected]
logger "WARNING : iptables flushed and opened by cron job"

And with crontab -e place something like

#*/5 8-19 * * * /root/scripts/openFW.sh

to flush your iptables rules and open the FW every 5 mins. Uncomment this before you edit your rules; check the rules (be sure that they are available, and not already flushed by this cron job); after everything is fine comment the flush cron out

Hope this helps.