Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

My server is Red Hat Enterprise Linux Server release 5.

What is the correct/proper command to clear all existing iptables rules defined in /etc/sysconfig/iptables (so that I can start defining/adding my new rules)?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

1) Method:

Install system-config-firewall and setuptool RPMs. Start "setup", go to "Firewall configuration" and disable the firewall.

Add your own rules.

Start setup and enable the firewall.

2) Method:

Flush iptables using: /etc/init.d/iptables stop

Add your own rules and save the change with:

/etc/init.d/iptables save

Start the configuration:

/etc/init.d/iptables start

share|improve this answer
    
Using method 2, will it allow to add and save rules once iptables is stopped using /etc/init.d/iptables stop? –  Gnanam Aug 4 '10 at 12:24
    
@Gnanam yes it does, iptables is a element part of the system you don't actually STOP it from working you simple flush all the rules when you stop it. you can verify it yourself by stopping it and then trying to run the command iptables -L –  Prix Aug 4 '10 at 18:16
1  
Your method 2 is very simple and straight forward. This is what exactly I was looking for. Instead of me manually cleaning-up all existing rules, this method 2 approach is automatically taking care of this. Even I've followed this same steps in my server and the solution is working. –  Gnanam Aug 5 '10 at 7:02
    
the above method is basicly all the commands you need to use manually being done via the iptables init script; –  Prix Aug 5 '10 at 8:08
iptables -F // flush all chains
iptables -t nat -F
iptables -t mangle -F
iptables -X // delete all chains

Update the file with the current rules (not needed after the above steps but for further references)

iptables-save -c > /etc/iptables-save
share|improve this answer
    
I've a question here. The first command alone iptables -F is not sufficient to delete all the rules? Do I still need to run all the next 3 commands as well? –  Gnanam Aug 4 '10 at 7:14
    
@Gnanam yes, you can confirm that by running iptables -L table where table would be nat for example. –  Prix Aug 4 '10 at 7:20
    
Your answer 'Yes' is to which one of my above 2 questions? 1) Execute just first command alone 2) Execute all the 4 commands. –  Gnanam Aug 4 '10 at 8:36
2  
the answer is for you try it, experience. Those are simple commands and you can always run iptables-restore to bring back what you had previously. –  Prix Aug 4 '10 at 8:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.