From owner-freebsd-ipfw@FreeBSD.ORG Wed Jan 21 10:52:51 2004 Return-Path: Delivered-To: freebsd-ipfw@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 730A716A4CE for ; Wed, 21 Jan 2004 10:52:51 -0800 (PST) Received: from riffraff.plig.net (riffraff.plig.net [195.40.6.40]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8C66243D55 for ; Wed, 21 Jan 2004 10:52:35 -0800 (PST) (envelope-from marcs@draenor.org) Received: by riffraff.plig.net (Postfix, from userid 3010) id A94BEFA3E6; Wed, 21 Jan 2004 18:52:34 +0000 (GMT) Date: Wed, 21 Jan 2004 18:52:34 +0000 From: Marc Silver To: Thomas Wolf Message-ID: <20040121185234.GE70495@draenor.org> References: <20040121162343.45gqrbzfytkwc@.mailhost.wsf.at> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040121162343.45gqrbzfytkwc@.mailhost.wsf.at> User-Agent: Mutt/1.4.1i cc: freebsd-ipfw@freebsd.org Subject: Re: dialup firewalling X-BeenThere: freebsd-ipfw@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: IPFW Technical Discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Jan 2004 18:52:51 -0000 Hi guys, Thanks very much. You have all been fantastic, and a great help to me. I've revised the document to use PPP NAT, and amended the ruleset as below: # Define the firewall command (as in /etc/rc.firewall) for easy # reference. Helps to make it easier to read. fwcmd="/sbin/ipfw" # Define our outside interface. With userland-ppp this # defaults to tun0. oif="tun0" # Force a flushing of the current rules before we reload. $fwcmd -f flush # Allow all connections that we initiate, and keep their state, # but deny established connections that don't have a dynamic rule. $fwcmd add check-state $fwcmd add allow ip from me to any out via $oif keep-state $fwcmd add deny tcp from any to any established in via $oif # Allow internet users to connect to the port 22 and 80. # This example specifically allows connections to the sshd and a # webserver. $fwcmd add allow tcp from any to me dst-port 22,80 in via $oif setup keep-state # Allow ICMP packets: remove type 8 if you don't want your host # to be pingable. $fwcmd add allow icmp from any to any via $oif icmptypes 0,3,8,11,12 # Deny and log all the rest. $fwcmd add deny log ip from any to any Does this ruleset look more correct and will it definitely work with PPP's NAT? Once again, thank you all very much and I look forward to your replies. Cheers, Marc On Wed, Jan 21, 2004 at 03:23:43PM -0000, Thomas Wolf wrote: > > Marc Silver schrieb: > > > Hi guys and gals, > > > > The short story: I wrote an article a while back about dialup > > firewalling with FreeBSD, and after an update was made to the article a > > few months back by another individual it's been slightly broken. > > > > I am currently working on fixing this document and get it more up to > > date, and was hoping to run the following ruleset past all of you. The > > problem is mostly that I no longer have a dialup connection to test with > > this, so I was hoping to ask opinions on whether or not the following > > rulebase would work: > > > > # Force a flushing of the current rules before we reload. > > $fwcmd -f flush > > > > # Divert all packets through the tunnel interface. > > $fwcmd add divert natd all from any to any via tun0 > > > > # Allow all connections that we initiate, and keep their state, > > # but deny established connections that don't have a dynamic rule. > > $fwcmd add check-state > > $fwcmd add allow ip from me to any keep-state > > $fwcmd add deny tcp from any to any established > > > > # Allow internet users to connect to the port 22 and 80 on my machine. > > # This example specifically allows connections to the sshd and a > > # webserver. > > $fwcmd add allow tcp from any to me dst-port 22,80 setup keep-state > > > > # Allow ICMP packets: remove type 8 if you don't want your host > > # to be pingable. > > $fwcmd add allow icmp from any to any icmptypes 0,3,8,11,12,13,14 > > > > # Deny and log everything else. > > $fwcmd add deny log ip from any to any > > > > Now, if my knowledge of ipfw2 is correct, this should allow everything > > out, and should only allow port 22 and 80 in. It'll also allow ICMP. > > Simple enough, but am I correct in my assumptions? > > No, it will not work. keep-state rules and natd are difficult to handle. > In your setup, traffic from a box in your lan ($lanclientip) with a > destination on the internet ($targetip), going via your gateway > ($gatewayip) will be handled like this: > > original packet: $lanclientip -> $targetip > > on leaving the gateway, packets are going through the divert rule, > now the packet has $gatewayip -> $targetip. The keep-state rule > now creates a temporary rule for '$gatewayip <-> $targetip' and allows > the packet out. > > The response from $targetip gets 'natted first so when it reaches > the check-state rule, it already has $targetip -> $lanclientip and > will not match the temporary rule. > > Thomas > > -- > Thomas Wolf > Wiener Software Fabrik > Dubas u. Wolf GMBH > 1050 Wien, Mittersteig 4 -- Success is never final. Failure is never fatal. It is courage that counts. -- Winston Churchill