34

My DNS server is 192.168.1.152.

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:     127.0.0.53
Address:    127.0.0.53#53

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

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

# nslookup unraid.local 192.168.1.152
Server:     192.168.1.152
Address:    192.168.1.152#53

Name:   unraid.local
Address: 192.168.1.152

/etc/resolv.conf has a wrong nameserver:

# 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

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

root@ubuntu:~# systemd-resolve --status
Global
          DNSSEC NTA: 10.in-addr.arpa
                      16.172.in-addr.arpa
                      168.192.in-addr.arpa
                      17.172.in-addr.arpa
                      18.172.in-addr.arpa
                      19.172.in-addr.arpa
                      20.172.in-addr.arpa
                      21.172.in-addr.arpa
                      22.172.in-addr.arpa
                      23.172.in-addr.arpa
                      24.172.in-addr.arpa
                      25.172.in-addr.arpa
                      26.172.in-addr.arpa
                      27.172.in-addr.arpa
                      28.172.in-addr.arpa
                      29.172.in-addr.arpa
                      30.172.in-addr.arpa
                      31.172.in-addr.arpa
                      corp
                      d.f.ip6.arpa
                      home
                      internal
                      intranet
                      lan
                      local
                      private
                      test

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

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?

37

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

change this:

[Resolve]
#DNS=

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

[Resolve]
DNS=192.168.1.152

after that, restart the service:

service systemd-resolved restart

And when you check the status you should see

$ systemd-resolve --status
Global
         DNS Servers: 192.168.1.152

      DNSSEC NTA: 10.in-addr.arpa
                  16.172.in-addr.arpa
                  168.192.in-addr.arpa
                  17.172.in-addr.arpa
                  18.172.in-addr.arpa
                  19.172.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 Nov 4 '17 at 22:10
  • 12
    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 Nov 8 '17 at 22:55
  • 4
    Does not look optimal, you will have to do this every time you change DNS server/network – Victor Feb 14 '18 at 21:23
  • 1
    You would need to reconfigure every time the DNS IP's changes (for instance on different networks). – Victor Feb 14 '18 at 23:40
34

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
reboot
  • 2
    This solution worked somewhat, host and nslookup commands resolve names properly, but wget and browsers are not – FireSpore Nov 11 '17 at 5:39
  • 1
    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 Apr 29 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 Jun 24 at 12:21
9

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=10.96.0.10 8.8.8.8 8.8.4.4

  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 Feb 14 '18 at 23:39
  • Victor do you have a best solution? this is the same if you use static net config – Fabio Fumarola Feb 16 '18 at 15:19
  • This answer works for both static and dynamic configurations: askubuntu.com/a/974482/343617 – Victor Feb 16 '18 at 15:41
  • thank you, the solution I have pointed out was static. I agree – Fabio Fumarola Feb 18 '18 at 11:39
  • This just worked for me on a new 18.04 install – JamesCW Apr 30 at 13:56
1

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).
  network:
   version: 2
   renderer: NetworkManager
   ethernets:
EOF
echo "    ${NIC}:" >> /etc/netplan/01-netcfg.yaml
cat >>/etc/netplan/01-netcfg.yaml <<EOF
      dhcp4: yes
      nameservers:
        search: [abc.domain.edu, def.domain.edu]
        addresses: [10.10.11.22, 10.10.11.23]

EOF

#work around DNS resolv bug
systemctl stop systemd-resolved
sed -i 's/#DNS=/DNS=10.10.11.22 10.10.11.23/' /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
reboot
############### End Netplan Config
1

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

nameserver 9.9.9.9
nameserver 127.0.0.1

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 Feb 14 '18 at 23:39
  • it's not elegant, but it work's gcloud sometimes sabotage my bedtime. – Rodrigo Ferrari Jun 2 '18 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 Oct 2 '18 at 16:01
1

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

Add:

[Resolved]
Cache=yes
DNS=192.168.1.152

Then...

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.

  • 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 Jan 23 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 Jan 23 at 4:20
0

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:

nameserver 127.0.0.53#53

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.

0

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,

nameserver 8.8.8.8

And then do

# chattr +i /etc/resolv.conf

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

-3

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

[Resolve]
#DNS=
#FallbackDNS=
#Domains=
#LLMNR=yes
#MulticastDNS=yes
#DNSSEC=no
#Cache=yes
#DNSStubListener=udp

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.
#
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.
nameserver 8.8.8.8

So remove the 127.0.0.53 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.