Linux Short Tip: systemd-networkd and DNS servers

You maybe have noticed that you can configure DNS servers in your systemd-networkd settings, but these addresses don’t appear in /etc/resolv.conf. You need to enable/start systemd-resolved, this daemon checks global DNS settings in /etc/systemd/resolved.conf, DNS settings for each link from systemd-networkd + DNS stuff that comes from a DHCP server and writes everything into /run/systemd/resolve/resolv.conf. You need to create a symlink to your /etc/systemd/resolved.conf, then everything works as expected:

root@ci ~ # systemctl enable systemd-resolved
Created symlink from /etc/systemd/system/multi-user.target.wants/systemd-resolved.service to /usr/lib/systemd/system/systemd-resolved.service.
root@ci ~ # systemctl start systemd-resolved
root@ci ~ # systemctl status systemd-resolved
● systemd-resolved.service - Network Name Resolution
Loaded: loaded (/usr/lib/systemd/system/systemd-resolved.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2016-05-13 13:48:31 CEST; 2s ago
Docs: man:systemd-resolved.service(8)
Main PID: 13897 (systemd-resolve)
Status: "Processing requests..."
Tasks: 1 (limit: 512)
CGroup: /system.slice/systemd-resolved.service
└─13897 /usr/lib/systemd/systemd-resolved

May 13 13:48:31 ci.virtapi.org systemd[1]: Starting Network Name Resolution...
May 13 13:48:31 ci.virtapi.org systemd-resolved[13897]: Positive Trust Anchors:
May 13 13:48:31 ci.virtapi.org systemd-resolved[13897]: . IN DS 19036 8 2 49aac11d7b6f6446702e54a1607371607a1a418552
May 13 13:48:31 ci.virtapi.org systemd-resolved[13897]: Negative trust anchors: 10.in-addr.arpa 16.172.in-addr.arpa 17.
May 13 13:48:31 ci.virtapi.org systemd-resolved[13897]: Using system hostname 'ci'.
May 13 13:48:31 ci.virtapi.org systemd-resolved[13897]: Switching to system DNS server 8.8.8.8.
May 13 13:48:31 ci.virtapi.org systemd[1]: Started Network Name Resolution.
root@ci ~ # cat /run/systemd/resolve/resolv.conf
# This file is managed by systemd-resolved(8). Do not edit.
#
# Third party programs must not access this file directly, but
# only through the symlink at /etc/resolv.conf. To manage
# resolv.conf(5) in a different way, replace the symlink by a
# static file or a different symlink.

nameserver 8.8.8.8
root@ci ~ # rm /etc/resolv.conf
root@ci ~ # ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
root@ci ~ #

This entry was posted in 30in30, General, Linux, Short Tips. Bookmark the permalink.

2 Responses to Linux Short Tip: systemd-networkd and DNS servers

  1. Osqui says:

    Hello
    Thanks a lot!! You saved me the day!!
    Do you know why this linkage isn’t done by default?? It’s a pity!!

  2. Thank you so much! I love your tips

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.