Skip to content

Commit

Permalink
Merge pull request #478 from amnezia-vpn/bugfix/macos-dns-resolve
Browse files Browse the repository at this point in the history
Fix resolv-update script for MacOS (OpenVPN DNS)
  • Loading branch information
pokamest committed Dec 28, 2023
2 parents c9bde5c + 8d3e21d commit bb43b54
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions deploy/data/macos/update-resolv-conf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

# Mac name-resolution updater based on @cl's script here:
# https://blog.netnerds.net/2011/10/openvpn-update-client-dns-on-mac-os-x-using-from-the-command-line/
# Openvpn envvar parsing taken from the script in debian's openvpn package.
# Openvpn envar parsing taken from the script in debian's openvpn package.
# Smushed together and improved by @andrewgdotcom.

# Parses DHCP options from openvpn to update resolv.conf
# To use set as 'up' and 'down' script in your openvpn *.conf:
# up /etc/openvpn/update-resolv-conf
# down /etc/openvpn/update-resolv-conf

echo "*** starting update-resolv-config script ***"

[ "$script_type" ] || exit 0
[ "$dev" ] || exit 0

Expand All @@ -34,11 +36,11 @@ update_all_dns()
echo updating dns for $adapter
# set dns server to the vpn dns server
if [[ "${SRCHS[@]}" ]]; then
networksetup -setsearchdomains "$adapter" "${SRCHS[@]}"
networksetup -setsearchdomains "$adapter" "${SRCHS[@]}"
fi
if [[ "${NMSRVRS[@]}" ]]; then
networksetup -setdnsservers "$adapter" "${NMSRVRS[@]}"
fi
networksetup -setdnsservers "$adapter" "${NMSRVRS[@]}"
fi
done
}

Expand All @@ -61,7 +63,7 @@ case "$script_type" in
if [ "$part1" = "dhcp-option" ] ; then
if [ "$part2" = "DNS" ] ; then
NMSRVRS=(${NMSRVRS[@]} $part3)
elif [ "$part2" = "DOMAIN" ] ; then
elif [ "$part2" = "DOMAIN" ] || [ "$part2" = "DOMAIN-SEARCH" ]; then
SRCHS=(${SRCHS[@]} $part3)
fi
fi
Expand All @@ -72,3 +74,5 @@ case "$script_type" in
clear_all_dns
;;
esac

echo "*** finished update-resolv-config script ***"

0 comments on commit bb43b54

Please sign in to comment.