Merge pull request #76 from discordianfish/push-custom-dns-servers

Support pushing custom DNS servers
This commit is contained in:
Kyle Manna 2015-10-16 07:44:53 -07:00
commit f277449569

View File

@ -37,11 +37,12 @@ usage() {
echo " [-s SERVER_SUBNET]" echo " [-s SERVER_SUBNET]"
echo " [-r ROUTE ...]" echo " [-r ROUTE ...]"
echo " [-p PUSH ...]" echo " [-p PUSH ...]"
echo " [-n DNS_SERVER ...]"
echo echo
echo "optional arguments:" echo "optional arguments:"
echo " -d Disable NAT routing and default route" echo " -d Disable NAT routing and default route"
echo " -c Enable client-to-client option" echo " -c Enable client-to-client option"
echo " -D Disable built in external dns (google dns)" echo " -D Do not push dns servers"
echo " -N Configure NAT to access external server network" echo " -N Configure NAT to access external server network"
echo " -m Set client MTU" echo " -m Set client MTU"
echo " -t Use TAP device (instead of TUN device)" echo " -t Use TAP device (instead of TUN device)"
@ -67,6 +68,8 @@ OVPN_ROUTES=()
TMP_ROUTES=() TMP_ROUTES=()
OVPN_PUSH=() OVPN_PUSH=()
TMP_PUSH=() TMP_PUSH=()
OVPN_DNS_SERVERS=("8.8.8.8" "8.8.4.4")
TMP_DNS_SERVERS=()
OVPN_TLS_CIPHER='' OVPN_TLS_CIPHER=''
OVPN_CIPHER='' OVPN_CIPHER=''
OVPN_AUTH='' OVPN_AUTH=''
@ -75,7 +78,7 @@ OVPN_AUTH=''
[ -r "$OVPN_ENV" ] && source "$OVPN_ENV" [ -r "$OVPN_ENV" ] && source "$OVPN_ENV"
# Parse arguments # Parse arguments
while getopts ":a:C:T:r:s:du:cp:DNm:t" opt; do while getopts ":a:C:T:r:s:du:cp:n:DNm:t" opt; do
case $opt in case $opt in
a) a)
OVPN_AUTH="$OPTARG" OVPN_AUTH="$OPTARG"
@ -104,6 +107,9 @@ while getopts ":a:C:T:r:s:du:cp:DNm:t" opt; do
p) p)
TMP_PUSH+=("$OPTARG") TMP_PUSH+=("$OPTARG")
;; ;;
n)
TMP_DNS_SERVERS+=("$OPTARG")
;;
D) D)
OVPN_DNS=0 OVPN_DNS=0
;; ;;
@ -137,6 +143,9 @@ done
# if new push directives were not defined with -p, use default # if new push directives were not defined with -p, use default
[ ${#TMP_PUSH[@]} -gt 0 ] && OVPN_PUSH=("${TMP_PUSH[@]}") [ ${#TMP_PUSH[@]} -gt 0 ] && OVPN_PUSH=("${TMP_PUSH[@]}")
# if dns servers were not defined with -n, use google nameservers
[ ${#TMP_DNS_SERVERS[@]} -gt 0 ] && OVPN_DNS_SERVERS=("${TMP_DNS_SERVERS[@]}")
# Server name is in the form "udp://vpn.example.com:1194" # Server name is in the form "udp://vpn.example.com:1194"
if [[ "$OVPN_SERVER_URL" =~ ^((udp|tcp)://)?([0-9a-zA-Z\.\-]+)(:([0-9]+))?$ ]]; then if [[ "$OVPN_SERVER_URL" =~ ^((udp|tcp)://)?([0-9a-zA-Z\.\-]+)(:([0-9]+))?$ ]]; then
OVPN_PROTO=${BASH_REMATCH[2]}; OVPN_PROTO=${BASH_REMATCH[2]};
@ -202,8 +211,9 @@ EOF
[ -n "$OVPN_AUTH" ] && echo "auth $OVPN_AUTH" >> "$conf" [ -n "$OVPN_AUTH" ] && echo "auth $OVPN_AUTH" >> "$conf"
[ -n "$OVPN_CLIENT_TO_CLIENT" ] && echo "client-to-client" >> "$conf" [ -n "$OVPN_CLIENT_TO_CLIENT" ] && echo "client-to-client" >> "$conf"
[ "$OVPN_DNS" == "1" ] && echo push "dhcp-option DNS 8.8.4.4" >> "$conf" for i in "${OVPN_DNS_SERVERS[@]}"; do
[ "$OVPN_DNS" == "1" ] && echo push "dhcp-option DNS 8.8.8.8" >> "$conf" echo "push dhcp-option DNS $i" >> "$conf"
done
# Append Routes # Append Routes
for i in "${OVPN_ROUTES[@]}"; do for i in "${OVPN_ROUTES[@]}"; do
# If user passed "0" skip this, assume no extra routes # If user passed "0" skip this, assume no extra routes