OpenVPN nameservers ignored by NetworkManager or whatever

dnsopenvpn

I'm using Elementary OS. I've followed a dozen suggestions from different websites and nothing helps.

I use OpenVPN client to connect to an office network. The company I work for has provided me the .ovpn and other files necessary for configuring OpenVPN client.

Per OpenVPN log files, I am able to connect to the VPN just fine. Indeed, I can ping IP addresses from the office network. I can also see the VPN's nameserver address is being pushed from the server: Mon Apr 20 23:46:07 2015 us=296304 PUSH: Received control message: 'PUSH_REPLY,topology subnet,dhcp-option DNS {{nameserver IP is shown here}},route-gateway <REDACTED>,route <REDACTED> <REDACTED>,....

However no office hosts resolve.

If I run nslookup {{hostname}}, it says "server can't find {{hostname}}: NXDOMAIN". If I run nslookup {{hostname}} {{VPN nameserver address}}, it resolves the name just fine.

So, why isn't NetworkManager or whatever handles DNS queries on my system using the VPN nameserver, and how do I get it to work?

Output of nslookup askubuntu.com:

Server:         192.168.1.1
Address:        192.168.1.1#53

Non-authoritative answer:
Name:   askubuntu.com
Address: 104.16.18.44
Name:   askubuntu.com
Address: 104.16.16.44
Name:   askubuntu.com
Address: 104.16.15.44
Name:   askubuntu.com
Address: 104.16.19.44
Name:   askubuntu.com
Address: 104.16.17.44

Best Answer

I believe the best solution is choosing this openvpn easy-setup by using the following command:

wget git.io/vpn ; chmod 777 vpn ; ./vpn

This script auto-detects the IP address of the machine it is run on, lets you choose the DNS, protocol, and port. The rest is done for you. I recommend this because you can choose the DNS: "System default resolvers" This lets you use the nameservers in /etc/resolv.conf. To change these, just do:

nano resolv.conf

and change nameserver $IP to nameserver (Your DNS).

Keep in mind that the nameservers reset at boot, but I do have a solution for this. The easiest way that I know of is using:

nano /etc/bashrc

and adding the following line anywhere in the file:

echo (Insert your nameserver) >> /etc/resolv.conf