From owner-freebsd-questions@FreeBSD.ORG Tue Apr 13 13:00:30 2010 Return-Path: Delivered-To: freebsd-questions@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5396E106567E for ; Tue, 13 Apr 2010 13:00:30 +0000 (UTC) (envelope-from steve@ibctech.ca) Received: from smtp.ibctech.ca (v6.ibctech.ca [IPv6:2607:f118::b6]) by mx1.freebsd.org (Postfix) with SMTP id B473A8FC2D for ; Tue, 13 Apr 2010 13:00:29 +0000 (UTC) Received: (qmail 76823 invoked by uid 89); 13 Apr 2010 13:03:23 -0000 Received: from unknown (HELO ?IPv6:2607:f118::5?) (steve@ibctech.ca@2607:f118::5) by 2607:f118::b6 with ESMTPA; 13 Apr 2010 13:03:23 -0000 Message-ID: <4BC46AEA.7050008@ibctech.ca> Date: Tue, 13 Apr 2010 09:00:26 -0400 From: Steve Bertrand User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.7) Gecko/20100111 Lightning/1.0b1 Thunderbird/3.0.1 MIME-Version: 1.0 To: Jerry References: <20100411115740.7bbf7f88@scorpio.seibercom.net> <4BC32880.5050507@ibctech.ca> <20100412141535.786efc3c@scorpio.seibercom.net> In-Reply-To: <20100412141535.786efc3c@scorpio.seibercom.net> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: freebsd-questions@FreeBSD.org Subject: Re: IPFW and separate data files. X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Apr 2010 13:00:30 -0000 On 2010.04.12 14:15, Jerry wrote: > On Mon, 12 Apr 2010 10:04:48 -0400, Steve Bertrand > articulated: > >> On 2010.04.11 11:57, Jerry wrote: >>> I am using IPFW on a FreeBSD-7.3 machine. Presently, I am loading >>> several tables for IPFW. So far, I have just keep the data for the >>> tables in the actual "ipfw-rules" referenced in the 'rc.conf' file >>> itself. What I would like to do is keep the data for these tables in >>> separate files and just have them imported when the firewall is >>> loaded. I have constructed a simple script that is called from the >>> 'ipfw-rules' file. >>> >>> My question is if there is a better way of accomplishing this? Is >>> there a downside to doing this way? The data for these tables tends >>> to be dynamic and I would rather work with the separate files than >>> edit the master one and risk messing it up. >> >> I have a setup that is very similar to this. I 'include' the other >> files from the one referenced in /etc/rc.conf by adding lines like >> this: >> >> . /etc/ipfw.include > > OK, I think I know where you are going with this; however, I want to > make sure I have it correct. I am assuming that you are adding the > ". /etc/ipfw.include" file in the file referenced in the rc.conf file. > Is that correct? It is correct: # grep ipfw.rules /etc/rc.conf firewall_script="/etc/ipfw.rules" # grep ipfw.include /etc/ipfw.rules . /etc/ipfw.include > I know that it is a little over the top, which is why I was looking for > an easier way. The reason I was doing it this way was because I only had > to add the IPs that I wanted to block without having to add the directives also. That is all I do too. All of my table definitions are in the initial fw script, ipfw.rules (poorly named, I know ): #!/bin/sh flush="/sbin/ipfw -q flush" cmd="/sbin/ipfw add" table="/sbin/ipfw table" $flush # Tables # Client/infrastructure IPs for allowing access $table 1 add 208.70.104.0/21 ..... # SMTP ALLOWED OUTBOUND TABLE $table 2 add 208.70.104.92/32 $table 2 add 208.70.104.93/32 .... . /etc/ipfw.include etc. The included file contains the rule definitions themselves, as well as any sweeping rules that aren't for any specific protocol or IP address. To add a new IP to a rule that is using tables: # ipfw table 2 add x.x.x.x Because this doesn't save anything, a reboot will erase those new entries. To take care of that, I use this (note that this may not catch edge cases): ipfw list | \ perl -nle 's/table\((\d+)\)/\"table($1)"/g; print "\$cmd $_";' \ > /etc/ipfw.include \ && chown root:wheel /etc/ipfw.include && chmod 400 /etc/ipfw.include Steve