LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 08-05-2015, 05:08 PM   #1
Altiris
Member
 
Registered: Mar 2013
Posts: 556

Rep: Reputation: Disabled
How can I permanently delete all iptables rules?


Im not in the mood for "why". I just want to know if there is a way to completely, permanently remove every single rule that has been added into iptables. If so, what is the command as I really need it. I have tried iptables -F, -Z, -X whatever it is, nothing seems to permanently remove it.

Thank You!
 
Old 08-05-2015, 05:29 PM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Code:
iptables -F
iptables -X
done.
You said "it". Clarify that please.

Last edited by Habitual; 08-05-2015 at 05:30 PM.
 
Old 08-05-2015, 05:40 PM   #3
Altiris
Member
 
Registered: Mar 2013
Posts: 556

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
Code:
iptables -F
iptables -X
done.
You said "it". Clarify that please.
Oh by it I meant all of the rules. Ive tried iptables -F and iptables -X but Ill try again. Well, it works that much I know. However when I try to restore my rules back using a config file, its put back rules that had been previously added by an automated program (libvirt), even if I clear it from the file. The command I use to restore is iptables-restore </etc/firewall.rules and then I do iptables-save >/etc/firewall.rules I will try it all again though.

EDIT: I guess I just can't use the iptables-save command anymore as it puts back the stuff from libvirt. Guess I can only use iptables-restore ...that stinks. iptables is really wonky.

Last edited by Altiris; 08-05-2015 at 05:44 PM.
 
Old 08-05-2015, 05:58 PM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
Quote:
Originally Posted by Altiris View Post
Oh by it I meant all of the rules. Ive tried iptables -F and iptables -X but Ill try again. Well, it works that much I know. However when I try to restore my rules back using a config file, its put back rules that had been previously added by an automated program (libvirt), even if I clear it from the file. The command I use to restore is iptables-restore </etc/firewall.rules and then I do iptables-save >/etc/firewall.rules I will try it all again though.

EDIT: I guess I just can't use the iptables-save command anymore as it puts back the stuff from libvirt. Guess I can only use iptables-restore ...that stinks. iptables is really wonky.
Well, when you do iptables-save > /etc/firewall.rules you overwrite your original rules with whatever is in the tables at that time. When you then use that file with iptables-restore you reload them just like it was when saved - additional rules included. Whatever was originally in /etc/firewall.rules is... gone...

If you want to keep your original firewall rules intact, then try...

Code:
iptables-save >/etc/firewall.saved.rules
itpables-restore /etc/firewall.saved.rules

AND usually at boot or to put back to known state...

/etc/rc.d/rc.firewall start which likely loads /etc/firewall.rules as shell script
Generally, the iptables-save/-restore format is not the same as a firewall script used to initialize iptables which is commonly /etc/firewall.rules, so overwriting that file with iptables-save will likely break your boot firewall script.

So to permanently delete any runtime added rules you must have the original iptables rules script available to run after iptables -F.

Last edited by astrogeek; 08-05-2015 at 06:13 PM. Reason: typos, additional comment
 
Old 08-05-2015, 06:25 PM   #5
Altiris
Member
 
Registered: Mar 2013
Posts: 556

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
Well, when you do iptables-save > /etc/firewall.rules you overwrite your original rules with whatever is in the tables at that time. When you then use that file with iptables-restore you reload them just like it was when saved - additional rules included. Whatever was originally in /etc/firewall.rules is... gone...

If you want to keep your original firewall rules intact, then try...

Code:
iptables-save >/etc/firewall.saved.rules
itpables-restore /etc/firewall.saved.rules

AND usually at boot or to put back to known state...

/etc/rc.d/rc.firewall start which likely loads /etc/firewall.rules as shell script
Generally, the iptables-save/-restore format is not the same as a firewall script used to initialize iptables which is commonly /etc/firewall.rules, so overwriting that file with iptables-save will likely break your boot firewall script.

So to permanently delete any runtime added rules you must have the original iptables rules script available to run after iptables -F.
Yeah I just found this site https://www.frozentux.net/iptables-t...tml/x1882.html and it said to do pretty much the samething. Your post helepd me understand more though.
 
Old 08-05-2015, 06:33 PM   #6
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
Quote:
Originally Posted by Altiris View Post
Yeah I just found this site https://www.frozentux.net/iptables-t...tml/x1882.html and it said to do pretty much the samething. Your post helepd me understand more though.
Great!

Just remember, iptables-save and iptables-restore allow you to save state and restore a saved state. Restore does NOT restore an initial non-saved state, which might be confusing you.

The initial state is generally set by a shell script using iptables -N/-A/-I commands and is what you should manage for setting known states.

Good luck!

Last edited by astrogeek; 08-05-2015 at 06:37 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to permanently set iptables rules austinramsay Slackware 12 10-13-2013 11:29 AM
[SOLVED] Delete permanently a route v_fone Linux - Networking 2 09-03-2009 07:27 AM
how to save iptables firewall rules permanently sunlinux Linux - Security 3 12-07-2006 11:53 AM
IPTABLES how to add/edit/delete rules in existing chain? debug019 Linux - Newbie 1 11-11-2004 02:48 PM
Permanently Adding iptable rules GUIPenguin Linux - Networking 2 10-12-2004 11:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 01:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration