Howto disable the iptables firewall in Linux

Q. Quick question: I need to disable firewall in Linux for testing purpose. I’m using CentOS 4.4. How do I disable the firewall in Linux?

A. A Linux firewall is software based firewall that provides protection between your server (workstation) and damaging content on the Internet or network.

It will try to guard your computer against both malicious users and software such as viruses/worms.

Task: Disable / Turn off Linux Firewall (Red hat/CentOS/Fedora Core)

Type the following two commands (you must login as the root user):
# /etc/init.d/iptables save
# /etc/init.d/iptables stop

Task: Enable / Turn on Linux Firewall (Red hat/CentOS/Fedora Core)

Type the following command to turn on iptables firewall:
# /etc/init.d/iptables start

Other Linux distribution

If you are using other Linux distribution such as Debian / Ubuntu / Suse Linux etc, try following generic procedure.

Save firewall rules
# iptables-save > /root/firewall.rules
OR
$ sudo iptables-save > /root/firewall.rules

Now type the following commands (login as root):
# 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

To restore or turn on firewall type the following command:
# iptables-restore < /root/firewall.rules

GUI tools

If you are using GUI desktop firewall tools such as 'firestarter', use the same tool to stop firewall.
System > Administration > firestarter > Click on Stop Firewall button:

Howto disable the iptables firewall in Debian  / Ubuntu Linux

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 10 comments… read them below or add one }

1 mike 11.23.07 at 2:37 pm

you can get the status of iptables with the following

service iptables status

service iptables help gives:

Usage: /etc/init.d/iptables {start|stop|restart|condrestart|status|panic|save}

2 Photos of China 07.04.08 at 7:29 am

I have this error on centOS

/etc/init.d/iptables save
Usage /etc/init.d/iptables {start|output_int|stop|restart|status}

3 vivek 07.04.08 at 8:19 am

Are you sure you got CentOS? Another option is
iptables-save > /root/working.fw

4 Flash32 10.30.08 at 4:06 pm

Thanks Guys!!!

5 Robert 12.24.08 at 3:32 pm

The easy way to do this is:

chkconfig iptables off

then to re-enable

chkconfig –level 345 iptables on

6 joe 01.05.09 at 7:56 pm

on fedora, once you enabled firwalls/selinux during installation, I can never make nfs boot or ftp works. you can see firewall disabled, iptables disabled, yet no help. Either selinux or fedora GUI has bugs, what I get:
Loading: TFTP error 2: Only absolute filenames allowed
Failed.
to our people, the selinux is a nightmare. forget what the system told you. selinux adds extension to file attributes then some garbage cannot be removed.

7 Amie 01.07.09 at 8:32 pm

Hi – first time here and really need some help!

I gave my father in law a netbook for Xmas with Linux as an operating system but cannot connect to Sky broadband. Sky unable to help, any ideas??

8 Manu Anand 01.09.09 at 11:36 pm

Hey Amie:

Try connecting with a ethernet cable.
If that works then try KDE’s network manager.

HTH
Manu

9 Tomas 02.27.09 at 3:08 pm

Excellent!
Really Thanks

10 Ashwani 04.09.09 at 1:50 am

Thanks for help….

FTP can be accessed by stop IP tables.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tagged as: , , , , , , , , , , , , , ,

Previous post: Download or install C, C++ compiler on Red Hat Enterprise Linux 5 (RHEL)

Next post: Howto Red hat enterprise Linux 5 configure the network card