From afb30c44da277684955ebb08e680be2defe28ad4 Mon Sep 17 00:00:00 2001
From: Nyr <me@nyr.be>
Date: Thu, 15 May 2014 18:20:53 +0200
Subject: [PATCH] Now using resolvers from resolv.conf

This will help with some ISPs restricting access to third party DNS
servers like it happens with LowEndSpirit and Torqhost.
---
 openvpn-install.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/openvpn-install.sh b/openvpn-install.sh
index e2e5271..acae4e1 100755
--- a/openvpn-install.sh
+++ b/openvpn-install.sh
@@ -174,9 +174,11 @@ else
 	# Set the server configuration
 	sed -i 's|dh dh1024.pem|dh dh2048.pem|' server.conf
 	sed -i 's|;push "redirect-gateway def1 bypass-dhcp"|push "redirect-gateway def1 bypass-dhcp"|' server.conf
-	sed -i 's|;push "dhcp-option DNS 208.67.222.222"|push "dhcp-option DNS 129.250.35.250"|' server.conf
-	sed -i 's|;push "dhcp-option DNS 208.67.220.220"|push "dhcp-option DNS 74.82.42.42"|' server.conf
 	sed -i "s|port 1194|port $PORT|" server.conf
+	# Obtain the resolvers from resolv.conf and use them for OpenVPN
+	cat /etc/resolv.conf | grep -v '#' | grep 'nameserver' | grep -E -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | while read line; do
+		sed -i "/;push \"dhcp-option DNS 208.67.220.220\"/a\push \"dhcp-option DNS $line\"" server.conf
+	done
 	# Listen at port 53 too if user wants that
 	if [ $ALTPORT = 'y' ]; then
 		iptables -t nat -A PREROUTING -p udp -d $IP --dport 53 -j REDIRECT --to-port $PORT