Can the order in which a DNS entry is looked up be changed?

2

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.

rohit

Posted 2010-01-07T09:33:01.243

Reputation:

Answers

4

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

quack quixote

Posted 2010-01-07T09:33:01.243

Reputation: 37 382

A quick but very detailed and good answer, +1. – John T – 2010-01-07T09:45:52.700

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 – 2010-01-07T09:46:08.300

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. – None – 2010-01-07T10:42:16.987

0

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

Jürgen A. Erhard

Posted 2010-01-07T09:33:01.243

Reputation: 375