Dns and hosts file

We have the Dns module which is great, but just implements the network layer. Is there a suggested solution for how to implement full DNS lookups that use the hosts file?

No (well, not that I’m aware of) – so the dns_client (unix and lwt) read /etc/resolv.conf to figure out the name servers configured on your system (though search and domain are not respected in resolv.conf).

But indeed, on Unix[tm] computers it is slightly more complicated, with the existence of /etc/nsswitch.conf, and /etc/hosts (well, plus nis etc. – but I guess hardly anyone cares about it).

For your usecase, I suspect a parser of /etc/hosts is necessary, and then using that. Since the format looks rather simple, that should be straightforward to add.

A long time ago, I had to dabble down there with nsswitch.conf. It’s all based on C libraries, and … I think it’s probably not so wise to dig around down there. Best thing is to use the libc(3) entrypoints. B/c the entire point of the thing, is a pluggable structure for configuring lookup of various things, e.g. hosts, users, groups, other stuff. If you implement your own structure for this, just for hosts, then when somebody installs your software on a machine that uses nsswitch.conf in a way you hadn’t predicted or supported, your software will work differently than libresolv, right?

Yes, I think that’s what I might do. I don’t need it yet so I have time to consider it. Thank you.

Yes, there are trade-offs. But it’s also not free, as I have to push the work into a thread when using the system libraries. I do have control over the environment I’m going to run in, so it might be fine. I need to think about it more.