resolv.conf parsing optimizations

This commit is contained in:
Nyr 2020-05-29 14:16:10 +02:00
parent 42bee2ae2f
commit 03cf6ddf2e

View file

@ -110,13 +110,13 @@ new_client_dns () {
1|"")
# Locate the proper resolv.conf
# Needed for systems running systemd-resolved
if grep -q "127.0.0.53" "/etc/resolv.conf"; then
if grep -q '^nameserver 127.0.0.53' "/etc/resolv.conf"; then
resolv_conf="/run/systemd/resolve/resolv.conf"
else
resolv_conf="/etc/resolv.conf"
fi
# Extract nameservers and provide them in the required format
dns=$(grep -v '#' "$resolv_conf" | grep nameserver | grep -E -o '[0-9]{1,3}(\.[0-9]{1,3}){3}' | xargs | sed -e 's/ /, /g')
dns=$(grep -v '^#\|^;' "$resolv_conf" | grep '^nameserver' | grep -oE '[0-9]{1,3}(\.[0-9]{1,3}){3}' | xargs | sed -e 's/ /, /g')
;;
2)
dns="8.8.8.8, 8.8.4.4"