Reset (flush) Iptables rules Linux

Posted on May 17, 2017 at 9:53 pm

Bash script to correctly reset (flush) all iptables rules:

#!/bin/bash
 
# Simple script to reset all iptables rules
# Without creating issues like with "iptables -F"
 
IPTABLES="$(which iptables)"
 
# Set default policies (accept) for all three default chains
$IPTABLES -P INPUT ACCEPT
$IPTABLES -P FORWARD ACCEPT
$IPTABLES -P OUTPUT ACCEPT
 
# Now flush all old rules and old custom tables
$IPTABLES --flush
$IPTABLES --delete-chain
$IPTABLES -t nat --flush
$IPTABLES -t mangle --flush

Set correct permissions:

chmod +x resetfw.sh

Reset iptables rules:

./resetfw.sh

Other Posts

Updated Posts