Configure Netconfig for Static Domain Search Lists

Share
Share

In SLE 11 we have a new (better) way to set up automatic network configuration.

It’s called netconfig (man 8 netconfig). Its a “modular tool to modify network configuration”.

Well on my SLED 11 RC1 Box it pretty much worked out of the box. Except:

  • When using Modem devices (eg UMTS/G3 via a Phone) DNS Servers where not added to /etc/resolv.conf ( see Configure netconfig for modem use )
  • Static search entries did not work / where overwritten by NetworkManager

Netconfig uses a bunch of scripts in /etc/netconfig.d to do the actual work. Its configuration resides in /etc/sysconfig/network/config

The following tries to fully explains what is happening. If you’re just interested in the Solution skip down to Summary.

The Search Domain Problem

If you’re just as lazy as me you don’t want to type Fully Qualified Domain Names all the time. Of course you could use /etc/hosts but thats boring and not very transportable.

So I set up NETCONFIG_DNS_STATIC_SEARCHLIST in /etc/sysconfig/network/config. But it doesn’t work when using NetworkManager. The NM overwrites the search entries in /etc/resolv.conf if it finds something in DHCP. Bummer.

What is happening

netconfig uses a bunch of script (modules) to decide what to do in certain situations. The Modules are configured using the NETCONFIG* Variables in /etc/sysconfig/network/config.

The variable NETCONFIG_DNS_POLICY is used to control how netconfig should set up Name Servers in /etc/resolv.conf

Excerpt from /etc/sysconfig/network/config (default):

...
## Type:        string
## Default:     "auto"
#
# Defines the DNS merge policy as documented in netconfig(8) manual page.
# Set to "" to disable DNS configuration.
#
NETCONFIG_DNS_POLICY="auto"
...

Unfortunately man 8 netconfig only has this to say about NETCONFIG_DNS_POLICY:

NETCONFIG_DNS_POLICY -Defines the DNS merge policy.

Nothing about what the actual Values could be.

The /etc/netconfig.d/dns-resolver script is responsible for setting resolv.conf so we find our possible values here:

Excerpt from /etc/netconfig.d/dns-resolver (SLED 11 RC1 Version):

...
# just for the case we need the original value...
_NETCONFIG_DNS_POLICY="$NETCONFIG_DNS_POLICY"
if [ "$_NETCONFIG_DNS_POLICY" = "auto" ]; then
    if [ "x$NETWORKMANAGER" = "xyes" ] ; then
        #
        # Use NetworkManager policy merged data
        #
        _NETCONFIG_DNS_POLICY='STATIC_FALLBACK NetworkManager'
    else
        #
        # We use static settings and extend them
        # with interface specific if available
        #
        _NETCONFIG_DNS_POLICY='STATIC *'
    fi
elif [ "x$_NETCONFIG_DNS_POLICY" = "x" ]; then
    #
    # empty policy means do not touch anything.
    # successful exit.
    #
    exit 0;
fi
#
# A * or ? is evaluated in the "for loop", so we need to replace it
#
_NETCONFIG_DNS_POLICY=`echo "$_NETCONFIG_DNS_POLICY" | \
        sed 's/\*/__ALL__/g' | sed 's/\?/__ONE__/g'`

sf=0
for POL in $_NETCONFIG_DNS_POLICY; do
    case "$POL" in
    (NetworkManager)
        if [ "x$NETWORKMANAGER" = "xyes" ] ; then
            debug "Use NetworkManager policy merged settings"
            CFG="$STATEDIR/NetworkManager.netconfig"
            if [ -r "$CFG" ] ; then
                get_dns_settings "$CFG"
            fi
            break
        fi
    ;;
    (STATIC)
        debug "Keep Static"
        DNS_SEARCHLIST="$DNS_SEARCHLIST $NETCONFIG_DNS_STATIC_SEARCHLIST"
        DNS_SERVERS="$DNS_SERVERS $NETCONFIG_DNS_STATIC_SERVERS"
    ;;
    (STATIC_FALLBACK)
        debug "Static Fallback"
        sf=1
    ;;
    (*)
        #
        # revert the replacement; now we want the evaluation
        #
        POL=`echo "$POL" | sed 's/__ALL__/*/g' | sed 's/__ONE__/?/g'`
        debug "Other: $POL"
        for IFDIR in $STATEDIR/$POL; do
            test -d "$IFDIR" -a \
                 -d "/sys/class/net/${IFDIR##*/}" || continue
            # proceed every interface we find with this match
            manage_interfaceconfig  "$IFDIR"
        done
    ;;
    esac
done
...

This tells us that we can use the values auto, STATIC, STATIC_FALLBACK, NetworkManager and /sys/class/net/ Interfaces ( with * and ? wildcards ).

The Cause

What it also tells us is that the default auto is translated to STATIC_FALLBACK NetworkManager.

STATIC_FALLBACK only uses the value in NETCONFIG_DNS_STATIC_SEARCHLIST if the NetworkManager does not provide a value.

Excerpts from /etc/netconfig.d/dns-resolver

...
if [ $sf -eq 1 -a -z "$DNS_SEARCHLIST" ]; then
    DNS_SEARCHLIST="$NETCONFIG_DNS_STATIC_SEARCHLIST"
fi
...

The Solution

Change the configuration in NETCONFIG_DNS_POLICY from STATIC_FALLBACK to STATIC

Excerpt from /etc/sysconfig/network/config

NETCONFIG_DNS_POLICY="STATIC NetworkManager"

Et voila! Working hostname search.

Summary

To use a static domain search configure your search:

Excerpt from /etc/sysconfig/network/config

NETCONFIG_DNS_STATIC_SEARCHLIST="my.domain.tld"

And then configure netconfig to keep static configurations even when oder modules provide the information:

Excerpt from /etc/sysconfig/network/config

NETCONFIG_DNS_POLICY="STATIC NetworkManager"
Share
(Visited 35 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *

No comments yet

Avatar photo
43,783 views