What is the difference between resolvconf, systemd-resolve, and avahi?
When you run a command such as ping foobar
the system needs to work out how to convert foobar
to an ip address.
Typically the first place it looks is /etc/nsswitch.conf
.
This might have a line such as:
hosts: files dns mdns4
This tells the lookup routine to first look in "files", which is /etc/hosts
. If that doesn't find a match then it will then try to do a DNS lookup. And if we still don't know the answer then it'll try to do a mDNS lookup.
The DNS lookup is where the system then looks at /etc/resolv.conf
. This tells it what DNS servers to look at. On my machines I have this auto-configured by DHCP.
% cat /etc/resolv.conf
# Generated by NetworkManager
search mydomain
nameserver 10.0.0.1
nameserver 10.0.0.10
How resolv.conf
is built can change, depending on the operating system, what optional components you got, other configuration entries, boot sequence... In your case, on Ubuntu, you're running the systemd programs that configure this file to point to your local systemd-resolved
and that will know how to talk to the real DNS servers.
On my primary servers, which have static IP addresses and no systemd-resolved
, I manually edit this file.
Finally mdns4
tells the routines to try asking avahi-daemon
if it knows the name.
You can change the rules. eg if /etc/nsswitch.conf
just said:
hosts: files
then only the local /etc/hosts
file is used.
Other entries are possible; eg ldap
would make it do an LDAP lookup.
Toshi Taperek
Updated on September 18, 2022Comments
-
Toshi Taperek over 1 year
I'm currently working on a project that has required some DNS troubleshooting, however I am fairly new to the wonderful world of networking and am at a bit of a loss as to where to begin. My specific problem probably belongs on the RaspberryPi StackExchange, so I'll avoid crossposting. Just looking for information here.
Looking for information, I was lead to the
resolv.conf(5)
file,resolvconf(8)
,systemd-resolve(1)
, and the beast thatavahi
appears to be.My Raspi with Raspbian Buster appears to have
avahi-daemon
running. My Ubuntu 18.04.4 LTS hassystemd-resolved
ANDavahi-daemon
. Doesresolvconf(8)
(man page only on Ubuntu) coordinate the two? When is/etc/resolv.conf
used/ignored?On Ubuntu:
$ cat /etc/resolv.conf # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN # 127.0.0.53 is the systemd-resolved stub resolver. # run "systemd-resolve --status" to see details about the actual nameservers. nameserver 127.0.0.53 search telus
On Raspbian:
$ cat /etc/resolv.conf # Generated by resolvconf nameserver 192.168.0.1 nameserver 8.8.8.8 nameserver fd51:42f8:caae:d92e::1
Which utilities are responsible for this? I don't really understand enough jargon to sift through the man pages and differentiate all these, and I'd love an explanation of how their roles are related.
-
Johan Myréen almost 4 yearsThe
/etc/resolv.conf
file is just an implementation detail, it is not as essential as this answer implies. The definitive mechanism for applications to do name resolution is via library functions. These functions can make use ofresolv.conf
or they may not. Depending on how it is configured, systemd-resolved can make use of an existingresolv.conf
provided by e.g. resolvconf(8), or it can optionally provide/etc/resolv.conf
via a symlink to a systemd-resolved maintained version of the file. See freedesktop.org/software/systemd/man/… -
Stephen Harris almost 4 yearsEverything is "implementation detail" if you go deep enough. For example,
nsswitch.conf
is a libc feature and alternate libc libraries need follow this. I described how glibc and the attendent NSS libraries work. Ubuntu and Debian, out of box, do as I describe.