From owner-freebsd-questions@freebsd.org Fri Dec 7 22:07:23 2018 Return-Path: Delivered-To: freebsd-questions@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 4562A1321CF7 for ; Fri, 7 Dec 2018 22:07:23 +0000 (UTC) (envelope-from luzar722@gmail.com) Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 7DC177A045 for ; Fri, 7 Dec 2018 22:07:22 +0000 (UTC) (envelope-from luzar722@gmail.com) Received: by mail-io1-xd30.google.com with SMTP id r200so4443717iod.11 for ; Fri, 07 Dec 2018 14:07:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-transfer-encoding; bh=jW2r7VttK0mrU6UzfodD5/OJ486cES+seXcpMdciRRM=; b=PQX1urrYJEeDk/W2hG1dFUau1PzHv7Cuba/ZF1dyYDilpG/FwF4VVKT0WaOtJz6gF8 lraXMQafZtR5cSlo1+UgnRPKmu9CCCNEXlbLdijJSXMSxPP5RWypKKSPZaBFj3mL9YPM gS+mqIUHesB2xLZWzriOyKkzMXHC1Gpo6NgglF9TB6Bv5c7kh8Iki7CAZdlghnkxjUam yaUsIZat8zU5KSwFAzdDS8k12jE2CdJjD71kfY+KU46UwCa3YNYLP1TSMWMRqxm1eje+ Ra0dCpCjaK6d9wk45yz9bPvRIfUAg+nEG/lxUCKTr+KKgz0k8NgGmMS6+oabfDvwb1JS zd+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-transfer-encoding; bh=jW2r7VttK0mrU6UzfodD5/OJ486cES+seXcpMdciRRM=; b=Kc06g5qo3QNAL4b7eNYPGisUnvA3blTA10V86HltJB5UYZ61i334eQeK4PL6EdwvR0 ptZkcmQFsZRKmuKYOEDSknlgGxjfXFeJ1qIJJZf6fXiT9C/YXWlCXI9PDOU2X2+GHuY+ v5qpJ7KHNzx4yipFMz3I+qZO48l8nLbaurY9EKxmpT0h9G1Kt56rHuiPPHn86LXsL0tS KqpPQRirb6t30aj28ezbWeJxhdK9OTzTcS4sKUWbU/wQ+wFtRVV3c3YV/ID/2f4FESDi vIOk9HBp/cWO72V5MkJXXYzLf8AZKlQs3b9iWHTU3Le+zIN4465L5yATIBqDy3JygeP/ pidg== X-Gm-Message-State: AA+aEWbJzzt5sqOtL4xYhmgnVnb4oEgLflZHJ9TYkUxKmWM47/tmw3A4 h/NaSOCnU1yjxvACGz6RgnFeMpQE X-Google-Smtp-Source: AFSGD/UMQnQlrz8AwfcB82yDPuLjoHL23DoN4FHv2xLulgQgw0vng5/GG8j5SsDTkk6MmAa/QQ/D2g== X-Received: by 2002:a6b:8f42:: with SMTP id r63mr2994770iod.202.1544220441884; Fri, 07 Dec 2018 14:07:21 -0800 (PST) Received: from [10.0.10.7] (cpe-65-25-62-234.neo.res.rr.com. [65.25.62.234]) by smtp.googlemail.com with ESMTPSA id m132sm2547036itm.26.2018.12.07.14.07.20 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 07 Dec 2018 14:07:21 -0800 (PST) Message-ID: <5C0AEF17.7070100@gmail.com> Date: Fri, 07 Dec 2018 17:07:19 -0500 From: Ernie Luzar User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) MIME-Version: 1.0 To: Doug McIntyre CC: freebsd-questions@freebsd.org Subject: Re: sh code to determine if host is on lan References: <5C099F41.2020407@gmail.com> <5C09AB7B.4010001@gmail.com> <20181207011905.af7d5c29.freebsd@edvax.de> <5C09C491.1060803@gmail.com> <20181207195645.GA64030@geeks.org> In-Reply-To: <20181207195645.GA64030@geeks.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 7DC177A045 X-Spamd-Result: default: False [-4.34 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[gmail.com]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36]; FREEMAIL_FROM(0.00)[gmail.com]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-questions@freebsd.org]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; RCVD_COUNT_THREE(0.00)[3]; TO_MATCH_ENVRCPT_SOME(0.00)[]; MX_GOOD(-0.01)[cached: alt3.gmail-smtp-in.l.google.com]; DKIM_TRACE(0.00)[gmail.com:+]; RCPT_COUNT_TWO(0.00)[2]; RCVD_IN_DNSWL_NONE(0.00)[0.3.d.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]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; IP_SCORE(-0.58)[ipnet: 2607:f8b0::/32(-1.53), asn: 15169(-1.31), country: US(-0.09)]; NEURAL_HAM_SHORT(-0.74)[-0.742,0]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; MID_RHS_MATCH_FROM(0.00)[] X-Rspamd-Server: mx1.freebsd.org X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Dec 2018 22:07:23 -0000 Doug McIntyre wrote: > On Thu, Dec 06, 2018 at 07:53:37PM -0500, Ernie Luzar wrote: >> Polytropon wrote: >>> elOn Thu, 06 Dec 2018 16:06:35 -0700, JD wrote: >>>> On 12/06/2018 03:14 PM, Ernie Luzar wrote: >>>>> Hello list >>>>> >>>>> Know that "route -n get default" will give me the nic name of the >>>>> interface connected upstream. That "ifconfig nic" will give me the ip >>>>> address. That if that ip address is one of these ranges >>>>> 192.168/16 or 172.16/12 or 10/8 then the host is on a lan. > > Hmm, I thought my host here was on a LAN.. > > vmx0: flags=8843 metric 0 mtu 1500 > inet 216.250.176.100 netmask 0xffffffe0 broadcast 216.250.176.127 > inet6 2001:4980:2:dad::100 prefixlen 64 > > And this one too.. > bce0: flags=8843 metric 0 mtu 1500 > inet6 2001:4980:0:1000:21e:c9ff:feb5:663a prefixlen 64 autoconf > inet6 2001:4980:0:ffff:21e:c9ff:feb5:663a prefixlen 64 autoconf > > Are you sure your definition of "LAN" is the correct term? > > What is it you are trying to determine? > > > Like most ISPs my ISP doesn't provide ipv6 service. So not interested in it until it goes public nationwide. Your 216.250.176.100 ipv4 address is public routeable. Looks like this machine is running vm and the freebsd os is configured as the gateway to the public internet. If it has a LAN behind it using ipv4 addresses, then this gateway is also running a firewall with NAT so the LAN nodes can reach the public internet. I'm playing with 12.0-RC3 and vnet jails. Vnet jails come in two flavors based on the hosts network topography. The host is either the gateway or its a node on the lan. Lans use these reserved non-routeable ipv4 address ranges for network communication. If the host's default ip address is in the range covered by one of theses 192.168/16 or 172.16/12 or 10/8 ranges then the host is a node on a lan. That is what I am trying to determine in a sh script. I know that I can drill down through a few standard commands to capture the hosts external ipv4 address easy enough. But comparing it to the different ranges becomes a painful coding task. I think I just figured out the simple method I was looking for. Just issue the whois command using the captured hosts external ipv4 address and interrogate the reply for "Private Use". Thanks for every bodies replies.