How to use DNS from VPN using openvpn command line interface?

I’ve tried to use this:

This does not work 100% (after connecting to the server, I can access IP addresses, but not using domain names specific to the VPN):

sudo openvpn \
     --config /path/to/silviubogan.ovpn \
     --pkcs12 /path/to/silviubogan.p12 \
     --tls-auth /path/to/silviubogan.key --allow-pull-fqdn

This has nothing to do with DNS. It just means openvpn will also pull and apply network settings that contains names instead of only IP address or IP ranges. It is for setting up the VPN not for DNS queries after the VPN is set up.

Simply use the DNS server the VPN network tells you to use. The DNS server is usually send with the IP and other information to set up the VPN. If you want this automatically use NM or use a script that will do this. If you don’t want to use NM, a tool like resolveconf is usually required and need to be set up before it works.

What is the command line option to specify the DNS server when using openvpn as in the command above?

You cannot set it directly - you need to script the up/down events

Sample scripts is located in /usr/share/openvpn/contrib/pull-resolv-conf/

1 Like

I solved this with the help of a colleague, by putting in /etc/resolve.conf the DNS IPs of Google. Everything seems to work now, but I am not sure whether it worked before too.