Penguin
Diff: PerrysFirewallingScript
EditPageHistoryDiffInfoLikePages

Differences between current version and revision by previous author of PerrysFirewallingScript.

Other diffs: Previous Major Revision, Previous Revision, or view the Annotated Edit History

Newer page: version 26 Last edited on Wednesday, April 13, 2011 7:24:40 pm by JamieCurtis
Older page: version 18 Last edited on Friday, February 25, 2005 4:00:41 pm by AlastairPorter Revert
@@ -1,20 +1,33 @@
- cvs -d :pserver :anonymous@cvs .sf .net :/cvsroot /wand checkout iptables  
-  
-Or get the Debian packages from CraigBox (when Hoiho's repository is up, you'll know)  
+To obtain the latest development copy go to [GitHub|http ://github .com/jimmyish/bearwall] . If you want a released version, go to the ~GitHub download page [here|http ://github.com/jimmyish/bearwall/downloads]  
  
 The firewall logs, and by default, syslog will put this on the screen. You can turn that off using dmesg(8). Specifically, you want to type dmesg -n 1. Or edit /etc/syslog.conf to put all the logging on another console. Firewalls shouldn't have monitors anyway. :) 
+  
+If you wish to build a debian package for the firewall (one may already exist in a Hoiho repository someday) check out the debian directory from [here|http://github.com/jimmyish/bearwall-debian] into the copy you got above.  
+  
+----  
+!!!How to build and install the package  
+  
+Use a prebuild debian (or ubuntu) package if you can !  
+  
+If you can't, once you have got the latest development copy, just run  
+<verbatim>  
+ make install  
+</verbatim>  
+This will put things in the following places. By default the configuration lives in <tt>/usr/local/etc/linuxserver-firewall</tt>, the executable in <tt>/usr/local/sbin</tt> and rulsets live in <tt>/usr/local/share/linuxserver-firewall/ruleset.d</tt>  
+  
+Consider altering the default locations inside the <tt>Makefile</tt> before building if you want them to be in a different location.  
  
 ---- 
 !!!How it works 
  
-The main engine is a script called "firewall". When you run it it sets up some chains, and runs each script in "hosts.d/*", then each script in "interfaces.d/*.if". The "ruleset.d/*" directory is used for customised rulesets, the standard scripts come with a whole heap. Theres also a support directory, but this is for internal use and shouldn't be needed. 
+The main engine is a script called "<tt> firewall</tt> ". When you run it it sets up some chains, and runs each script in "<tt> hosts.d/*</tt> ", then each script in "<tt> interfaces.d/*.if</tt> ". The "<tt> ruleset.d/*</tt> " directory is used for customised rulesets, the standard scripts come with a whole heap. Theres also a support directory, but this is for internal use and shouldn't be needed. 
  
-!!The hosts.d directory  
-This is like the interfaces.d directory, except it's not limited per interface. This is useful if you wish to provide rules for all packets on all interfaces (eg: TypeOfService munging) or if you want to have rules that effect a host no matter which interface packets arrive/leave by. This directory doesn't get used much, but the support is there should you want it :) 
+!!The <tt> hosts.d</tt> directory  
+This is like the <tt> interfaces.d</tt> directory, except it's not limited per interface. This is useful if you wish to provide rules for all packets on all interfaces (eg: TypeOfService munging) or if you want to have rules that effect a host no matter which interface packets arrive/leave by. This directory doesn't get used much, but the support is there should you want it :) 
  
-!!The interfaces.d directory  
-This has one file per interface, the file is named after the interface with ".if" appended to it, for instance "eth0.if". Each file specifies the rules for that interface. ${if} is an environmental variable which holds the current interface name. Several chains exist for each interface: 
+!!The <tt> interfaces.d</tt> directory  
+This has one file per interface, the file is named after the interface with "<tt> .if</tt> " appended to it, for instance "<tt> eth0.if</tt> ". Each file specifies the rules for that interface. ${if} is an environmental variable which holds the current interface name. Several chains exist for each interface: 
 ;${if}-in: Used by all packets entering by this interface for this host only. 
 ;${if}-out: Used by all packets leaving by this interface for this host only. 
 ;${if}-forward-in: Used by packets coming IN this interface that aren't destined for this host itself. 
 ;${if}-forward-out: Used by packets going OUT an interface that aren't originated by this host itself 
