LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 11-16-2009, 11:06 PM   #1
codenjanod
Member
 
Registered: Oct 2006
Posts: 38

Rep: Reputation: 15
Breaking up a huge firewall script


Hi all,

I am in the process of creating a firewall script for Linux(CentOS 5.3) IPTables, for my current company firewall.
We have various zones;
DMZ, Trusted, Web, Squid and a few others.

Instead of having all these in one script, what will or can be the best way to break the entire script apart, and have the script call various config files, like;

My script is called: firewall.sh
I would like to break it apart so that each zone is in its own file;
dmz.zone
trusted.zone
...
...
etc

And then the script file must call these zone files when loading.

What would be the best way in setting that up ??
And how do you call files from a script ??

Thank you
 
Old 11-16-2009, 11:41 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,035

Rep: Reputation: 471Reputation: 471Reputation: 471Reputation: 471Reputation: 471
Calling a script from within another script is done by sourcing it

eg.
Code:
#!/bin/bash

# source other script
. /path/to/my/other/script

...
That said, using scripts is not the usual process for running iptables firewalls, is your script just for initial configuration or does it load the rules on startup ?
 
Old 11-19-2009, 06:23 AM   #3
codenjanod
Member
 
Registered: Oct 2006
Posts: 38

Original Poster
Rep: Reputation: 15
Hi kbp,

The script initially loads the rules at startup.
I found it easier to maintain a script and reload new or removed rules.

Is there a better/easier way?
Or a more secure way?


Thanks for the help
 
Old 11-19-2009, 07:09 AM   #4
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,035

Rep: Reputation: 471Reputation: 471Reputation: 471Reputation: 471Reputation: 471
Usually the rules are stored in /etc/sysconfig/iptables, but whatever works for you is fine. Just make sure everyone knows where they're supposed to go otherwise it could get confusing

cheers
 
Old 11-19-2009, 08:17 AM   #5
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 3,449

Rep: Reputation: 489Reputation: 489Reputation: 489Reputation: 489Reputation: 489
Quote:
Originally Posted by codenjanod View Post
Hi all,

I am in the process of creating a firewall script for Linux(CentOS 5.3) IPTables, for my current company firewall.
We have various zones;
DMZ, Trusted, Web, Squid and a few others.
hmmm, I'm not totally sure whether you mean that you want one script to call other scripts or whether you want one script that looks up, eg, the ip addresses for the DMZ in one conf file and for the squid zone from another...but, I don't really see any big advantage in breaking it up.
  • if you mean a script that calls other scripts, you have the problem that it might not all happen at once (or, if something goes wrong, the later part might not happen) and that might leave you in an insecure state, if only transiently.
  • if you mean saving the conf for separate zone separately, you can do that within a properly-structured script, so I don't see that being a big advantage either (and you still have the 'what if one of the zone configs is missing or inaccessible' problem, although you can almost cure that by testing for the presence of readable conf files and writing out a suitable error message if the file isn't readable, I suppose)

Another question might be 'Should I write this as a shell script or in a scripting language such as Python, Perl, etc?' Python might be neater, but it does depend on the python interpreter being runnable when you invoke the script (and if someone upgrades the python package, that can't be guaranteed, necessarily) where, by contrast, you can pretty much guarantee that a bash script will be runnable, so you'd need a demonstrable benefit to writing in the 'higher' scripting language for that to be a useful way forward.

Personally, I have a bash script of roughly 1000 lines for setting up iptables and the accompanying syscontrol junk, and I find that is in no danger of becoming unmanageable (not currently in use, but I was at that time interested in iptables and what it could do). That said, I did take pains to comment it pretty extensively (...which is why its ~1000 lines to write out ~100 lines of iptables rules...) and structure the thing so that the separate 'stanzas' of the rules are kept separate.

Quote:
Usually the rules are stored in /etc/sysconfig/iptables
I wouldn't rely on that; I think that's Red Hat and derivatives only. I know the OP is using Centos, and so it is probably true for that and for Fedora, but I don't think outside of those it is generally true (but I don't have extensive experience of others).
 
Old 11-19-2009, 05:26 PM   #6
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Debian, FreeBSD
Posts: 3,739
Blog Entries: 5

Rep: Reputation: Disabled
Quote:
Originally Posted by kbp
Usually the rules are stored in /etc/sysconfig/iptables, but whatever works for you is fine. Just make sure everyone knows where they're supposed to go otherwise it could get confusing
I keep a firewall script under version control that I use to load (and re-load) the ruleset. After doing so, it's a simple:
Code:
# service iptables save
And the ruleset persists going forward.
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Huge Data Set Analysis, Shell Script to copy specific HEX Pairs into a separate file telecom_is_me Programming 11 06-29-2008 10:48 PM
Breaking Past Firewall PatrickNew Linux - Software 7 06-01-2007 12:10 PM
Breaking College Firewall for Chatting scratch09 Linux - Security 2 06-17-2005 12:53 AM
slackware's /etc/rc.d/rc.firewall equivalent ||| firewall script startup win32sux Debian 1 03-06-2004 09:15 PM
Huge Firewall Log Files seanfitz Linux - Networking 1 01-29-2004 10:23 AM


All times are GMT -5. The time now is 09:07 PM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration