What is the difference between search domains and nameservers? [closed]

I've usually seen two kinds of entries in /etc/resolv.conf on certain servers. The domain-name-servers entry specifies which DNS to use for resolving hostnames to IP addresses. Recently I saw an entry for search IP_ADDRESS. So here's my question. What's the difference between a nameserver and a search domain?


Solution 1:

the search indicate what domain(s) to append to your host name in a search. for example if you run this command :

ping myserver

if you do not have anything in the search domain, it will search for "myserver" in your hostfile, and if nothing there, it will return

unknown host

but if you add search mydomain.com

then the same ping would return

64 bytes from myserver.mydomain.com (some ip): icmp_seq=1 ttl=62 time=415 ms

(provided the "myserver.mydomain.com actually exist, and reply to ping requests)

nameserver on the other hand is the IP address of your actual DNS server, where you look up all hostnames that is not in your hosts file.

edit: added some more details, and the 2nd part of the question (nameserver)

Solution 2:

  • A name server entry tells the system what name servers to ask for name resolution.
  • A search domain provides a default domain name for searches. If you provide example.net and example.com as search domains and try to contact the host server1, the system will look for server1.example.net and server1.example.com without you having to type out the full domain.