Lets say the /etc/resolv.conf has the following..

search x.com y.com

For a resolution "ping foo" I see that the resolver first tries the FQDN with configured search domains (ie: foo.x.com, foo.y.com) and then tries the default "foo."

Is this the behavior consistent across all *nix platforms ? Or some implementations can do the short name resolution in the root domain first (ie: "foo.") ?


from the resolv.conf manpage:

options ndots:n
                 Sets a threshold for the number of dots which must
                 appear in a name given to res_query(3) (see
                 resolver(3)) before an initial absolute query will be
                 made.  The default for n is 1, meaning that if there
                 are any dots in a name, the name will be tried first as
                 an absolute name before any search list elements are
                 appended to it.  The value for this option is silently
                 capped to 15.

Thus if resolv.conf has options ndots:0 it will attempt a root domain search immediately and not try any search list domains. The manpage seems to indicate it should try searching if the query domain doesn't exist in the root, but my resolver didn't do that when testing. Otherwise if there is no dot, it tries search elements in order first, then the root domain after exhausting the list. Note, you can set search . which puts the root domain in the search list.

Another thing to note is your name resolution may never make it to resolv.conf if the request is satisfied by another nsswitch.conf mechanism before it gets there.

  • Thanks. I am running ubuntu 14.04. Setting ndots:0 triggers an initial absolute query. If that fails the resolver does continue and tries with the other search domains. But I am wondering if this behavior is consistent since you observed your resolver not trying other search domains if the first one fails. What *nix/resolver are you using ?
    – Manohar
    Dec 30 '15 at 23:26
  • debian jessie seems to stop. freebsd 10.2 applies search after nxdomain on the root. Tested by calling host foo<n> with tcpdump -vv -ni <if> 'port 53' running in another shell. That should result in using gethostbyname() and following the system name resolution rules. Dec 31 '15 at 6:01
  • About having the dot as the first entry in the search (ie: "search ."), it doesn't work for me. In fact with dot present in the search domain resolver is not sending out the absolute query at all.
    – Manohar
    Dec 31 '15 at 23:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.