Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 30 Sep 2016 15:15:10 +0100
From:      Matthew Seaman <matthew@FreeBSD.org>
To:        freebsd-questions@freebsd.org
Subject:   Re: [Mildly OT] Userland Control Of getbostbyname()
Message-ID:  <12a5cae8-8aa1-68a1-5130-a6813c07c972@freebsd.org>
In-Reply-To: <a0681443-0282-48ac-5884-6d1f3868787a@tundraware.com>
References:  <a0681443-0282-48ac-5884-6d1f3868787a@tundraware.com>

next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
--7kwUWgPfhV0ov6NUpRpVhgn31sJOVL6DM
Content-Type: multipart/mixed; boundary="cDgsL2QcrhpCCseSGkvEX921DvxmUjX7f";
 protected-headers="v1"
From: Matthew Seaman <matthew@freebsd.org>
To: freebsd-questions@freebsd.org
Message-ID: <12a5cae8-8aa1-68a1-5130-a6813c07c972@freebsd.org>
Subject: Re: [Mildly OT] Userland Control Of getbostbyname()
References: <a0681443-0282-48ac-5884-6d1f3868787a@tundraware.com>
In-Reply-To: <a0681443-0282-48ac-5884-6d1f3868787a@tundraware.com>

--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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?12a5cae8-8aa1-68a1-5130-a6813c07c972>