I would like to configure my Ubuntu 18.04.2 (LTS) machine to always use the Google DNSs, no matter what the network. I'm experiencing DNS issues with some VPN connections, e.g. if I connect to a VPN from my home WiFi, no names resolve after that. I've had this problem in the past, and back then setting the nameservers in /etc/resolv.conf and making it immutable did the trick.

However, with netplan I haven't found any instructions for declaring DNSs globally. I don't want to do it per network, as the use case is exactly that whenever I'm connected to some unknown wifi, I want to be able to use my VPNs.

After ~1 h of googling around, I haven't found anything that would resolve my problem. I can only find instructions for defining the nameservers for a specific wifi adapter, which also requires me to define access-points, which I don't want to do. Any pointers how to proceed?

Edit: I resolved the most pressing issue by setting the DNS servers for my VPN connections from the network-manager VPN settings GUI, but still it would be practical to figure this out, as I don't necessarily want to do this separately for each VPN.

  • 1
    You neglected to mention you meant wifi, etc. on a non-server setup. Unfortunately, if you are NOT using Network Manager your only solution is the immutable /etc/resolv.conf you indicated, but that will bypass the local resolution of /etc/hosts the way SystemD's Resolved handles requesrts. – Thomas Ward Jul 15 '19 at 20:19

First, let me clear up a misconception about VPNs. When connected via VPN, you'll end up, or should end up, using the VPN provider's DNS servers. If for no other reason, this is to prevent "DNS Leaks".

As you note, you don't want to setup a per-connection DNS configuration.

First you need to get DNS working without VPN. Then later, with VPN up, you'll do "DNS Leak" testing to confirm a fully secure and private tunnel.

If you edit /etc/systemd/resolved.conf (man resolved.conf) you find a line like:


Remove the #, and set your space-separated list of DNS servers there.

Reboot, and use either:



systemd-resolve --status

And observe your DNS servers and where they're attached (eth0).

Then bring up VPN and re-run one of the previous two commands, and note the DNS server change, and where they're attached (tun0).

Now for "DNS Leak" testing, visit https://dnsleaktest.com or https://dnsleak.com and confirm that you have no leaks.

Lastly, I'll mention that the symlink for /etc/resolv.conf has to be correct... (and you haven't edited that file manually... correct?).

| improve this answer | |
  • Thanks, this seems to have done the trick. I understand the security implications, but at least in the past I had bad experiences using NordVPN's provided DNS servers, as they were for some reason very slow, and caused a noticeable delay when using the Internet. – Joel Lehikoinen Jul 18 '19 at 6:04

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.