@@ -32,46 +45,59 @@
 and it will correctly add the --append ${if}- for you and use the correct table too so you don't have to remember if it's the mangle, filter or nat table :) 
  
 Now, you often have a lot of rules that are common between interface, and are even common between firewall installations, for instance some rules that deny all incoming TCP connections but allow outgoing TCP connections. These are stored in the ruleset.d/ directory (discussed later). These firewall "fragments" can be loaded on the fly automatically and used as targets. There is a neat little wrapper around this that you will probably use for almost all your firewalling rules called "policy". policy takes two (or more) arguments, the first is the chain name as you would provide to "apply_policy" and the second is the target, the remaining arguments are passed directly to iptables and can be used for more filtering. 
 some examples: 
- policy in tcp-strict 
+  
+<tt> policy in tcp-strict</tt>  
+  
 will load the "tcp-strict" ruleset from the ruleset.d directory, and then issue a iptables rule such as: 
- /sbin/iptables --table filter --append ${if}-in --jump tcp-strict 
+  
+<tt> /sbin/iptables --table filter --append ${if}-in --jump tcp-strict</tt>  
+  
 policy will not load a ruleset twice if it's used twice, and will not load rulesets that aren't used to save memory. policy is also smart enough to know about built in rules and some aliases that can be used to make things more clear. 
-| __name__ | __aliases__  
-| ACCEPT | ALLOW, PERMIT  
-| DROP | DENY, BLACKHOLE  
-| MASQUERADE | MASQ*  
  
-since policy uses --append you just list the rules you want for an interface one after another. A ruleset for eth0 might look like: 
+__name__ |  
+ __aliases__  
+ACCEPT |  
+ ALLOW, PERMIT  
+DROP |  
+ DENY, BLACKHOLE  
+MASQUERADE |  
+ MASQ*  
+  
+ since policy uses <tt> --append</tt> you just list the rules you want for an interface one after another. A ruleset for eth0 might look like:  
+<verbatim>  
  policy in ACCEPT 
  policy out ACCEPT 
  policy forward-in ACCEPT 
  policy forward-out ACCEPT 
