[illumos-Developer] DHCP, DNS domains and search lists in /etc/resolv.conf

Guido Berhoerster guido+illumos.org at berhoerster.name
Tue May 17 13:22:30 PDT 2011


* Hans Rosenfeld <rosenfeld at grumpf.hope-2000.org> [2011-05-17 20:32]:
> Hi,
> 
> I got a problem with DHCP-supplied DNS domain names and NWAM.
> 
> The dhcp server at work gives me three domain names: foo.bar.com,
> bar.com and baz.com. On OpenSolaris b134 that resulted in a single
> "domain foo.bar.com" statement in /etc/resolv.conf.  
> 
> Since I upgraded to OI, which includes the new NWAM stuff that was
> integrated into ONNV about a year ago, that results in three domain
> statements in /etc/resolv.conf:
> 
> domain foo.bar.com
> domain bar.com
> domain baz.com
> nameserver ...
> 
> Resolv.conf(4) states that only one domain or search statement is
> allowed, and that the last one found is used if there are more than one.
> So I now get a DNS domain and search list of "baz.com", and the
> other domains are ignored.
> 
> I just hacked together a quick fix which should give some saner
> behaviour. If only one DNS domain name is provided, a domain statement
> will be created in /etc/resolv.conf, otherwise a search statement with
> all domains will be used.
> 
> Please take a look at the attached patch and tell me how my chances are
> to get this fix in :)
> 
> 
> Hans
> 
> 
> -- 
> %SYSTEM-F-ANARCHISM, The operating system has been overthrown

> diff -r 1c4c7dff49cd usr/src/cmd/svc/milestone/net-loc
> --- a/usr/src/cmd/svc/milestone/net-loc	Wed Mar 30 16:30:27 2011 +0200
> +++ b/usr/src/cmd/svc/milestone/net-loc	Tue May 17 21:15:38 2011 +0200
> @@ -204,7 +204,12 @@
>  		'dhcp')
>  			DNS_DOMAIN=`get_dhcpinfo DNSdmain`
>  			DNS_SERVERS=`get_dhcpinfo DNSserv`
> -			# No DNS search info for IPv4
> +			# construct DNS search info for IPv4
> +			echo $DNS_DOMAIN | read first_domain other_domains
> +			if [ -n "$other_domains" ]; then
> +				DNS_SEARCH=$DNS_DOMAIN
> +				DNS_DOMAIN=""
> +			fi
>  			;;
>  		'*')
>  			echo "Unrecognized DNS configsrc ${configsrc}; ignoring"

This only works by coincidence because /sbin/sh is ksh93 which
runs the "read" in the "echo ... | read ..." pipe in the current
shell and not a subshell. A portable solution would be

set -- $DNS_DOMAIN
if [ $# -gt 1 ]; then
        DNS_SEARCH="${DNS_DOMAIN}"
        unset DNS_DOMAIN
fi


-- 
Guido Berhoerster



More information about the Developer mailing list