Modern hostname lookups in Linux


Finding the IP-address for a host is not as simple as it used to be when lookups was just done via the /etc/hosts file and querying  name-servers listed in /etc/resolv.conf. Nowadays the nsswitch library and the module is talking to systemd-resolved daemon via the system DBus bus. Its has become quite hard to follow and find any problems.

This "nss-resolve"-module then communicates with the systemd-resolved daemon via DBus which in turn will use various ways of looking up a server.

The resolvconf program

Some systems use this program (package openresolv in debian) is responsible to track all possible resolvers in use. When interfaces are started by dhcp for instance, the dhcp scripts will add what ever DNS servers and tell resolvconf about it.

Resolvconf keeps a updated database of all information under /run/resolvconf. In the subdirectory interfaces, all DNS-information from interfaces are kept in a file per interface.

When running "resolvconf -u", resolvconf reads all this data and updates /etc/resolv.conf. 

It then talks to the system DBus and inform about the changes to 

You can watch dbus-communication happen with the command "dbus-monitor --system".


This system too maintains possible resolver sources. This also the process that listens to the address on many systems. Performing lookup and caching of lookups. The tool to communicat with this services is the command resolvectl. You can for instance flush all caches by running "recolvectl flush-caches"

Sources for resolv.conf

The file /etc/resolv.conf is normally just a symbolink link to the file /run/systemd/resolved/resolve.conf

Some debugging tricks

This is a simple test to talk directly to the systemd-resolved sending a simple query via dbus-send:

dbus-send --system --dest=org.freedesktop.resolve1 --type=method_call --print-reply /org/freedesktop/resolve1 org.freedesktop.resolve1.Manager.ResolveHostname int32:0 int32:0 uint64:0

Tricks and Tips

Some DBus tricks:

Listen all connections to the system dbus:

dbus-send --system --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListNames

Returns a list of names

dbus-send --system --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetConnectionUnixProcessID string::1.4

Get PID for owner of a name