18.04 Unable to connect to server due to "Temporary failure in name resolution"

Solution 1:

I think I had this issue before. I used the first answer in this question to resolve it: Wrong nameserver set by resolvconf and NetworkManager

The answer is to change the resolv.conf symlink:

sudo rm -f /etc/resolv.conf
sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
reboot

Solution 2:

For me the answer was that the DNS entries were missing in my Netpan setup. I edited them manually (in my case /etc/netplan/50-cloud-init.yaml but I realize that this might be specific to my environment, and might not "stick").

I changed

network:
ethernets:
    ens160:
        addresses:
        - 10.8.25.116/28
        dhcp4: false
        gateway4: 10.8.25.113
        nameservers:
            addresses: []
            search: []
version: 2

to

network:
ethernets:
    ens160:
        addresses:
        - 10.8.25.116/28
        dhcp4: false
        gateway4: 10.8.25.113
        nameservers:
            addresses: [8.8.8.8,4.2.2.2]
            search: []
version: 2

and then applied it using

netplan apply