What is the difference between /etc/hosts and /etc/resolv.conf? Also, is there a good documentation that explain all these configuration files.

Thank you. Bala

4 Answers 4


resolv.conf specifies the nameservers for resolver lookups, where it will actually use the DNS protocol for resolving the hostnames.
Typically the hosts file is used for administrative purposes, such as backend and internal functions, which is substantially more isolated in scope, as only the local server will reference it.

/etc/nsswitch.conf specifies the lookup order with the hosts entry.

If this does not answer your question, please clarify further.

Look at the following manpages:


resolv.conf specifies nameservers in order of search preference.

hosts overrides all nameservers by mapping urls/shortnames to IPs.

  • /etc/resolv.conf: Lists nameservers that are used by your host for DNS resolution. If you are using DHCP, this file is automatically populated with DNS record issued by DHCP server.
  • /etc/hosts/: It is just a static lookup method for resolution.
  • /etc/nsswitch.conf: It defined order of resolution. Who should it consult first for resolution, a DNS or a host file? For example, if the file has following configuration hosts: files dns then /etc/hosts file will be checked first for resolution, if domain is still un-resolvable, DNS will then be consulted.

/etc/hosts: Mapping between IP addresses & hostnames, for name resolution. localhost.localdomain localhost myhost.domain.org myhost

/etc/nsswitch.conf: Sources that must be used by various system library lookup functions.

passwd: files nisplus nis
shadow: files nisplus nis
group: files nisplus nis
hosts: files dns nisplus nis

/etc/resolv.conf: Domain names that must be appended to bare hostnames, and DNS servers that will be used for name resolution.

search domain1.org domain2.org

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .