Cannot connect to OpenVPN server under Ubuntu 16.04

Solution 1:

Ubuntu provides a script to update its resolv.conf: /etc/openvpn/update-resolv-conf

you can add it to your client.ovpn by appending these lines to it:

up /etc/openvpn/update-resolv-conf
down /etc/openvpn/update-resolv-conf

when starting the vpn service it will evaluate foreign options sent by the server. those should contain information about dns servers for the remote network you just connected to.

To allow these scripts to be run, you either need to change the configuration and add

script-security 2

as well, or you can add this parameter to your commandline like this:

sudo openvpn --config client.ovpn --script-security 2