Click Technology

Linux, Windows, Mac it's all good

Flushing IPTABLES

April4

IPTABLES is the Linux firewall and it is, in short, great. The one only niggle is that sometimes you want to be able to just clear all the rules and have a nice clean firewall to fiddle with.

I found this script on the interweb and it works like a dream. To use it just do this..

1. Open a terminal window by opening the run command line with Alt + F2. Of course, if you’re using a GUI-less terminal, this doesn’t apply, just skip to step 2.

Once open, type

gnome-terminal

and click OK. There’s your terminal window.

2. Now, let’s install vim, one of the common editors in Linux. Issue the command

sudo apt-get install vim

Enter your normal login password and away you go, installing VIM in a second, job done.

3. Now let’s create the file with these commands..

cd
sudo vim fwflush

to create and edit the file. Once in VIM, just cut and paste the script below into the terminal window / command line.

#!/bin/sh
#
# rc.flush-iptables - Resets iptables to default values.
#
# Copyright (C) 2001  Oskar Andreasson <bluefluxATkoffeinDOTnet>
#
#
# Configurations
#
IPTABLES="/sbin/iptables"

#
# reset the default policies in the filter table.
#
$IPTABLES -P INPUT ACCEPT
$IPTABLES -P FORWARD ACCEPT
$IPTABLES -P OUTPUT ACCEPT

#
# reset the default policies in the nat table.
#
$IPTABLES -t nat -P PREROUTING ACCEPT
$IPTABLES -t nat -P POSTROUTING ACCEPT
$IPTABLES -t nat -P OUTPUT ACCEPT

#
# reset the default policies in the mangle table.
#
$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

#
# flush all the rules in the filter and nat tables.
#
$IPTABLES -F
$IPTABLES -t nat -F
$IPTABLES -t mangle -F
#
# erase all chains that's not default in filter and nat table.
#
$IPTABLES -X
$IPTABLES -t nat -X
$IPTABLES -t mangle -X

Job done, now save it using the following key sequence in order

:wq

OK, that’s the file created and ready for use – we just need to make it excecutable. Do that by issuing the chmod command thus…

chmod u+x fwflush

4. Now run the script thus..

./fwflush

Now, if you issue the iptables command to show all the chains/rules, there are none but the defaults. Sweeeet!

sudo iptables -L
posted under Linux Tips | No Comments »

I used to run Click Technology from 1995 to 2010.  Now no longer, I maintain the site with things I find interesting or are noteworthy or have some handy-tip value.