My DNS server is

This DNS is provided to clients by DHCP. The windows clients on my LAN resolve names properly using that DNS, but my Ubuntu VM doesn't.

The VM is set up with bridge networking and is being properly provided the DNS server, but my local hostnames aren't being resolved by nslookup or browsers.

Here is an nslookup of one of my local domains:

# nslookup unraid.local

** server can't find unraid.local: SERVFAIL

Here is what it should resolve by using my DNS server:

# nslookup unraid.local

Name:   unraid.local

/etc/resolv.conf has a wrong nameserver:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.


I ran that command. Under DNS Servers, confusingly, it specifies the correct server (and my default gateway).

root@ubuntu:~# systemd-resolve --status
          DNSSEC NTA: 10.in-addr.arpa

Link 2 (ens33)
      Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6
       LLMNR setting: yes
MulticastDNS setting: no
      DNSSEC setting: no
    DNSSEC supported: no
         DNS Servers:

I don't want to "hard code" the DNS server's IP in a config file because I won't be able to resolve when I change networks.

How can I get resolvconf and NetworkManager to automatically set the DHCP server's IP in /etc/resolv.conf?

13 Answers 13


Known systemd bug.

Temporary workaround with no need to reconfigure if the DNS IP's changes:

sudo rm -f /etc/resolv.conf
sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
  • 2
    This solution worked somewhat, host and nslookup commands resolve names properly, but wget and browsers are not
    – FireSpore
    Commented Nov 11, 2017 at 5:39
  • 2
    this is correct ...the current bug is that the link to /etc/resolv.conf comes from /run/systemd/resolve/stub-resolv.conf which is bollox it should be /run/systemd/resolve/resolv.conf note that /etc/resolv.conf doesn't really exist in either case
    – Mr Heelis
    Commented Apr 29, 2019 at 22:37
  • @FireSpore: does ping work then? host and nslookup resolve host names differently from ping or wget. You may need to look into /etc/nsswitch.conf for a solutioin.
    – HongboZhu
    Commented Jun 24, 2019 at 12:21
  • 2
    Instead of reboot it worked for me to do service systemd-resolved restart && sudo systemctl restart networking
    – Ben Mares
    Commented Jan 13, 2020 at 16:59
  • It worked for me even without reboot
    – Afshin
    Commented Jan 7, 2021 at 6:27

Try editing /etc/systemd/resolved.conf, adding your desired DNS server:

change this:


to this (but use the one you want - this is an example):


after that, restart the service:

service systemd-resolved restart

And when you check the status you should see

$ systemd-resolve --status
         DNS Servers:

      DNSSEC NTA: 10.in-addr.arpa
  • Here is the systemd-resolve --status after changing /etc/systemd/resolved.conf pastebin.com/AeUFQkyB Browsers still fail to resolve names also.
    – FireSpore
    Commented Nov 4, 2017 at 22:10
  • 23
    systemd is so broken. DHCP tells the host what DNS should be, (and a bunch of other network settings) you should not have to change any files on the host for this to work.
    – teknopaul
    Commented Nov 8, 2017 at 22:55
  • 5
    Does not look optimal, you will have to do this every time you change DNS server/network
    – Victor
    Commented Feb 14, 2018 at 21:23
  • 4
    You would need to reconfigure every time the DNS IP's changes (for instance on different networks).
    – Victor
    Commented Feb 14, 2018 at 23:40

I finally got a solution for this problem for ubuntu 17.10. By default this version of Ubuntu uses systemd-resolved, which I hope is going to be stable for the next versions.

In order to use custom dns instead of the local systemd-resolved cache, do the following:

  1. add new nameservers. Edit the file in /etc/systemd/resolved.conf as sudoer. Here I've commented out the DNS entry and placed my dns [Resolve] DNS=

  2. cancel the actual symlink to /etc/resolv.conf

  3. create a new symlink sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
  4. restart the service sudo service systemd-resolved restart
  5. restart the network manager sudo systemctl restart networking

And now if you dig to a name provided by your add dns, you should see the record resolved dig nexus.default.svc.cluster.mydomain

Last step is to update the order of resolution in /etc/nsswitch.conf, by placing the dns before the mdns4_minimal

hosts           files dns mdns4_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] myhostname
  • 1
    You would need to reconfigure every time the DNS IP's changes (for instance on different networks).
    – Victor
    Commented Feb 14, 2018 at 23:39
  • Victor do you have a best solution? this is the same if you use static net config Commented Feb 16, 2018 at 15:19
  • This answer works for both static and dynamic configurations: askubuntu.com/a/974482/343617
    – Victor
    Commented Feb 16, 2018 at 15:41
  • thank you, the solution I have pointed out was static. I agree Commented Feb 18, 2018 at 11:39
  • This just worked for me on a new 18.04 install
    – JamesCW
    Commented Apr 30, 2019 at 13:56

