From owner-freebsd-net@freebsd.org Mon Jul 8 17:17:57 2019 Return-Path: Delivered-To: freebsd-net@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 74B9215E3F3A for ; Mon, 8 Jul 2019 17:17:57 +0000 (UTC) (envelope-from kudzu@tenebras.com) Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 7CFFE808AD for ; Mon, 8 Jul 2019 17:17:56 +0000 (UTC) (envelope-from kudzu@tenebras.com) Received: by mail-qk1-x72f.google.com with SMTP id 201so11755319qkm.9 for ; Mon, 08 Jul 2019 10:17:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tenebras-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=2JZhuUPBKCxsnqF7GlNHjbtRZrgDX/IeAOx7MWIawVQ=; b=Ml6O/xUYhC0OHhCcVfdIPV9WXgEEJ/UFkYl8GRCFEoTmM0GpZRNHAk9fFi4r1lZiAz ioKAYmUQPC8Qo8U8wvOFC1mi2fgj/UF7gzCv0gJkGkFKEYzCvlJ64PBLazawIj6MtMOA rvdaM94FUtPVV4KnkC/YMaDf5ne1qj7er1EzboDiwIvzwnz+uBUyQxDVS3bOAZfn94Op 5lZ4+QalMThn++za4EvQB0WG9kK9d4wOmkc3o1y0uvaakI2o1EM5log93AYYBhZR+iRT uT8oM/SQstFT4NJNt7vHwV2J6joEFh6UWP/JKi9dbQkGWT7FelkdVMQIsuw9ZTh8I2JJ Sq9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=2JZhuUPBKCxsnqF7GlNHjbtRZrgDX/IeAOx7MWIawVQ=; b=Slz3R1I/eQb0lgw13jpdUSWXk0KbDm4OP1QIyk2AxJ3GB5YJjobbppTVV8iB4+GGkm K8qQzzia69rP1LJ/YGlDSp3KIwtHQ6T49G4ZR3i0ip5UHPOb09PqLab5ujbHrD5i4C4i UUw6CWoLGizd/yRFv0pxwg+YcgIl43bOkVafO7jELWU4Q3zHdfWkleYYiPrGRNEYpWTz vFne/uLO9Aq6N4ELpXnOC9VdB670GZjNyMrG/N/iXS8uAwT8MOUJxJJBVdbTB/U33bP/ XYNEzB4fTun0Lq/BA1LM1qaTCaUW67u7FJwqHYnBHL98qJaltXxt7CykaP9vcjcne5lV yCew== X-Gm-Message-State: APjAAAXtWzFFV56GlEQZVAzDbw/ZnXB6YWbcD7Iyk9rqg/QDb1Tr4aGE gSgFu+BM/ryLbuIxozy6TWk1t61QZG3vhDw43dZesdbPRkj1cA== X-Google-Smtp-Source: APXvYqy4vptQxggfRzGiQF2phFjV/9zdsariEuojDUZT6aHMqOg+Zy2uEem2wowKtSjIL6HsO3cAPuIz/VmLYc0Ktn8= X-Received: by 2002:a37:6085:: with SMTP id u127mr15492041qkb.25.1562606275388; Mon, 08 Jul 2019 10:17:55 -0700 (PDT) MIME-Version: 1.0 References: <8e388abc-f2ac-b070-cf86-a4d3971ac095@rawbw.com> In-Reply-To: <8e388abc-f2ac-b070-cf86-a4d3971ac095@rawbw.com> From: Michael Sierchio Date: Mon, 8 Jul 2019 10:17:19 -0700 Message-ID: Subject: Re: How to set up ipfw(8) NAT between an alias and the main IP address, when the alias is in another network? To: "freebsd-net@freebsd.org" X-Rspamd-Queue-Id: 7CFFE808AD X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=tenebras-com.20150623.gappssmtp.com header.s=20150623 header.b=Ml6O/xUY X-Spamd-Result: default: False [-3.18 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-0.99)[-0.992,0]; R_DKIM_ALLOW(-0.20)[tenebras-com.20150623.gappssmtp.com:s=20150623]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-net@freebsd.org]; DMARC_NA(0.00)[tenebras.com]; URI_COUNT_ODD(1.00)[3]; RCPT_COUNT_ONE(0.00)[1]; RCVD_TLS_LAST(0.00)[]; DKIM_TRACE(0.00)[tenebras-com.20150623.gappssmtp.com:+]; MX_GOOD(-0.01)[cached: alt1.aspmx.l.google.com]; RCVD_IN_DNSWL_NONE(0.00)[f.2.7.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org : 127.0.5.0]; HTTP_TO_IP(1.00)[]; TO_DN_EQ_ADDR_ALL(0.00)[]; R_SPF_NA(0.00)[]; NEURAL_HAM_SHORT(-0.85)[-0.852,0]; FROM_EQ_ENVFROM(0.00)[]; SUBJECT_ENDS_QUESTION(1.00)[]; MIME_TRACE(0.00)[0:+,1:+]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; RCVD_COUNT_TWO(0.00)[2]; IP_SCORE(-3.03)[ip: (-9.51), ipnet: 2607:f8b0::/32(-3.16), asn: 15169(-2.40), country: US(-0.06)] Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.29 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, 08 Jul 2019 17:17:57 -0000 NAT is already maintaining state =E2=80=93 it is possible to combine statef= ul rules and NAT, but don't. ;-) Are you really proposing to NAT twice, or is 192.168.1.2 a phony address for the purposes of discussion here? In any case, consider something like the following: #!/bin/sh fw=3D"/sbin/ipfw -q" sysctl net.inet.ip.fw.one_pass=3D0 IP_JAIL=3D"192.168.100.2" IP_EXIF=3D"192.168.1.2" OIF=3D"sk0" ###########################################################################= ##### # If 192.168.1.2 is really your interface address, you'll be nat'ing twice # on the way to the internet, which is ugly. You don't need the *unreg_only= * # directive if you only have RFC1918 addresses anyway. You should clarify # if this is the case. *reset* kills all active nat sessions if you run thi= s # script again. $fw flush $fw nat 1 config \ redirect_addr ${IP_EXIF} ${IP_JAIL} \ redirect_addr ${IP_JAIL} ${IP_EXIF} \ if ${OIF} unreg_only reset ###########################################################################= ##### # separate in and out as a matter of habit - don't mention protocol in nat # statement, do this in subsequent rules $fw add 01000 nat 1 ip from any to any in recv ${OIF} # check-state isn't needed, really, since it gets performed at the next # rule that mentions state #$#$#$#$# $fw add 01500 check-state # these will match traffic to/from external IP and not jail $fw add 02000 allow tcp from ${IP_EXIF} to any out setup keep-state $fw add 02010 allow udp from ${IP_EXIF} to any out keep-state $fw add 02020 allow icmp from ${IP_EXIF} to any out keep-state ###########################################################################= ##### # Why is this safe? because it will only match NAT return packets. # It only permits traffic to your jail in this case. Also, for TCP to # function properly, to need to accept ICMP error messages, esp. need-frag $fw add 02000 allow ip from any to ${IP_JAIL} ###########################################################################= ##### # outbound packets pass through nat $fw add 03000 nat 1 ip from any to any out xmit ${OIF} ###########################################################################= ##### # if your default rule (65535) is DENY, you need something like this. This will # match only NAT'd traffic $fw add 50000 allow ip from any to any out xmit ${OIF} On Sat, Jul 6, 2019 at 1:03 AM Yuri wrote: > My network interface looks like this: > > sk0: flags=3D8843 metric 0 mtu 15= 00 > options=3D80009 > ether 01:3c:47:8a:17:12 > inet 192.168.1.2 netmask 0xffffff00 broadcast 192.168.1.255 > inet 192.168.100.2 netmask 0xffffffff broadcast 192.168.100.2 > media: Ethernet autoselect (100baseTX ) > status: active > nd6 options=3D29 > > The second IP address is an alias that is used for jail. > > I would like to set up NAT so that this jail would access the internet > through the same interface. > > > I tried this script: > > > fw=3D"/sbin/ipfw -q" > > $fw nat 1 config redirect_addr 192.168.100.2 192.168.1.2 redirect_addr > 192.168.1.2 192.168.100.2 if sk0 unreg_only reset > > $fw add 1001 nat 1 tcp from 192.168.100.2/32 to any via sk0 keep-state > > $fw add 1002 check-state > > > The rule 1001 has keep-state, therefore it should process both outgoing > tcp and incoming response packets. But the outbound packets are NATted, > but the inbound ones are not. > > What is wrong, and how to fix this script? > > > Thank you, > > Yuri > > > _______________________________________________ > freebsd-net@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-net > To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org" > --=20 "Well," Brahm=C4=81 said, "even after ten thousand explanations, a fool is = no wiser, but an intelligent person requires only two thousand five hundred." - The Mah=C4=81bh=C4=81rata