From owner-freebsd-net@freebsd.org Mon Jul 17 18:19:02 2017 Return-Path: Delivered-To: freebsd-net@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E9552D9CDFD for ; Mon, 17 Jul 2017 18:19:02 +0000 (UTC) (envelope-from brahmann@lifec0re.net) Received: from mx.lifec0re.net (lifec0re.net [212.86.98.154]) by mx1.freebsd.org (Postfix) with ESMTP id ACD076AEA4 for ; Mon, 17 Jul 2017 18:19:01 +0000 (UTC) (envelope-from brahmann@lifec0re.net) Received: from [176.36.220.213] (helo=vortexSS) by mx.lifec0re.net with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89 (FreeBSD)) (envelope-from ) id 1dX9xe-000Ph1-Or for freebsd-net@freebsd.org; Mon, 17 Jul 2017 20:37:34 +0300 Date: Mon, 17 Jul 2017 20:37:34 +0300 In-Reply-To: <596CF4FB.9070306@grosbein.net> References: <20170717172642.GF39925@home.opsec.eu> <596CF4FB.9070306@grosbein.net> MIME-Version: 1.0 Subject: Re: A web server behind two gateways? To: freebsd-net@freebsd.org From: brahmann Message-ID: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Jul 2017 18:19:03 -0000 Hi, you can use(if itsobe server with two uplinks) ipfw probe 0,5, two sep= arate flows for two fibs, with some two flowfib script=2E=20 I did that once and work like a charm=2E=20 Wbr, brahmann 17 =D0=BB=D0=B8=D0=BF=D0=BD=D1=8F 2017 =D1=80=2E 20:33:47 GMT+03:00, Eugen= e Grosbein =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0= =B2: >18=2E07=2E2017 0:26, Kurt Jaeger wrote: > >> I have a vague idea: >>=20 >> If you set a tag (or a keep-state :flowname) using a ipfw rule that >matches >> the incoming gateway MAC and match that tag/check-state flowname and >> the connection (keep-state) to fwd the answer packet back to that >gateway ? > >In fact, the NAT engine already keeps state track of packet flows >and uses that to correctly translate answers back to public IP address=2E > >All you need is to forward translated outgoing answers to correct >channel >based on translated external source IP address (read: do policy based >forwarding)=2E > > >_______________________________________________ >freebsd-net@freebsd=2Eorg mailing list >https://lists=2Efreebsd=2Eorg/mailman/listinfo/freebsd-net >To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd=2Eorg" > > >!DSPAM:596cf513971106642921193! --=20 =D0=92=D1=96=D0=B4=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=BE =D0=B7 = =D0=BC=D0=BE=D0=B3=D0=BE Android =D0=BF=D1=80=D0=B8=D1=81=D1=82=D1=80=D0=BE= =D1=8E =D0=B7 K-9 Mail=2E =D0=92=D0=B8=D0=B1=D0=B0=D1=87=D1=82=D0=B5 =D0=B7= =D0=B0 =D1=81=D1=82=D0=B8=D1=81=D0=BB=D1=96=D1=81=D1=82=D1=8C=2E From owner-freebsd-net@freebsd.org Mon Jul 17 18:19:19 2017 Return-Path: Delivered-To: freebsd-net@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E6465D9CE31; Mon, 17 Jul 2017 18:19:19 +0000 (UTC) (envelope-from eugen@grosbein.net) Received: from hz.grosbein.net (hz.grosbein.net [78.47.246.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "hz.grosbein.net", Issuer "hz.grosbein.net" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 7BE706AF37; Mon, 17 Jul 2017 18:19:18 +0000 (UTC) (envelope-from eugen@grosbein.net) Received: from eg.sd.rdtc.ru (root@eg.sd.rdtc.ru [62.231.161.221]) by hz.grosbein.net (8.15.2/8.15.2) with ESMTPS id v6HIJ9XR080790 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Jul 2017 20:19:10 +0200 (CEST) (envelope-from eugen@grosbein.net) X-Envelope-From: eugen@grosbein.net X-Envelope-To: asomers@freebsd.org Received: from [10.58.0.4] ([10.58.0.4]) by eg.sd.rdtc.ru (8.15.2/8.15.2) with ESMTPS id v6HIJ56N073335 (version=TLSv1.2 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT); Tue, 18 Jul 2017 01:19:05 +0700 (+07) (envelope-from eugen@grosbein.net) Subject: Re: A web server behind two gateways? To: Alan Somers References: <596CA093.6020508@grosbein.net> <596CF1BA.8050104@grosbein.net> Cc: FreeBSD Net , freebsd-jail@freebsd.org, Grzegorz Junka From: Eugene Grosbein Message-ID: <596CFF94.2090506@grosbein.net> Date: Tue, 18 Jul 2017 01:19:00 +0700 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.3 required=5.0 tests=BAYES_00,LOCAL_FROM autolearn=no autolearn_force=no version=3.4.1 X-Spam-Report: * -2.3 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * 2.6 LOCAL_FROM From my domains X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on hz.grosbein.net X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Jul 2017 18:19:20 -0000 18.07.2017 0:48, Alan Somers wrote: > I think what you meant to say is "this will work for a server directly > connected to two external gateways (whether or not NAT is involved), > but won't work if the server is not on the same subnet as the > gateways". That's true. But judging by the OP, I think they're all > on the same subnet. Yes. Anyway, as long as there is NAT involved, one already has stateful engine and simpliest and universal solution for this situation is PBR after NAT for outgoing packets. It works no matter whether gateways are directly connecter or not and does not require multiple routing tables nor complex FIB or VNET configurations: # remove "default" NAT rule ipfw delete 50 # translate incoming traffic and create NAT states ipfw add 40 nat 123 ip from any to any in recv $iface1 ipfw add 50 nat 124 ip from any to any in recv $iface2 # insert normal filtering here ... # translate outgoing replies using existing NAT states ipfw add 50020 nat global ip from $LAN to any out xmit $iface1 ipfw add 50030 nat global ip from $LAN to any out xmit $iface2 # translate new outgoing connections not having a state yet ipfw add 50040 nat 123 ip from any to any out xmit $iface1 ipfw add 50050 nat 124 ip from any to any out xmit $iface2 # perform Policy Based Routing for packets going to "wrong" route ipfw add 50140 fwd $gateway2 ip from $extip2 to any out xmit $iface1 ipfw add 50150 fwd $gateway1 ip from $extip1 to any out xmit $iface2 # that's all, folks! This works no matter where default route points to ($gateway1 or $gateway2). All you need is working default route and net.inet.ip.fw.one_pass=0. This can be extended to any number of external channels/interfaces and optimized with ipfw tables but for two channels I prefer write it so for readability. I use this for many installations and it just works.