Do entries in local 'hosts' files override both forward and reverse name lookups?

Solution 1:

Generally the hosts file will be used for both forward and reverse lookups. The preference on a Unix system this will depend on the order of entries in you nsswitch.conf file.

e.g. the line below will make the hosts file override DNS. Reversing the entries will make DNS override the hosts file.

hosts:      files dns

I am not sure if you can tune to order of preference on a windows system.

I have had a look at the source for ping in inetutils-20071127 (the version installed on my Ubuntu 9.04 box) and the source seems to enable numeric only mode if you ping an IP address rather than a hostname:

                if (inet_aton(target, &whereto.sin_addr) == 1) {
                        hostname = target;
                        if (argc == 1)
                                options |= F_NUMERIC;

This could explain why you don't get a reverse lookup when you ping your host by IP address.

Solution 2:

I found a reference to changing registry entries to alter the name resolution order on Windows:

http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=963485

Quoting from there:

By default, Windows checks name resolution providers in the following order:

Local, (NetBT local name cache), Hosts, DNS, NetBT (WINS).

You want the order to be Hosts, DNS, Local, NetBT.

In what follows, lower numbers are higher priority.

The following registry keys in

HKEY_LOCAL_MACHINE\SYSTEM\CurentControlSet\ServicessTcpip\ServiceProvider

need to be modified.

DnsPriority= 0x3e8 (Decimal: 1000)
HostsPriority= 0x1f4 (Decimal: 500)
LocalPriority= 0x5dc (Decimal: 1500)
NetbtPriority= 0x7d1 (Decimal: 2001)

Solution 3:

The /etc/host.conf file specifies which order is used for discovering IP addresses. Mine contains the following by default:

#
# /etc/host.conf
#

order hosts,bind
multi on

This means that the hosts file is always checked first and then DNS (bind).

If nis is not specified here then it will never look at /etc/nsswitch.conf.

Documentation link: http://tldp.org/LDP/nag/node82.html