I just subscribed to a VPN provider.

I have Xubuntu 17.10, openvpn 2.4.3. After launching the openvpn command I check the IP (fine) and performed a simple DNS leak test: not fine, it shows my Internet Service Provider!

How to fix this DNS leak?

I have one preliminary interrogation:

  • is it "fixable" on my side? Or is the remote server wrongly configured?

On my side, I tried changing some values in the .ovpn config file for openvpn:

  1. Originally there were already these lines, that are expected to work, but nope:

    script-security 2
    up /etc/openvpn/update-resolv-conf
    down /etc/openvpn/update-resolv-conf
  2. I changed them according to this reddit answer (explicitly specifying DNS addresses):

    dhcp-option DNS
    dhcp-option DNS
    dhcp-option DNS
    up "/etc/openvpn/update-resolv-conf foreign_option_1='dhcp-option DNS' foreign_option_2='dhcp-option DNS' foreign_option_3='dhcp-option DNS'"
    down "/etc/openvpn/update-resolv-conf foreign_option_1='dhcp-option DNS' foreign_option_2='dhcp-option DNS' foreign_option_3='dhcp-option DNS'"

    Doing that seems to do the job, as the content of /etc/resolvconf gets updated by the up/down scripts:

    # 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.
    search lan

    but DNSleaktest still showing my ISP.

  3. So then I learned the existence of the ubuntu package openvpn-systemd-resolved which provides a script similar to update-resolve-conf but makes it work with systemd (here I have no idea what processes use this: network-manager? openvpn?). I installed the package and replaced the script name in my .ovpn file:

    up "/etc/openvpn/update-systemd-resolved ..."
    down "..."

    Still no luck. [While writing this I just figured out the solution, see my answer below]

  4. Then I played a lot with the /etc/resolv.conf file. Normally it should not be changed, so I put my DNS servers addresses into /etc/resolvconf/resolv.conf.d/base, but issuing resolvconf -u did not appear to work.

  5. Chatted with a support person from the VPN company, no solution.

  6. I tried various solutions like this one, and subsequent unaccepted answers:

    • installing dnsmasq and putting server=... into /etc/dnsmasq.conf;
    • putting a "supersede" line in the /etc/dhcp/dhclient.conf (details);
    • the chattr-based hack.
  7. I forgot the other things I tried, then I thought, stackexchange will save me from my misery, and it miraculously did, just by the power of formulating a question.

[Edit 1: Not solved! Actually my first answer is not the reason it works]

I noticed it after more checking. I can remove the systemd-update-resolved lines and it still works, but only on certain conditions:

When the openvpn service is running, I get DNS leaks. If I stop it, and then restart only the service for my client:

sudo service openvpn stop
sudo service openvpn@client start

then it works.

Sorry, I suppose I haven't check the openvpn manual thoroughly, but why is that? Isn't it a security leak? Especially because the openvpn service is activated automatically after installation from apt. How to make the change permanent? (I tried sudo systemctl disable openvpn, but at next startup I still had the same problem).

[Edit 2: routing tables]

Once I stopped openvpn and started openvpn@client, I don't have DNS leaks and the output of route -n is:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface       UG    0      0        0 tun0         UG    100    0        0 eno1 UGH   0      0        0 eno1 U     0      0        0 tun0       UG    0      0        0 tun0     U     1000   0        0 eno1   U     100    0        0 eno1

After a sudo service openvpn restart:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface       UG    0      0        0 tun0         UG    100    0        0 eno1 UGH   0      0        0 eno1 U     0      0        0 tun0       UG    0      0        0 tun0     U     1000   0        0 eno1   U     100    0        0 eno1

