Default DNS Server not switched after connecting to OpenVPN

Solution 1:

Add to the client configuration file (the file with extension .ovpn) downloaded from the OpenVPN server the line:

dhcp-option DOMAIN-ROUTE .

As you know, before adding this line, in Ubuntu 18.04 you must install update-systemd-resolved scripts as described in https://github.com/jonathanio/update-systemd-resolved

If it still does not work, perhaps you must add your internal DNS server too. Check the lines you add at the end of the .ovpn file looks like:

script-security 2
dhcp-option DNS 10.1.0.1  # replace this IP with your DNS server IP.
dhcp-option DOMAIN yourinternaldomain.local  # replace this with your internal domain name.
dhcp-option DOMAIN-ROUTE .
up /etc/openvpn/update-systemd-resolved
down /etc/openvpn/update-systemd-resolved
down-pre

If you use the UI (gnome) to connect

Last, if you are using the UI VPN Icons to connect to your VPN, you must re-import the .ovpn modified file.

To do that execute in a terminal:

sudo apt install openvpn openvpn-systemd-resolved resolvconf
sudo apt install network-manager-openvpn network-manager-openvpn-gnome

Click in Ubuntu start menu:

Ubuntu Menu

Type the word "network" and click on Network. It should show somthing like:

Network setup

Click in the "+" sign on VPN and click in "import from file" option:

import ovpn file

Once imported, add a name and click the "add" button at the top right of the dialog.

You are all set!


To connect to the VPN, click in the network icon and after that in the lock icon.

enter image description here