====== Ubuntu - VPN - OpenVPN - Configure OpenVPN to resolve local DNS & hostnames ====== To allow accessing local computers on the LAN by their hostnames instead of just by IP Address. **NOTE:** By default, the client **resolv.conf** file does not contain a line to point the client to the VPN DNS server; nor does it contain a line telling the client what the local domain name is. * Adding these lines (and removing when VPN is down) to resolv.conf automatically is the goal. ---- ===== Server ===== Ensure the following lines are in the server config file **/etc/openvpn/server.conf**. push "dhcp-option DNS 192.168.1.1" push "dhcp-option DOMAIN localdomain" **NOTE:** This tells the client that they should use 192.168.1.1 as the DNS server, and localdomain as a domain. ---- ===== Client ===== Install the **resolvconf** package to give your OpenVPN client the ability to rebuild the resolv.conf file when you start and stop your VPN connection. This also backups the existing resolv.conf file; and creates a symlink to the resolv.conf file. sudo apt install resolvconf sudo mv /etc/resolv.conf /etc/resolv.conf.orig sudo ln -s /run/resolvconf/resolv.conf /etc/resolv.conf Add the following lines to the client .ovpn file. up /etc/openvpn/update-resolv-conf down /etc/openvpn/update-resolv-conf **NOTE:** This will run **update-resolv-conf** every time the client connects to or disconnects from the VPN server. ---- ===== Test ===== Run the openvpn command with **--script-security 2** flag to allow update-resolv-conf to be run: sudo openvpn --script-security 2 --config /path/to/client.ovpn ---- ===== References ===== https://steamforge.net/wiki/index.php/How_to_configure_OpenVPN_to_resolve_local_DNS_%26_hostnames http://www.softwarepassion.com/solving-dns-problems-with-openvpn-on-ubuntu-box/ https://serverfault.com/questions/318563/how-to-push-my-own-dns-server-to-openvpn