Your /etc/resolv.conf is not the problem. systemd-resolved just defaults to unconfigured, so it fails all lookups. Feel free to rant about Unconfigured vs A Reasonable Default.

Manually add nameservers to systemd-resolved. (editing per Olorin's comment below to add mkdir, correct path /etc not /lib, in order to survive system updates)

sudo mkdir -p /etc/systemd/resolved.conf.d
sudo nano /etc/systemd/resolved.conf.d/00-my-dns-server-is.conf




sudo systemctl daemon-reload

systemd-resolved is smart, but, unconfigured as it is, by package maintainers, it just LOOKS stupid because package maintainers do not believe in A Reasonable Default. We can put 13 internet root servers in there aka "djb way", or 10 opennic servers: https://pastebin.com/JBfYVVtG or the three fastest opennic servers, as measured by namebench. Plus ISP nameservers, sure. Plus Google, sure. systemd-resolved is not the problem. I am the problem.

  • 1
    Though you probably don't want to edit a file /usr/lib - those will likely be overwritten on package upgrade. I think a corresponding file somewhere in /etc/systemd is the way to go (it already should have an /etc/systemd/resolved.conf ready to be edited by admins).
    – Olorin
    Commented Jan 23, 2019 at 4:16
  • 1
    man resolved.conf.d, with the d, yes /etc/systemd/resolved.d is the place. I'm noticing that we often have to mkdir /etc/[path].d. bob@laptop l /etc/systemd/resolved.conf.d ls: cannot access '/etc/systemd/resolved.conf.d': No such file or directory
    – BobDodds
    Commented Jan 23, 2019 at 4:20
  • This looked very promising but my system is still using /etc/resolv.conf (/run/systemd/resolve/stub-resolv.conf). I tried /etc/systemd/resolved.conf.d and /etc/systemd/resolved.d my /etc/systemd/resolved.conf is also configured with the correct DNS server but i nothing is updating /run/systemd/resolve/stub-resolv.conf and it seems this is the only file being used. (i also set in netplan yaml file dhcp4-overrides: use-dns: no for now I will need to symlink /etc/resolv.conf to /run/systemd/resolve/resolv.conf. Not sure if i missed anything but would really like a proper solution.
    – Sruli
    Commented Nov 30, 2020 at 13:29

On my system I found a bad symlink: /etc/resolv.conf was a symlink which points to /run/systemd/resolve/stub-resolv.conf

This file contains only one line:


As a result, the local network's DNS lookup was often missing.

So, instead I changed /etc/reolv.conf to point to /run/systemd/resolve/resolv.conf

and now works correctly.


I put together a script that works around the issue of Netplan not currently supporting the ability to supersede DHCP supplied DNS servers and domain search order. It creates the Netplan yaml file and configures systemd-resolved to work as expected.

################## Start Netplan config (renderer: NetworkManager)
#  Some useful commands for customisation
# NetConn=$(nmcli device show|grep GENERAL.CONNECTION|head -n1|awk '{print $2}')
# IP=$(nmcli device show|grep IP4.ADDRESS|head -n1|awk '{print $2}')
# GATEWAY=$(nmcli device show|grep IP4.GATEWAY|head -n1|awk '{print $2}')
# sed -i 's/renderer: networkd/renderer: NetworkManager/' //etc/netplan/01-netcfg.yaml
systemctl start NetworkManager
NIC=$(nmcli device show|grep GENERAL.DEVICE|head -n1|awk '{print $2}')

#####   create Netplan yaml config file
cat >/etc/netplan/01-netcfg.yaml <<EOF 
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
   version: 2
   renderer: NetworkManager
echo "    ${NIC}:" >> /etc/netplan/01-netcfg.yaml
cat >>/etc/netplan/01-netcfg.yaml <<EOF
      dhcp4: yes
        search: [abc.domain.edu, def.domain.edu]
        addresses: [,]


#work around DNS resolv bug
systemctl stop systemd-resolved
sed -i 's/#DNS=/DNS=' /etc/systemd/resolved.conf
sed -i 's/#Domains=/Domains=abc.domain.edu def.domain.edu' /etc/systemd/resolved.conf
systemctl start systemd-resolved
systemctl restart NetworkManager
netplan apply
############### End Netplan Config

The solution that worked for me is posted here on my blog

Use nano editor to edit these 2 files

nano /etc/resolv.conf
nano /etc/resolvconf/resolv.conf.d/head

Add DNS servers you want to use


Then restart the service

service systemd-resolved restart

Final check:

cat /etc/resolv.conf

Do nslookup

nslookup google.com 

i just used this and it fixed the problem on my laptop at home, but some time in the future when I am out of my home network I can see that it will cause problems, because the primary and secondary dns server will still be my home servers with their lan addresses.

  • 2
    You would need to reconfigure every time the DNS IP's changes (for instance on different networks).
    – Victor
    Commented Feb 14, 2018 at 23:39
  • it's not elegant, but it work's gcloud sometimes sabotage my bedtime.
    – digoferra
    Commented Jun 2, 2018 at 4:39
  • Editing /etc/resolv.conf doesn't work as the file will be overwritten during the systemd-resolved restart. Just edit /etc/systemd/resolved.conf. See my answer here: askubuntu.com/questions/977243/ubuntu-17-10-disable-netplan/…
    – EnzoR
    Commented Oct 2, 2018 at 16:01

It's strange but the only solution which worked for me on Ubuntu 18.04 was the one I found here:

First, change /etc/resolv.conf by setting the desired nameserver:

# nano /etc/resolv.conf

Set, for instance,


And then do

# chattr +i /etc/resolv.conf

This protects /etc/resolv.conf file so that no one can modify it including root user.


I just went through this again on another machine. I decided to live with systemd's resolved and with networkmanager by editing the resolved.conf file, /etc/systemd/resolved.conf, and setting networkmanager to use the same dns server. Stop the stub listener from taking over dns:


...then go into NetworkManager and stop nm from using dhcp to acquire a nameserver IP. Turn off Automatic for DNS, set the nameserver IP.


What I did, after this happened to me when I upgraded from a much older Ubuntu release and my name resolution broke. First I tried the 00-yadayadayada approach above - but that did NOT work.

cd /etc mv resolv.conf resolv.conf-I-HATE-SYSTEMD cp resolv.conf-I-HATE-SYSTEMD resolv.conf

And then edited the file /etc/resolv.conf. The first gets rid of the pesky symbolic link (and documents that was done) so that subsequent reboots won't overwrite it (I hope).

What all of this demonstrates is THE ABSOLUTE FOLLY THAT IS SYSTEMD. What the fsck does a resolver configuration have to do with system startup order, etc., such that systemd should be involved AT ALL. What a piece of junk.

ARRRRRRRRGH. What a piece of junk systemd is. Too many programmers with too much time on their hands to lazy to do the "un fun" jobs of actually writing and fixing APPLICATIONS, seeing it as somehow "beneath" them. Bah.



Use cat and see if /etc/resolvconf/run/interface/* is anything you do NOT want, comment it later using vi.

  • did you mean cat /etc/resolvconf/interface-order ? you could also say: comment it later using your favorite text editor, such as, for example, vi
    – jmarina
    Commented Jun 16, 2023 at 7:30
  • yep, you got me... but after some testing, I realized it's not because of resolvconf, and found it was generated by dhcpcd, so I edited /etc/dhcpcd.conf and un-commended the line starts with "static domain_name_servers", and set some IP addresses separated by space.
    – Alex Lee
    Commented Jun 25, 2023 at 5:48

I've only been able to get name resolution to work with Docker by disabling systemd-resolved completely:

systemctl stop systemd-resolved
systemctl disable systemd-resolved

Then edit /etc/resolv.conf like you would have back in the pre-systemd days.

EDIT: This approach isn't aggressive enough. If your Docker container runs for long enough, Systemd will restart systemd-resolved and DNS resolution will break again. Some people have reported success by running this command:

systemctl mask systemd-resolved

...which is like systemctl disable but stronger. In my Docker deployments I resort to removing the systemd-resolved binary to make sure that Systemd cannot restart it under any circumstances. The command to do that is:

rm -f /lib/systemd/systemd-resolved

I have the same problem. Each reboot, nothing will resolve. I've uninstalled everything and reinstalled it about 50 times already. It's simply just broken.

so the fix is.... "just apply a few settings each time you boot your pc, which allows 90% of host names to resolve but wget and apt-get updates and upgrades will fail randomly for no reason"

cat /etc/systemd/resolved.conf

#  This file is part of systemd.
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
# See resolved.conf(5) for details


When using Ubuntu 17.10 Desktop, you have to edit the one file that says DO NOT EDIT THIS FILE BLAH BLAH BLAH

well that's the ONLY way it works~!

root@nas:~# cat /etc/resolv.conf
# This file is managed by man:systemd-resolved(8). Do not edit.
# is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.

So remove the IP as the name server and enter another one, google for example. It appears my actual DNS IP address doesn't resolve host names either (even though it works on 10 other machines and devices in the house), but google's works fine.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .