OpenVPN Client – DNS Script

The OpenVPN server can pass DNS servers and a domain name to the client. This gives the benefit of using the remote dns servers for local hostname lookups.

Finding a good script that worked to do this provide difficult…

In server.conf add:

push "dhcp-option DOMAIN ion.lan"
push "dhcp-option DNS"

Then save this script on the client in same location as the client config


case "$1" in
	    mv /etc/resolv.conf /etc/resolv.conf.bak

		echo "# Generated by OpenVPN Client UP Script" > /etc/resolv.conf
		for opt in ${!foreign_option_*};
	        echo ${!opt} | sed -e 's/dhcp-option DOMAIN/domain/g' -e 's/dhcp-option DNS/nameserver/g' >> /etc/resolv.conf
        mv /etc/resolv.conf.bak /etc/resolv.conf
        echo "Pass either UP or DOWN"

In the client.conf add

script-security 2

up "./ up"
down "./ down"

Now connect and check /etc/resolv.conf to see if the VPN nameserver and domain is listed.

Leave a Reply

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