Openvpn: Update dns servers FIX

Because newer Ubuntu versions are using systemd for dns resolution instead of resolvconf, you need to modify your Openvpn client config a bit.

Add following lines to your config (/etc/openvpn/myconnection.conf):

script-security 2
setenv PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
up /etc/openvpn/update-systemd-resolved
down /etc/openvpn/update-systemd-resolved

Simply add the new update script by running:

sudo apt install openvpn-systemd-resolved

Or add the script manually:

sudo wget https://raw.githubusercontent.com/jonathanio/update-systemd-resolved/master/update-systemd-resolved -P /etc/openvpn/

Server config

To route all clients over the vpn gateway add following lines to your server config:

push "redirect-gateway def1"
push "dhcp-option DNS"
push "dhcp-option DNS"
push "dhcp-option DOMAIN yourdomain.com"

FYI: You can route just single clients via your vpn gateway by adding these same lines to a client-config-dir (ccd) file. 


Author: Anton Bracke

Software engineering student from Germany. Loves programming in PHP, JS and sometimes C.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.