Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
08-14-2010, 11:47 AM
|
#1
|
Member
Registered: Mar 2006
Distribution: Slackware 14
Posts: 92
Rep:
|
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
|
|
|
08-14-2010, 01:45 PM
|
#2
|
Moderator
Registered: May 2001
Posts: 29,415
|
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".
|
|
|
08-14-2010, 04:05 PM
|
#3
|
Member
Registered: Mar 2006
Distribution: Slackware 14
Posts: 92
Original Poster
Rep:
|
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
|
|
|
08-14-2010, 05:33 PM
|
#4
|
Moderator
Registered: May 2001
Posts: 29,415
|
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)
|
|
|
08-14-2010, 05:50 PM
|
#5
|
Member
Registered: Mar 2006
Distribution: Slackware 14
Posts: 92
Original Poster
Rep:
|
Nice one ! THANKS !!
|
|
|
All times are GMT -5. The time now is 12:56 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|