9

I am using focal Ubuntu 20.04.1 LTS (hosted virtual machine)

Occasionally after a reboot DNS resolution fails (e.g. ping google.com > Resource temporarily unavailable)

To 'fix' this I reboot the machine.

What is the proper fix and why is this occurring sporadically ?

The contents of resolv.conf indicates the file is being managed by systemd-resolved

# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients directly to
# all known uplink DNS servers. This file lists all configured search domains.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.
# No DNS Servers known

example error:

wal@www:~$ ping google.com
ping: google.com: Resource temporarily unavailable
4
  • 1
    @Nmath question updated. also How do you know that this is a problem with DNS resolution? - ping google.com fails (as above) but ping 8.8.8.8 works
    – wal
    Nov 16, 2020 at 5:37
  • Check the /etc/resolv.conf link, it should point to the stub-resolv.conf, but yours points to the resolv.conf, and for some reason, that file does not contain any DNS servers (Some recommend using that to cut out systemd-resolv completely, but then a real DNS server, like the router should be included).
    – ubfan1
    Nov 16, 2020 at 5:44
  • you can read through that documentation to configure your symlink for DNS resolving: wiki.archlinux.org/index.php/Systemd-resolved
    – starkus
    Nov 16, 2020 at 5:52
  • What does sudo systemd-resolve --status say when this happens?
    – rtaft
    Nov 19, 2020 at 17:49

2 Answers 2

9
+100

If /etc/netplan is empty then netplan does not configure your network.

Your network is probably configured in old ifup/ifdown style. That means you find the network configuration in /etc/network/interfaces.

In addition there is systemd-resolve with its DNS configuration file /etc/systemd/resolved.conf where you can put your DNS configuration in.

[Resolve]
DNS=8.8.4.4 8.8.8.8 2001:4860:4860::8844 2001:4860:4860::8888
#FallbackDNS=
Domains=example.com
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#Cache=yes
#DNSStubListener=yes

You can check your DNS settings with

systemd-resolve --status

You can restart systemd-resolve with

systemctl restart systemd-resolved

Alternatively you can put your settings in /etc/resolvconf/resolv.conf.d/tail which will be added to /run/resolvconf/resolv.conf during boot.

2
  • this answer has helped (i cannot upvote due to reputation being used for bounty) - i'm able to work around the problem by assigning the DNS field in /etc/systemd/resolved.conf - when i do this i no longer see the entry with search (all entries are nameserver: ... - still unsure why prior resolved.conf was seemingly randomly empty
    – wal
    Nov 23, 2020 at 0:26
  • You probably did not install netplan. I have no idea why. Without netplan you need another way to configure resolv.conf. This is in your case systemd-resolved now. search is probably empty because you did not set the Domains parameter in /etc/systemd/resolved.conf Nov 23, 2020 at 17:41
2

Ubuntu 20.04 uses /etc/netplan to set DNS. Do you have nameservers section in your /etc/netplan/?.yaml file?

yaml-file should have a section similar like this:

            nameservers:
                addresses:
                - 8.8.8.8
                - 2001:4860:4860::8888

resolve.conf is generated from netplan during boot and should should look like this.

nameserver 127.0.0.53
options edns0 trust-ad
search example.com

There is also a /etc/systemd/resolved.conf where static configuration may be strored. You can read more details man resolved.conf

Furthermore you can investigate journalctl -b and search for systemd-resolved messages.

1
  • /etc/netplan folder is empty (the folder exists however)... ...is generated from netplan during boot and should should look like this <-- it does look like that now (and is working) but as above on some reboots it is blank -
    – wal
    Nov 19, 2020 at 22:58

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.