From owner-freebsd-questions@freebsd.org Fri Sep 30 14:15:33 2016 Return-Path: Delivered-To: freebsd-questions@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 D6004C03016 for ; Fri, 30 Sep 2016 14:15:33 +0000 (UTC) (envelope-from matthew@FreeBSD.org) Received: from smtp.infracaninophile.co.uk (smtp.infracaninophile.co.uk [81.2.117.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "smtp.infracaninophile.co.uk", Issuer "infracaninophile.co.uk" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 6A06C310 for ; Fri, 30 Sep 2016 14:15:33 +0000 (UTC) (envelope-from matthew@FreeBSD.org) Received: from ox-dell39.ox.adestra.com (unknown [85.199.232.226]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: m.seaman@infracaninophile.co.uk) by smtp.infracaninophile.co.uk (Postfix) with ESMTPSA id 8458E57D1 for ; Fri, 30 Sep 2016 14:15:23 +0000 (UTC) Authentication-Results: smtp.infracaninophile.co.uk; dmarc=none header.from=FreeBSD.org Authentication-Results: smtp.infracaninophile.co.uk/8458E57D1; dkim=none; dkim-atps=neutral Subject: Re: [Mildly OT] Userland Control Of getbostbyname() To: freebsd-questions@freebsd.org References: From: Matthew Seaman Message-ID: <12a5cae8-8aa1-68a1-5130-a6813c07c972@freebsd.org> Date: Fri, 30 Sep 2016 15:15:10 +0100 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="7kwUWgPfhV0ov6NUpRpVhgn31sJOVL6DM" X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00,RDNS_NONE, SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on smtp.infracaninophile.co.uk X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Sep 2016 14:15:33 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --7kwUWgPfhV0ov6NUpRpVhgn31sJOVL6DM Content-Type: multipart/mixed; boundary="cDgsL2QcrhpCCseSGkvEX921DvxmUjX7f"; protected-headers="v1" From: Matthew Seaman To: freebsd-questions@freebsd.org Message-ID: <12a5cae8-8aa1-68a1-5130-a6813c07c972@freebsd.org> Subject: Re: [Mildly OT] Userland Control Of getbostbyname() References: In-Reply-To: --cDgsL2QcrhpCCseSGkvEX921DvxmUjX7f Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 09/30/16 14:47, Tim Daneliuk wrote: > Is it possible to control *which* DNS server (and port) a userland prog= ram > queries for DNS resolution when doing gethosbyname() and gethostbyip() > calls? dig and nslookup seem capable of defining the DNS server to que= ry, > but I don't know if they're doing the call directly or via the gethostb= y... > calls. >=20 > In a perfect world, I'd get a solution to this that was language agnost= ic - > a way to tell my userland programs - in C, Java, Python, perl, go ...=20 > always use this server:port when doing name resolution. Server, yes but not port, and only globally -- by editing /etc/resolv.con= f However, if you're running with the standard local_unbound enabled, then you can specify a forward-addr including a port in /var/unbound/forward.conf like so: forward-addr: 192.0.2.1@1053 Note: this is an all or nothing solution, although it does fulfil your criterion of being language agnostic. Every application will get directed to your alternative DNS server+port, not just some chosen one. You can override the resolvers per application if you're willing to code that per application. Of course the API used is language specific, and you can't use gethostbyname(3) and that ilk, (which can do lookups from many sources other than the DNS) but only by doing DNS lookups directly from your code. Cheers, Matthew --cDgsL2QcrhpCCseSGkvEX921DvxmUjX7f-- --7kwUWgPfhV0ov6NUpRpVhgn31sJOVL6DM Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQIcBAEBCgAGBQJX7nNuAAoJEABRPxDgqeTnDt8P/1Plxyj7jYhUGEe4ihsYi+CL 0c442ltrfY4IZgNoN939ZaWRzRtavJSri5doXXBnoxX/2HLWHSiv35jS/lT39tXN iKIrsjjhDgEMhGWz4PMcb6VvRlWqvBkUMZWCMrL9XCPk9UjM5qpE1hugrIQKKBzT ILIIpF3xl4Rfv6C3YAQu3hhCKP4+xHwStlbDOiN1sSX8LnfIoufF18a7MMlf/7I3 YipoWRpx/xjdRqnKxDWYFFq1fNUKpUlk8ruCdlICyktYMaE0WSOgPseJ3atu4Xue 33/pHUN9ptZ4CJsKZPR9vAU+adGJ8rHkdSRs9bweQJUlTbMVJExGsjhexnUaAKSw zZFSUVYV34K5WCtlhfkE6ODXwZcPf0Piz683xlQPCniKPlaabUL9HozjK9/cEnDd 8t0PoVYiyOpjakIhMIHCMl7qcfLecy0VhMiT6XuBSbX9pCRfk/SgNcW1KWO6lB3C OVjzBj/Sa4WyOSwXx45cynaztlxQRfqX6bWLbXQtEVCyAxl+y9usC7GAW1cXQMA5 /fGsPNALrrHR+pyC9aJ+JzCVAxaKhDIyJ2Xib//H7TvZ7escxc2JGTvS5sIO4KuM dgMMMswZHcCiojUx5IQ8P85NV1brcCVVGNU94NO+Qfvsgl0Tmcke1Ll7WWo10jSl bsmHPAF7co39oh0ZqRsh =CTAZ -----END PGP SIGNATURE----- --7kwUWgPfhV0ov6NUpRpVhgn31sJOVL6DM--