[systemd-devel] getaddrinfo() API with systemd

Lennart Poettering lennart at poettering.net
Mon Apr 27 07:35:04 PDT 2015


On Sat, 25.04.15 11:05, Nanda Kumar (nandakumar.nie at gmail.com) wrote:

> Hi,
> 
> I am facing problem while querying DNS using getaddrinfo() API under a
> process initiated by systemd. Despite having nameserver entry in
> /etc/resolv.conf, the query fails to resolve. After few system call traces,
> it is found that the problem is due to systemd resolution. It seems like,
> for a process inited by systemd, the getaddrinfo() DNS query routed via
> systemd while in stand alone mode (i.e. spawned by shell), the query
> happens normally. I changed the /etc/systemd/resolved.conf to add my DNS
> address and restarted systemd-resolved. Now the DNS query works properly.
> 
> Is there anyway to bypass systemd for getaddrinfo() [ex: passing extra
> flags to hints], and get the work done in usual way?

Well, if you don#t want to use resolved, then remove it from /etc/nsswitch.conf.

> In my case /etc/resolv.conf is softlink to runtime resolved.conf of
> systemd. Will unlinking and keeping the /etc/resolv.conf independent will
> solve the solution?

The way this works is this: resolved always writes out information
about all DNS servers it learnt to
/run/systemd/resolve/resolv.conf. If your /etc/resolv.conf points to
that file, then any app that bypasses NSS but reads that file will use
the same DNS servers as resolved, but talk directly to them. If
/etc/resolv.conf does not point there, then resolved will notice and
actually use it as source of configuration to learn addition DNS
servers from.

In essence, if you use networkd for all your networking configuration,
then making /etc/resolv.conf a symlink to
/run/systemd/resolve/resolv.conf is the right thing. If you use
something else, then not.

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list