Hacker News new | ask | show | jobs
by ubercow13 2541 days ago
At least on Linux, isn't DNS all at the application level anyway? There is no system level DNS lookup
2 comments

> At least on Linux, isn't DNS all at the application level anyway? There is no system level DNS lookup

Nearly all applications use the standard library, i.e. getaddrinfo(3) or the old gethostbyname(3) or something that wraps them. Which itself uses the services configured in /etc/nsswitch.conf, one of which is DNS which will in turn query the DNS server(s) configured in /etc/resolv.conf.

You can also have other services configured in nsswitch.conf like "mdns" (multicast DNS for names of devices on the LAN) and "files" for /etc/hosts, or any other name resolution system. The general result is that you can change the settings for the whole system and even add completely new name resolution services (like, for example, DoH) and have substantially everything automatically use them.

What do you mean?

https://linux.die.net/man/3/gethostbyaddr

It is one of the worst thing that can happen if this functionality moves into the application layer.

What the parent poster means is that each application does its own DNS lookup separately and independently. The family of functions you linked to, plus the newer getaddrinfo family of functions, is implemented in the C library within each process, not as a system call or as a separate daemon. These functions read the /etc/nsswitch.conf file, load the C library plugins listed there, and call each one in sequence - still within the same process. The most common setting is a variation of "hosts: files dns", which first reads /etc/hosts, then reads /etc/resolv.conf and connects directly to the DNS servers listed there, without using any system level "DNS lookup" daemon (unless you have nscd enabled).
That's in libc. I guess that's below the application later, but doesn't some code elect to not use that, like go programs? I might be mistaken
At least on linux, go's native resolver follows a sane subset of glibc conventions like parsing /etc/nsswitch.conf, /etc/resolv.conf, /etc/hosts [1]. As long as your dns configuration is defined there, you won't notice much of a difference between go programs using go's resolver and programs making glibc library calls for dns stuff.

1: https://jrl.ninja/etc/2/strace-go-1.12.3.txt

src for above: https://jrl.ninja/etc/2/getaddrinfo.go.txt