-
Check if resolvconf exists and is executable:
[ -x /sbin/resolvconf ] || exit 0
If /sbin/resolvconf is not present or not executable, the script exits early.
-
Determine the Address Family:
case "$ADDRFAM" in
inet|inet6) : ;;
*,*) ADDRFAM="$(echo $ADDRFAM | tr , '\n' | sort | head -n1)" ;;
*) exit 0 ;;
esac
It checks the ADDRFAM environment variable (address family). If it's inet (IPv4) or inet6 (IPv6), it proceeds. If ADDRFAM contains a comma (e.g., "inet,inet6"), it sorts them and picks the first one. If none of these match, it exits.
-
Prepare DNS Configuration Entries:
R=""
if [ "$IF_DNS_DOMAIN" ] ; then
R="${R}domain $IF_DNS_DOMAIN
"
fi
if [ "$IF_DNS_SEARCH" ] ; then
R="${R}search $IF_DNS_SEARCH
"
fi
if [ "$IF_DNS_SORTLIST" ] ; then
R="${R}sortlist $IF_DNS_SORTLIST
"
fi
for NS in $IF_DNS_NAMESERVERS ; do
R="${R}nameserver $NS
"
done
It appends to the variable R DNS-related options (domain, search, sortlist, nameservers) if they are set.
-
Fix for Handling Multiple Nameserver Options:
set_NS_to_first_arg() { NS="$1" ; }
STANDARD_IFS="$IFS"
IFS='
'
for OPT in $IF_DNS_NAMESERVER ; do
IFS="$STANDARD_IFS"
set_NS_to_first_arg $OPT
[ "$NS" ] && R="${R}nameserver $NS
"
done
IFS="$STANDARD_IFS"
This section attempts to handle multiple nameserver entries by setting the internal field separator (IFS) to a newline, so each nameserver gets processed properly.
-
Update resolv.conf Using resolvconf:
echo -n "$R" | /sbin/resolvconf -a "${IFACE}.${ADDRFAM}" || :
Finally, it feeds the built-up DNS configuration ($R) into resolvconf to update the DNS resolver configuration for the particular interface identified by ${IFACE}.${ADDRFAM}.