[Mildly OT] Userland Control Of getbostbyname()
matthew at FreeBSD.org
Fri Sep 30 14:15:33 UTC 2016
On 09/30/16 14:47, Tim Daneliuk wrote:
> Is it possible to control *which* DNS server (and port) a userland program
> queries for DNS resolution when doing gethosbyname() and gethostbyip()
> calls? dig and nslookup seem capable of defining the DNS server to query,
> but I don't know if they're doing the call directly or via the gethostby...
> In a perfect world, I'd get a solution to this that was language agnostic -
> a way to tell my userland programs - in C, Java, Python, perl, go ...
> always use this server:port when doing name resolution.
Server, yes but not port, and only globally -- by editing /etc/resolv.conf
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 at 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 801 bytes
Desc: OpenPGP digital signature
More information about the freebsd-questions