Can anybody explain to me about the dns-search directive in /etc/network/interfaces file:

iface eth0 inet static
    dns-search example.com

Is it mandatory? And how can I configure it?

  • 1
    I personally disabled this on my server, because I use IPv6, and when an address (f.e. hello.com) I was trying to connect to didn't support IPv6, the system tried to resolve hello.com.example.com instead and that yielded an IPv6 of the example.com as the result (not IPv4 address of hello.com as expected). I wrote about it in more detail here: daysleeper.cz/…
    – arrange
    Mar 9, 2013 at 11:28

2 Answers 2


dns-search determines which domain is appended for dns lookups.

Normally you will specify here the same domain as returned by hostname -f.

For detailed information see the following quote from man resolv.conf:

search Search list for host-name lookup.
    The  search  list  is  normally  determined from the local domain name; by
    default, it contains only the local domain name.  This may be changed by listing
    the desired domain search path following the search keyword with spaces or tabs
    separating  the  names.  Resolver queries having fewer than ndots dots (default
    is 1) in them will be attempted using each component of the search path in turn
    until a match is found.  For environments with multiple  subdomains  please read
    options ndots:n below to avoid man-in-the-middle attacks and unnecessary traffic
    for the root-dns-servers.  Note that this process may be slow and will generate
    a lot of network traffic if the servers for the  listed  domains  are not local,
    and that queries will time out if no server is available for one of the domains.

    The search list is currently limited to six domains with a total of 256 characters.
  • 3
    Why isn't the dns-search directive mentioned in the man page for the interfaces file? (manpages.ubuntu.com/manpages/utopic/en/man5/interfaces.5.html)
    – odigity
    Jan 12, 2015 at 19:41
  • 5
    @odigity, I think it is because it is an option passed to resolvconf, and not an internal feature of ifup.
    – Tiago
    Sep 28, 2015 at 8:55
  • How does this all hang together with search order as defined in /etc/nsswitch.conf ?? Sounds like multiple cures for the same problem Mar 29, 2017 at 8:56

I also found this in the README.gz located in /usr/share/doc/resolvconf on Ubuntu 14.04. It provides a bit more clarity.

Beware of the resolv.conf file being managed by the service resolvconf.

dns-search appears to be a necessary line in the stanza of a logical interface.

  3.4 ifupdown
    * Remove any "up" or "down" commands from /etc/network/interfaces
      that futz with /etc/resolv.conf and remove any scripts from
      /etc/network/if-*.d/ that futz with /etc/resolv.conf.
    * For each inet static logical interface through which a nameserver is
      accessible, add lines like the following to /etc/network/interfaces .

          dns-search foo.org bar.com

      Other recognized option words are 'dns-domain' and 'dns-sortlist'.
      These option names correspond to the option names used in the
      resolv.conf file with one exception: whereas one lists several
      nameserver addresses in /etc/resolv.conf on several "nameserver"
      lines, here one should list them all on a single "dns-nameservers"
      line.  See resolv.conf(5) for more information.  The lines entered
      in /etc/network/interfaces will be added to the resolver
      configuration file (without the "dns-" prefix, of course) when a
      physical interface is brought up as that logical interface.
      Note that the resolver configuration is updated AFTER all the "up"
      commands have been run; therefore "up" commands cannot make use of
      nameservers listed on "dns-nameservers" lines in the same logical
      interface stanza.  Changing this will require modifying ifupdown
      so that it talks to resolvconf; currently resolvconf hooks into
      ifupdown using the script /etc/network/if-up.d/000resolvconf. Note
      too that scripts in /etc/network/if-up.d/ CAN make use of the
      added nameservers because those scripts run after 000resolvconf.

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.