LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-14-2010, 11:47 AM   #1
tiuz
Member
 
Registered: Mar 2006
Distribution: Slackware 14
Posts: 92

Rep: Reputation: 15
Restore iptables Rules that have been saved with iptables-save


Hello,

A while ago i have saved iptables Rules with iptables-save to a file.

Now i need to do some modifikations and i would like to know if there is a way to get the contents of the file that has been saved with iptables-save back to "Human Readable form again"

For example: THIS form:

# Generated by iptables-save v1.3.5 on Sat Oct 28 15:10:09 2006
*mangle
:PREROUTING ACCEPT [40511857:54699979328]
:INPUT ACCEPT [40485221:54677480953]
:FORWARD ACCEPT [26394:22470203]
:OUTPUT ACCEPT [22521741:1599930162]
:POSTROUTING ACCEPT [22544591:1622118540]
COMMIT
# Completed on Sat Oct 28 15:10:10 2006
# Generated by iptables-save v1.3.5 on Sat Oct 28 15:10:10 2006
*filter
:INPUT ACCEPT [40479586:54675697556]
:FORWARD ACCEPT [26385:22469703]
:OUTPUT ACCEPT [22515275:1599136686]
-A INPUT -i eth1 -j DROP
COMMIT
# Completed on Sat Oct 28 15:10:10 2006

Into this form (how you enter the rules with iptables):

iptables -A INPUT -i ppp0 -p tcp --dport 21 -j DROP

etc etc.....

Thanks,
tz
 
Old 08-14-2010, 01:45 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
It's human readable form already and you only have one filtering rule (which kind of fails to make sense anyway). Your new line you can add to the "*filter" table section below or instead of the "-A INPUT -i eth1 -j DROP" as "-A INPUT -i ppp0 -p tcp --dport 21 -j DROP".
 
Old 08-14-2010, 04:05 PM   #3
tiuz
Member
 
Registered: Mar 2006
Distribution: Slackware 14
Posts: 92

Original Poster
Rep: Reputation: 15
Erm, well itīs only a part of the iptables-saved file (not the full one) and the line with A INPUT -i eth1 -j DROP was where just examples. I just want to know if itīs possible to get rules that have been saved with iptables-save back into a form as you give with iptables.

I mean you donīt enter
:PREROUTING ACCEPT [40511857:54699979328]
:INPUT ACCEPT [40485221:54677480953]
:FORWARD ACCEPT [26394:22470203] etc...etc...

in the command line

tz
 
Old 08-14-2010, 05:33 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Here's a kludge:
Code:
cat /path/to/iptables-save | while read LINE; do
 case "${LINE}" in
  \**) export TABLE="${LINE:1}";;
  :*)  LINE=(${LINE}) ; echo "/sbin/iptables -t "${TABLE} -P ""${LINE[0]:1:255}" "${LINE[1]}"";;
  -A*) echo "/sbin/iptables -t ${TABLE} ${LINE}";;
 esac
done
YMMV(VM)
 
Old 08-14-2010, 05:50 PM   #5
tiuz
Member
 
Registered: Mar 2006
Distribution: Slackware 14
Posts: 92

Original Poster
Rep: Reputation: 15
Nice one ! THANKS !!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Save iptables rules ochienged Linux - Newbie 2 04-15-2008 10:07 AM
iptables-save, iptables-restore, how to set up them in some script sarajevo Linux - Networking 1 03-24-2008 11:39 PM
iptables-save, but rules don't load on boot-up kpachopoulos Debian 2 11-18-2006 10:36 PM
IPTables will not restore rules dieduster Linux - Security 2 12-22-2005 07:17 AM
iptables save rules Osten Debian 1 02-10-2004 04:53 PM

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

All times are GMT -5. The time now is 03:45 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