From owner-freebsd-jail@freebsd.org Mon Jul 17 16:46:47 2017 Return-Path: Delivered-To: freebsd-jail@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 2AD0ED9A012; Mon, 17 Jul 2017 16:46:47 +0000 (UTC) (envelope-from asomers@gmail.com) Received: from mail-yw0-x229.google.com (mail-yw0-x229.google.com [IPv6:2607:f8b0:4002:c05::229]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id DC6B267025; Mon, 17 Jul 2017 16:46:46 +0000 (UTC) (envelope-from asomers@gmail.com) Received: by mail-yw0-x229.google.com with SMTP id a12so49800597ywh.3; Mon, 17 Jul 2017 09:46:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=JCgInFuJPuaFkiDTkhZKAVaHvfRRnIu4qtwqPxGVd9E=; b=ELlzURjAmunsi+CtyS27kLl6QqJXFWLMpapxDL2BPnrxll2iLAqgIcT/+mAnA+nOTf GgHPtTianMJGUr0gMt81LUDWlZU323gD50EAODybd69eJL1UKYBdaSXKoK51k9G0aZLd jzSdLCODJ6Q6Toj9tLtTfqVIzbQUNNAbwadOq18mEroc2J9iXTPTaUk11o7kkAjMZZDM uWPdWBe0trSCwG0lCX9IWQLpcCG/caYM0JyAVSHSFDt/oxyaeQcaj41Rm16kqIahJY6J 1iZrhZLj4y9oSG+TAnWjNUuEXmOisbe89xAn+ubn/ak6jcZQ/Yz0tveW9VSOO9/73/HI Kp1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=JCgInFuJPuaFkiDTkhZKAVaHvfRRnIu4qtwqPxGVd9E=; b=KJ/pY00BGIEZSmeyscP+rUL6AC91cfgv5yEvTiVBQ+TkG0X5HmDzVuEVT6v3UrJggK LKhd1xo2U4m06mVYZjRimvfTr3D3UFjnmPcmLUNE+3wlVN/uoij1sMlPpJy5JyTz0Gh+ rlhZh4z6xBBapiVZU2E891916nHSva840y7c9mCpjzwyzbghbhimA6ziDNF1RdkIt2FP R7G1yv2NQGGjAmkRqPqNq2P8PQwCJD1OwN3DaC75EzQsWVa3iXLsUTUdQvVrgW4NA2Oa vrUDSj8jYWdeieqvu4Um8bdlaZwswkspOy7+5PInFDi64oxEOTI+U66qzpdjI8x96oX3 Kxnw== X-Gm-Message-State: AIVw110OJjjskUcu7RdykTAuA2onFcbfNgpfmtmZZ9LHHZ90OAE4ErDn uO3bsY8MXB+P8Rr3bkhOFzVG8ay/Glge X-Received: by 10.129.101.213 with SMTP id z204mr16702484ywb.144.1500310005884; Mon, 17 Jul 2017 09:46:45 -0700 (PDT) MIME-Version: 1.0 Sender: asomers@gmail.com Received: by 10.13.243.135 with HTTP; Mon, 17 Jul 2017 09:46:45 -0700 (PDT) In-Reply-To: <596CA093.6020508@grosbein.net> References: <596CA093.6020508@grosbein.net> From: Alan Somers Date: Mon, 17 Jul 2017 10:46:45 -0600 X-Google-Sender-Auth: Bjhc47O_ZQ-8qRo9Af1H8JFRcp8 Message-ID: Subject: Re: A web server behind two gateways? To: Eugene Grosbein Cc: Grzegorz Junka , FreeBSD Net , freebsd-jail@freebsd.org Content-Type: text/plain; charset="UTF-8" X-BeenThere: freebsd-jail@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Discussion about FreeBSD jail\(8\)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Jul 2017 16:46:47 -0000 On Mon, Jul 17, 2017 at 5:33 AM, Eugene Grosbein wrote: > On 16.07.2017 19:48, Grzegorz Junka wrote: >> Hello, >> >> I have a jail running a web server in LAN. There are two routers/WANs >> that can connect LAN to the internet. I enabled NAT and port forwarding >> to the web server on both routers. >> >> The problem is that the web server responds to requests only from one >> router at a time depending on the default gateway set on the jail's >> host. If the default gateway is set as router 1 then the web page can be >> opened only through WAN1 and vice versa. >> >> Can I configure either router/host/jail so that the web server sends the >> response back to the IP that sent the request packet rather than to the >> default gateway? > > This is the job of external NAT box to route translated replys to right WAN > based on external source IP address produced during translation of the reply. > The jail or internal NAT have nothing to do with the problem. > > So, the solution depends of kind of NAT you use. That's not 100% true. The web server is choosing which gateway to use. As Grzegorz said, it's only configured to use a single gateway at a time. To do what Grzegorz wants, he'll need to use multiple fibs. Set "net.fibs=2" and "net.add_addr_allfibs=0" in /boot/loader.conf and reboot. You'll be able to configure a separate gateway for each fib. The hard part, though, is configuring your web server to use multiple fibs. I don't know if any common web server has that kind of support builtin. But your next guess was good. > >> And a bonus question, how can I configure two jails so that each jail >> sends packets to a different gateway (which may or may not be the same >> as the jails' host's default gateway)? > > Read "man jail" for "vnet" feature. This is definitely the path of least resistance. Basically, you'll assign each jail to a separate fib, so you'll still need the loader.conf settings I mentioned. Unfortunately, VNET/VIMAGE isn't in the standard kernel. If you're unable to run a custom kernel on this machine, you can still create two jails on separate fibs. The biggest downside compared to VNET/VIMAGE is that they'll share a single DNS resolver. Here's how to do it: * Make the loader.conf settings I mentioned earlier. * Create a separate static IP address for each jail, and associated each with a separate fib. Your rc.conf should contain something like this: ifconfig_igb1_alias0="inet 10.1.2.76/20 fib 0" ifconfig_igb1_alias1="inet 10.1.18.76/20 fib 1" * Add the default routes in /etc/rc.local like this: /sbin/route add default 10.1.0.1 -fib 0 /sbin/route add default 10.1.16.1 -fib 1 * Assign one address to one jail and the other address to the other jail * Ensure that in each jail, the web server starts with the correct fib. For example, if you're using apache24, I think you can put "apache24_fib=1" in /etc/rc.conf. Other web servers may require something different, depending on how their RC scripts are written. Happy hacking! -Alan