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
down-pre

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 1.1.1.1"
push "dhcp-option DNS 9.9.9.10"
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. 

Sources

Author: Anton Bracke

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

Leave a Reply

Your email address will not be published. Required fields are marked *