OpenVPN – Client DNS queries

domain-name-systeminternal-dnsnetworkingopenvpnvpn

I have an openVPN server using a routed TUN setup.

server.conf

topology subnet
server 10.8.0.0 255.255.255.0
push "redirect-gateway"
push "route 10.0.0.0 255.255.255.0"
push "dhcp-option DNS 10.0.0.1"    

I'm having trouble with my openVPN client and access to an intranet web server.
The domain name for the web server is intranet.app.

Access from the LAN is working fine – the gateway forwards DNS queries for intranet.app to the local server.

When I connect via openVPN it seems as if all DNS queries are forwarded to the DNS server listed by the Wireless / LAN adaptor used to connect to the internet.
If that DNS query doesn't resolve – it then queries the DNS server listed on the vpn gateway.

I have tested this by setting up a dummy domain on my server as intranet.lan.

intranet.app – resolves to 127.0.53.53 because .app is now a gTLD but intranet.app isn't a registered domain.

intranet.lan – doesn't resolve because .lan isn't a gTLD. The vpn gateway DNS server is then queried and query does resolve to the LAN hosted web server.

How can I programmatically make sure that the openVPN client only sends DNS queries to the VPN gateway and not the Wireless / LAN adapter??

Thanks

Best Answer

I have found a set of scripts at dnsleaktest.com which removes any existing links to DNS resolvers before the tunnel is created and adds those of the VPN connection. It also reverses this once the connection is closed.