+</verbatim>  
  
 You should only need to use "policy" in the interfaces.d/ directory. In most firewalls I put in place policy is the only command in the interfaces.d directory (sometimes I have a for loop if I've got a range of ports I want to do something with for instance). 
  
 There are also interface features which you can specify in these files. These are /proc entries in /proc/sys/net/ipv4/conf/${if}/*. there is an alias to manage these for you "if_feature". For instance: 
  if_feature rp_filter 1 # enable reverse path filtering for this interface 
  if_feature accept_redirects # accept ICMP redirects on this interface 
 etc... 
  
-!!classes.d 
+!!<tt> classes.d</tt>  
 There are several example class files in CVS. There are several standard interface "types" (eg: "external", "internal", "dmz" etc) and then you symlink interfaces to these. eg: 
+<verbatim>  
  ln -s external eth0.if 
  ln -s internal eth1.if 
  ln -s dmz eth2.if 
+</verbatim>  
  
 There are two new commands now that should appear as the very first rule in a interface definition. 
-; on_startup: This means that this interface definition will be run always from the main firewall init script "./ firewall"  
-; on_demand: This interface definition will only be run if the interface is already up 
+<tt> on_startup</tt> : This means that this interface definition will be run always from the main firewall script "<tt> firewall</tt> "  
+<tt> on_demand</tt> : This interface definition will only be run if the interface is already up 
  
 Also new main scripts were added: 
 ;fw-ipup: This brings up only one interface and presumes that the main "firewall" script has been run to set everything up. It takes one or two parameters. The first parameter is the interface name (such as eth0, eth1) and the second is an optional name for the name of the interface definition to read. For instance a wireless interface might use "home" or "work", so you could type: 
  ifup eth0 home 
 ;fw-ipdown: This removes all the firewalling rules to do with an interface. Dynamic rulesets that are loaded by that interface are __not__ removed, however won't be executed by packets so only a very slight memory overhead is kept. 
  
-!!the ruleset.d directory 
+!!the <tt> ruleset.d</tt> directory 
 This is used to store fragments of a firewall, each fragment does something simple and can be used by interface.d files. rulesets have the form of "''name''.rule". rulesets don't have much in the way of helper functions. The first line of them should be: 
  . support/ruleset.functions 
 the environmental variable ${RULE} will be set to the rule name (basically the name of the file less the ".rule" extension, and the environmental variable ${IPTABLES} will be set to the path to the iptables executable. There are also "polite_reject" and "polite_drop" which will be discussed later. 
  
@@ -86,24 +112,30 @@
 ;tcp-trust: Allows all TCP except to some well known ports that it shouldn't have access to (eg: linuxconf, nfs and portmap etc). Useful for an interface that is connecting to another department that you trust and want traffic to flow to and from, but they don't need any of your sensitive services, so if they get compromised hopefully the attacker won't get the opertunity to compromise you too. 
 ;udp-strict: Disallows incoming UDP that isn't part of an already established "connection" (ie: a reply from a packet that was originated here) 
 ;udp-trust: Disallows incoming UDP to potentially dangerous ports (NFS, Portmap, tftp etc) 
  
-Most of these rules are configurable and rather obvious if you edit them. __These rules must all be set +x or the script will fail.__  
+Most of these rules are configurable and rather obvious if you edit them. 
  
 !!Misc commands 
 There are also some misc commands that can be used from both interfaces.d/ and ruleset.d/ 
  
 ;polite_reject: requires at least one argument, the first is the rule to append to, the rest is any other iptables options that may be used (eg: limiting it by port). polite_reject then rejects the packets ratelimited to 5/s and logs them at a rate of 2/s, rendering floods less effective. All packets that aren't rejected are dropped. 
  
 ;polite_drop: same as polite_reject but only logs at 2/s and doesn't send back reject messages. This is useful for rules where you know that the rejects aren't going to be used (for example if the source address is a martian) or it could be downright harmful (eg: the packet was directed towards a multicast or broadcast address). 
+  
+!! Restrictions on the use of rulesets in forwarding  
+  
+Currently (as of version 1.0) there is a restriction in the use of ruleset in the forward-in of an interface. If a ruleset ACCEPT's a packet on the fw-in of an interface, the packet will ''__NOT__'' be checked by the fw-out of the outgoing interface. If this confuses you, just never use any rulesets that ACCEPT packets in the fw-in path.  
  
 !!FAQ 
 ;__Q__:Why do I get lots of messages saying "End of ''something''" on my screen/in my syslog 
 ;__A__:You don't have a catch all rule for something in one of your class files. Look at the syslog messages carefully and see what interface they are dealing with and which rule you are missing. 
  
 !!Wishlist features 
 These are all wishlist features which may or may not get implemented :) 
-; Renaming interfaces based on their category : "External0" "External1" "Internal1" "Internal2" etc - thusly when an interface comes up it is named by it's purpose. Useful for those machines that have 10+ interfaces and you can never remember which is which, also important when you have multiple ppp0, or VPN interfaces that may come up in any order (do you set the permissive rule on ppp0 or ppp1?) %%% 1. Superceded by a program whose name I forget which has a file of MAC->interfacenames and when run renames interfaces as required. Rather nifty. %%% 2. With ppp interfaces, bring them up with 'unit N' in the command line, and they will take on that number. Solves the problem nicely. You might need pppd 2.4.2.  
-; Some saner defaults : A simple default so if you run the script straight out of CVS it probably does what you want. Go get the deb if you need this.  
-; Use iptables-save and restore to speed shutdown/startup of script? : Not really worth the effort...  
-; Transparent support of ipv6 : Needs investigating  
-; Automatically load ip_nat_* modules : 
+* Renaming interfaces based on their category : "External0" "External1" "Internal1" "Internal2" etc - thusly when an interface comes up it is named by it's purpose. Useful for those machines that have 10+ interfaces and you can never remember which is which, also important when you have multiple ppp0, or VPN interfaces that may come up in any order (do you set the permissive rule on ppp0 or ppp1?)  
+** 1. Superceded by a program whose name I forget which has a file of MAC->interfacenames and when run renames interfaces as required. Rather nifty.  
+** 2. With ppp interfaces, bring them up with 'unit N' in the command line, and they will take on that number. Solves the problem nicely. You might need pppd 2.4.2.  
+* Some saner defaults : A simple default so if you run the script straight out of CVS it probably does what you want. Go get the deb if you need this.  
+* Use iptables-save and restore to speed shutdown/startup of script? : Not really worth the effort...  
+* Transparent support of ipv6 : Needs investigating  
+* Automatically load ip_nat_* modules : done