I‘m using CentOS Linux server version 5.x/6.x+. How do I configure a system so that the DNS resolver will append search path extensions to hostnames that have dots in them? For example, my domain name is test.com. when I query for mail hostname it should append .test.com and return the IP address of mail.test.com hostname.

You can easily configure the domain search list. The search list is normally determined from the local domain name; by default, it contains only the local domain name.
Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Linux
Est. reading time 2 mintues
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.


Open /etc/resolv.conf file, enter:
# vi /etc/resolv.conf
$ sudo vi /etc/resolv.conf
Now add search path as follows for sweet.home domain:
search sweet.home
Save and close the file.

A note about modern Linux distro

You need to use the nmcli command as follows”
nmcli connection modify br0 ipv4.dns-search "sweet.home"
nmcli connection modify br0 ipv6.dns-search "sweet.home"

Ensure you replace br0 with your interface name and “sweet.home” with your actual search domain name.

Optional ntdots configuration

Please note that you may also need to use ndots:n option to sets a threshold for the number of dots which must appear in a name given to query 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. For example set ndots to 2 as follows, to answer nslookup f1.mail query to get IP for f1.mail.in.test.com hostname:
## config file - /etc/resolv.conf ##
options ndots:2
search sweet.home

Save and close the file. Again replace sweet.home as per your domain name.

Test it

Use host command or dig command as follows:

$ host f1
$ host mail
$ dig smtp
$ ping router


  • The search list is currently limited to six domains with a total of 256 characters.

Help /etc/resolv.conf file overwritten by dhclient on a Linux based system

You may find that /etc/resolve.conf is being generated and overwritten by dhcp client, so any changes made to /etc/resolv.conf file will be subsequently overwritten. See how to fix this issue by reading the following tutorial:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 4 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
4 comments… add one
  • vinod Jul 9, 2007 @ 11:13

    What all the Daily Activities need to be done on a freebsd server,

  • Hari May 8, 2010 @ 5:54

    I am using CentOS 5.3 and for me /etc/resolve.conf is being generated by /sbin/dhclient-script, so any changes done to this file will be subsequently overwritten. I am trying to find a different way to add the search order.

  • Henry Jun 5, 2012 @ 1:04

    In regards to Hari’s question, I guess this was never answered, but I’ll answer it here because this page appears to be one of the first that pops up when I Google this particular question.

    These instructions work on my CentOS 5.6 workstation.

    The reason /etc/resolv.conf is being overwritten is because you’ve configured your DHCP client to get automatically obtain DNS information from the “provider”, thereby overwriting your changes everytime you reboot or restart your network services.

    To stop this, edit the following file:
    And set “PEERDNS=no”

    You should now be able to update /etc/resolv.conf with additional “search [domain]” lines and it should stick, even after rebooting.

    The following page provides additional information:

    If you’re running KDE, you can go into System > Administration > Network > Devices and double-click the appropriate eth device. Then uncheck “Automatically obtain DNS information from provider”. Go back to the “DNS” tab and add your additional domain suffixes separated by spaces. Save and exit. Restart your network services using “/etc/init.d/network restart” or reboot.

    Hopefully this helps someone.

  • Wellington Torrejais da Silva Mar 11, 2016 @ 17:22


Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum