Only add DNS if there are DNS set

This commit is contained in:
Alexandre
2022-05-02 20:40:10 +02:00
committed by GitHub
parent 6ecd14c7d0
commit f8cde01e12

View File

@@ -16,6 +16,7 @@ if bashio::config.has_value 'DNS_server'; then
# Get DNS servers # Get DNS servers
# shellcheck disable=SC2086 # shellcheck disable=SC2086
for server in ${DNSSERVER//,/ }; do # Separate comma separated values for server in ${DNSSERVER//,/ }; do # Separate comma separated values
# Only add DNS if successful
if ping -c 1 "$server" &> /dev/null if ping -c 1 "$server" &> /dev/null
then then
DNS="${DNS}nameserver $server\n" DNS="${DNS}nameserver $server\n"
@@ -25,11 +26,17 @@ if bashio::config.has_value 'DNS_server'; then
fi fi
done done
# Write resolv.conf # Only add DNS if there are DNS set
# shellcheck disable=SC2059 if [[ ! -z "$DNS" ]]; then
printf "${DNS}" >/etc/resolv.conf # Write resolv.conf
chmod 644 /etc/resolv.conf # shellcheck disable=SC2059
bashio::log.info "DNS SERVERS set to $DNSLIST" printf "${DNS}" >/etc/resolv.conf
chmod 644 /etc/resolv.conf
bashio::log.info "DNS SERVERS set to $DNSLIST"
else
bashio::log.warning "No valid DNS were found. Using default router (or HA) dns servers."
fi
else else
bashio::log.info "DNS Servers option empty. Using default router (or HA) dns servers." bashio::log.info "DNS Servers option empty. Using default router (or HA) dns servers."
fi fi