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

Solution Unverified - Updated -

Environment

  • Red Hat Enterprise Linux 8
  • Red Hat Enterprise Linux 7

Issue

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

Resolution

  • If "domain" and "search" directives are both used, only the last instance will be used for DNS queries.

Root Cause

  • According to the implementation of Glibc, If both "search" and "domain" configurations are mixed-used, only the last instance of the configuration will be used for DNS queries.

Diagnostic Steps

  • The following example of /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:   e3396.dscx.akamaiedge.net
Address: 184.28.66.67
Name:   e3396.dscx.akamaiedge.net
Address: 2600:1417:1800:19a::d44
Name:   e3396.dscx.akamaiedge.net
Address: 2600:1417:1800:18b::d44
  • We can see another example. The "search" directive is configured and followed by the "doamin" 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.