Not working anymore, I get DNS leaks in both cases. I tried installing the package openresolv (which replaces resolvconf), and it seems to work. Here is the new routing table:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface       UG    0      0        0 tun0         UG    100    0        0 eno1 UGH   0      0        0 eno1 U     0      0        0 tun0       UG    0      0        0 tun0     U     1000   0        0 eno1   U     100    0        0 eno1
  • 1
    Please add your routing table while you have the VPN active. – Rui F Ribeiro Apr 2 '18 at 8:55
  • Just did! But damned***, I can't make it work anymore, I get DNS leaks even when stopping the openvpn service! – PlasmaBinturong Apr 2 '18 at 9:50
  • No changes in routing. Are you setting up a client or a server? – Rui F Ribeiro Apr 2 '18 at 10:10
  • Yes I saw no changes. I'm setting up a client. – PlasmaBinturong Apr 2 '18 at 10:52
  • Basically nothing works, lastly openresolv neither. What services should I restart after each config edit? network-manager? openvpn? Is my browser caching some data? – PlasmaBinturong Apr 2 '18 at 11:06

Sooo the answer is to carefully follow the always-on-point instructions from the ArchLinux wiki:


and to append the corresponding lines.

So, in two steps:

sudo apt install openvpn-systemd-resolved

and append the following lines to your .ovpn file:

script-security 2
dhcp-option DNS
dhcp-option DNS
dhcp-option DNS
up /etc/openvpn/update-systemd-resolved
down /etc/openvpn/update-systemd-resolved

If that's not clear, your file should now contain two lines "up" and two lines "down":

# old lines
up /etc/openvpn/update-resolv-conf
down /etc/openvpn/update-resolv-conf
# new lines
script-security 2
dhcp-option DNS
dhcp-option DNS
dhcp-option DNS
up /etc/openvpn/update-systemd-resolved
down /etc/openvpn/update-systemd-resolved

[Edit 1: Actually NOPE, this wasn't the reason it worked]

See Edit 1 in my question.

[Edit 2: I think I got it right this time]

This issue of weird systemd-resolved.service behavior is referenced here.

It seems that the option to put in the client config file is the following:

dhcp-option DOMAIN-ROUTE .

which apparently routes all DNS through the selected connection...

  • However, when the computer goes out of sleep, I have to restart the openvpn service and then it's leaking again... – PlasmaBinturong Apr 2 '18 at 19:02

I had this DNS leak issue on Ubuntu 17.10 and now 18.04 LTS. It must have started when I updated from 16.10 a while back and I never thought to check until now, by accident. None of the above (and other things I found and tried) helped, until I ran into this URL below, reading all the way through the bug report. The comment on adding a dns-priority line worked for me.

https://bugs.launchpad.net/network-manager/+bug/1624317 look at comment #103.

Look for your installed NetworkManager VPN connections (the '$' is just my system prompt, to show you're at the command line in a terminal window):

$ ls -la /etc/NetworkManager/system-connections/*

Then choose the one you want to fix and run this command on it (or you can just edit the config file manually, as this command just adds a dns-priority entry under section ipv4):

$ sudo nmcli connection modify <vpn-connection-name> ipv4.dns-priority -42

And restart:

$ sudo service network-manager restart

Note that at least for me, putting it in the OpenVPN .ovpn config file that came from my VPN (ProtonVPN) did not work. For some reason it did not make it into the NetworkManager config when it was installed using the GUI dialog. Only by updating the config after it was installed, and then restarting NetworkManager, did it work. And you need to do this for each installed VPN config you want to use.

  • This works, but actually NOT really as desired. I monitor both my physical interface and tun0, DNS query for every domain actually gets sent, thus can be observed from both interfaces. – 32r34wgf3e Mar 9 at 14:22

This seems to be a bug due to Ubuntu switching to systemd-resolve before the network-manager-openvpn package was updated to be aware of systemd-resolve. Ubuntu 18.10 seems to have resolved this with network-manager 1.12.2-0ubuntu5. More information here: https://gitlab.gnome.org/GNOME/NetworkManager-openvpn/issues/10.

Until that's released, @Bob Willan's answer worked for me.

  • Tested in 18.10 with NetworkManager and works! Hopefully they will fix this in the next LTS release. – 32r34wgf3e Mar 9 at 14:23

I managed to solve this issue by adding these lines to my OpenVPN config file :

script-security 2

up /etc/openvpn/update-resolv-conf

down /etc/openvpn/update-resolv-conf

from @ How To Fix OpenVPN DNS Leak in Linux

And for Windows users (OpenVPN +2.3.9) :


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.