ali aboos

Linux: Reset iptables firewall rules

by on Oct.29, 2008, under Linux

Create a shell script (iptables_flush.sh) and copy paste the following lines:

#!/bin/sh
echo "Flushing iptables rules..."
sleep 1
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

Make the file executable
chmod +x iptables_flush.sh
and run the script:
./iptables_flush.sh

CC0 1.0 To the extent possible under law, the creator has waived all copyright and related or neighboring rights to this work.

:,

2 Comments for this entry

  • Wladimir Tavares

    There rules will lock down the machine and if you are connecting from a remote ssh session you wont connect.

    I’d recommend these rules

    # iptables -P INPUT ACCEPT
    # iptables -F
    # iptables -A INPUT -i lo -j ACCEPT
    # iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
    # iptables -A INPUT -p tcp –dport 22 -j ACCEPT
    # iptables -P INPUT DROP
    # iptables -P FORWARD DROP
    # iptables -P OUTPUT ACCEPT
    # iptables -L -v

  • Mokhtar Ebrahim

    Flushing iptables rules when I get lost which rule runs first 🙂

4 Trackbacks / Pingbacks for this entry

Leave a Reply

Time limit is exhausted. Please reload CAPTCHA.

Search InsaneLabs.com

Can't find what you're looking for? Drop a comment on a post or email (ali aht insanelabs doht com)

Links

Links open in a new window