Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Can the order in which an entry is looked up at the DNS or the hosts (/etc/hosts) be specified on Linux?

E.g.: If I specify DNS then hosts then the name should be resolved using DNS first, and hosts on fail.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Generally this is done with the /etc/resolv.conf and /etc/nsswitch.conf files. For determining the order, look at the "hosts" line of nsswitch.conf.

nsswitch.conf is where you configure the name service switching. This is a pretty standard one from a Debian Lenny system:

# /etc/nsswitch.conf
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.

# ...    

# HERE          vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv    
hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4
networks:       files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

resolv.conf lists your DNS servers and which domain names should be appended to the hostname by default. It's likely generated automagically by your DHCP client.

search lan
nameserver x.x.x.x
share|improve this answer
Thanks for your response.I will try this out –  rohit Jan 7 '10 at 9:41
A quick but very detailed and good answer, +1. –  John T Jan 7 '10 at 9:45
i'm pretty sure i remember putting the resolver order in resolv.conf once upon a time. the "order" keyword, i think, which is still used in host.conf. eg order hosts, bind, nis or order bind, hosts, nis. it's the same syntax tho "man resolv.conf" doesn't make any mention of the keyword. –  quack quixote Jan 7 '10 at 9:46
I was able to change the order in "hosts:" in nsswitch.conf Thanks a lot for your help. Your answer was very quick and to the point. –  rohit Jan 7 '10 at 10:42

Look for /etc/host.conf. man host.conf for more info.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.