When I connect to a VPN network through Gnome Network-manager I lose DNS resolution and in practice, I cannot access resources inside the VPN network or outside.
When I was using Ubuntu 16.04 and I was using the VPN, the "/etc/resolv.conf/
" file would contain the DNS servers of the (VPN) network I had connected. Now it always contains the following entries:
nameserver 127.0.0.53
search myprovider.com
From what I have understood 127.0.0.53
is the address of the DNS stub used by the system-resolved
.
I suspect that this is a bug because the VPN was working fine the Ubuntu 16.04. Is there any way that I can set the DNS servers of my network when I am using a VPN service?
Update:
I tried connecting to the OpenVPN network with the configuration file attached at the end of the post, but I get the following error:
Authenticate/Decrypt packet error: cipher final failed
I have verified that the server uses lzo compression and I have enabled it as well. The connection stays active but I cannot navigate to any page inside or outside the VPN.
In the configuration file listed below, I have included the solutions posted in the replies
client
dev tun
proto udp
remote openvpn.bibsys.no 1194
remote my-server-2 1194
resolv-retry infinite
nobind
user myuser
group myuser
persist-key
persist-tun
ca ca-cert.pem
cert openvpn.crt
key openvpn.key
cipher AES-256-CBC
comp-lzo yes
script-security 2
up /etc/openvpn/scripts/update-systemd-resolved
down /etc/openvpn/scripts/update-systemd-resolved
down-pre
Problem
The file
/etc/resolv.conf
does not get updated by the/etc/openvpn/update-resolv-conf
script becauseresolvconf
is not installed by default on ubuntu 18.04.In fact, one of the first lines of that script checks for the
/sbin/resolvconf
executable:Installing resolvconf via
apt-get
is not a solution as the/etc/openvpn/update-resolv-conf
script updates the/etc/resolv.conf
file with the pushed DNS entry but the tun device seems to ignore it.Solution
Ubuntu 18.04 uses
systemd-resolved
, so all you have to do is install the openvpn helper script forsystemd-resolved
viaor with these GitHub instructions
Update your
config.ovpn
file adding these lines:That instead of adding up and down of
/etc/openvpn/update-resolv-conf
to the conf.To prevent DNS Leakage, you should add this line to the end of the
config.ovpn
file (according to this systemd issue comment):I found a solution on this blog post. While there are two solutions mentioned, I prefer using the second one because it means my DNS is set by the OpenVPN server (the first solution means I use the same DNS servers whether or not I'm connected to the OpenVPN server).
In short:
sudo mkdir -p /etc/openvpn/scripts
sudo wget https://raw.githubusercontent.com/jonathanio/update-systemd-resolved/master/update-systemd-resolved -P /etc/openvpn/scripts/
sudo chmod +x /etc/openvpn/scripts/update-systemd-resolved
Then edit your OpenVPN client file (e.g. client.ovpn) by changing the up/down scripts to:
(I have commented out the original up/down settings).
Actually, there is a much easier solution to this problem. The issue is with DNS traffic and how Ubuntu 18 manages that. By default IP forwarding is disabled which is what OpenVPN needs in order to provide proper networking. All you have to do is run the following command:
Once you have this file opened, look for the line that contains
net.ipv4.ip_forward
. If this line is commented, remove the # sign at the front of the line (if it is not commented then you have another issue). Save the file and then restart your OpenVPN server instance.This fix does not require any modifications to the client or OpenVPN code following upgrade to Ubuntu 18. Tested and confirmed working.
However, this obviously requires you can administer the server. And unfortunately, the bug exists for many who just connect with 18.04 to an OpenVPN server that is administered by somebody else...
Tested on Ubuntu 18.04 at 13 Sep 2018
There is another useful command to setup what you need via command line. You can control your VPN connection both with command line and GUI.
ifname --
is the required by default, but does not affect anythingnever-default
should not use remote gateway as default routeAnd much more interested final touch:
Afterwards you can control vpn with GUI or use following commands:
I'm impacted too. In my case, I'm using OpenVPN with an internal name server (which is inside the VPN). That worked until Ubuntu 17.10 (with
hosts: files dns
in/etc/nsswitch.conf
)./etc/resolv.conf
was updated correctly by the openvpn scripts (through calls to/etc/openvpn/update-resolv-conf
in the openvpn client configuration file).However, name resolution for hosts inside the VPN was not working any more (or at least sporadically... I guess the local DNS cache was picking the names, but after a rather long time).
What seems to help, or even resolve the issue (though that's too early to say) is to install the below package:
If your system is using NetworkManager, then you may only need to change the connection's DNS priority, as per this answer:
In my case, the DNS was being updated, but ignored as the existing DNS servers had precedence. You may need root/
sudo
. If that doesn't work, tryipv6.dns-priority
.None of the proposed CLI-oriented (non-NetworkManager) solutions worked for me (I don't even have
up
anddown
lines inmyconfig.ovpn
).However, I've found that NetworkManager VPN seems to work again (it did not work a year or two ago, which is why I switched to openvpn CLI then). I did not tweak it in any way: just tried to activate it with the appropriate credentials.