How does configuring both `search` and `domain` in a `/etc/resolv.conf` effect DNS short name query sequence?

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux (RHEL)
    • 8
    • 7

Issue

  • What will the DNS search sequence be if both search and domain directives are configured in a /etc/resolv.conf?

Resolution

  • According to the implementation of Glibc, if domain and search directives are both used, only the last instance will be used for DNS queries.

Diagnostic Steps

  • The instance, /etc/resolv.conf shows that the domain directive is configured to example.com and followed by the search directive which is configured to redhat.com:

    [root@localhost etc]# cat resolv.conf
    nameserver 8.8.8.8
    domain example.com
    search redhat.com
    
    [root@localhost resolv]# nslookup www
    Server:     8.8.8.8
    Address:    8.8.8.8#53
    
    Non-authoritative answer:
    www.redhat.com  canonical name = ds-www.redhat.com.edgekey.net.                 <----- Only the last instance, "search" is used for the DNS query.
    ds-www.redhat.com.edgekey.net   canonical name = ds-www.redhat.com.edgekey.net.globalredir.akadns.net.
    ds-www.redhat.com.edgekey.net.globalredir.akadns.net    canonical name = e3396.dscx.akamaiedge.net.
    Name:   www.example.com 
    Address: 184.xx.xx.xx
    Name:   www.example.com 
    Address: 00:00:00:00:00:aa
    Name:   www.example.com 
    Address: 00:00:00:00:00:aa
    
  • In another example, the search directive is configured and followed by the domain directive:

    [root@localhost etc]# cat resolv.conf
    nameserver 8.8.8.8
    search redhat.com
    domain example.com
    
    [root@localhost resolv]# nslookup www
    Server:     8.8.8.8
    Address:    8.8.8.8#53
    
    Non-authoritative answer:
    Name:   www.example.com                          <------- Only the last instance, "domain" is used for the DNS query.
    Address: xxx.xxx.xxx.xxx
    Name:   www.example.com
    Address: xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
    

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments