This discussion is archived
1 2 Previous Next 19 Replies Latest reply: Aug 2, 2012 1:03 PM by TommyReynolds RSS

/etc/hosts is ignored.

946717 Newbie
Currently Being Moderated
nslookup would not check against /etc/hosts, the file gets ignored.

tried the following in /etc/nsswitch.conf:
hosts: files [NOTFOUND=continue] dns
or
hosts: files dns

Also, in /etc/host.conf
order files,bind

Whatever I do, /etc/hosts still could not get checked, Would you please let me know why?



Thanks!
  • 1. Re: /etc/hosts is ignored.
    946717 Newbie
    Currently Being Moderated
    Can anybody please pick up this issue?
  • 2. Re: /etc/hosts is ignored.
    Avi Miller Guru
    Currently Being Moderated
    943714 wrote:
    nslookup would not check against /etc/hosts, the file gets ignored.
    Correct. nslookup only checks your configured nameservers (in /etc/resolv.conf) not your local /etc/hosts file. It's not designed to do that. If you want to query your local /etc/hosts file, you should use getent instead.
  • 3. Re: /etc/hosts is ignored.
    946717 Newbie
    Currently Being Moderated
    Okay. But what if I don't have DNS access, and meanwhile an anpplication needs to get a host name resolved? I would have to add the entry in /etc/hosts right the way. By adding the entry in /etc/hosts, should the application be able to resolve the name? does an application usually resolve a host name by checking /etc/hosts or dns entries

    Thanks a lot for your response.

    Edited by: 943714 on Aug 1, 2012 6:46 PM

    Edited by: 943714 on Aug 1, 2012 6:49 PM

    Edited by: 943714 on Aug 1, 2012 7:00 PM
  • 4. Re: /etc/hosts is ignored.
    Avi Miller Guru
    Currently Being Moderated
    943714 wrote:
    Okay. But what if I don't have DNS access, and meanwhile an anpplication needs to get a host name resolved? I would have to add the entry in /etc/hosts right the way. By adding the entry in /etc/hosts, should the application be able to resolve the name? does an application usually resolve a host name by checking /etc/hosts or dns entries
    That depends on the application. If it's written properly, it will check the order in /etc/nsswitch.conf and resolve names appropriately. You would need to test using the target application.
  • 5. Re: /etc/hosts is ignored.
    Dude! Guru
    Currently Being Moderated
    Perhaps the confusion stems from not knowing the difference between /etc/hosts and DNS.

    The hosts file maps hostnames to IP addresses, but it is part of the operating system's Internet Protocol (IP) implementation. It is not DNS.

    DNS is a network service or application that typically uses Bind (named) and communicates over TCP port 53. DNS provides name resolution in a global or local network.

    The /etc/hosts file can only work for the local machine and cannot be queried by other machines in the network.

    In order for your system to find a DNS server you need to add an entry in the /etc/hosts file, e.g. dnsserver1 -> 192.168.1.53, or address the nameserver directly an entry in /etc/resolv.conf specifying the IP address of your DNS server. A DNS server can also be installed and queried on the local machine.

    A simple test to make sure your /etc/hosts file works is the "ping" utility, for instance, ping localhost, ping mymachine.example.com.

    Edited by: Dude on Aug 2, 2012 1:59 AM
  • 6. Re: /etc/hosts is ignored.
    Avi Miller Guru
    Currently Being Moderated
    Dude wrote:
    In order for your system to find a DNS server you need to add an entry in the /etc/hosts file, e.g. dnsserver1 -> 192.168.1.53, or address the nameserver directly using the IP address. A DNS server can also be installed and queried on the local machine.
    This is not true: The only way to configure a DNS server is to add the IP address of the server as a nameserver entry in /etc/resolv.conf on a Linux machine. There is no need to add anything to /etc/hosts.
  • 7. Re: /etc/hosts is ignored.
    Dude! Guru
    Currently Being Moderated
    That's correct. I was under the wrong impression you could actually put a name in /etc/resolv.conf that would be resolved using /etc/hosts file. I think it was possible in another operating system, but certainly does not work in Linux. It makes me wonder though if that is on purpose and why it shouldn't use /etc/hosts. Anyway, I will correct my previous post. Thanks for pointing this out!

    Edited by: Dude on Aug 2, 2012 1:55 AM
  • 8. Re: /etc/hosts is ignored.
    800381 Explorer
    Currently Being Moderated
    943714 wrote:
    Can anybody please pick up this issue?
    There is NO issue. From the "nslookup" man page (http://linux.die.net/man/1/nslookup):
    nslookup - query Internet name servers interactively
  • 9. Re: /etc/hosts is ignored.
    usr080678 Newbie
    Currently Being Moderated
    hello
    any A record entry in hosts file should resolve IP to host name and vise-verse regardless of OS version or vendor.
    however this for OS only, am not sure how your application refers those entries.

    you may put whole scenario it may help to understand and reply.

    :)

    Edited by: Soundar on Aug 2, 2012 4:00 AM
  • 10. Re: /etc/hosts is ignored.
    Dude! Guru
    Currently Being Moderated
    Well, the /etc/hosts file is not DNS and does not know about "A" records or other forms or DNS records. /etc/hosts is just another, local only method, of resolving a name to an IP address and vise versa.

    The problem/issue with my previous reply was that I though /etc/resolv.conf would also use /etc/hosts in order to resolve a hostname, but that was incorrect and /etc/resolv.conf requires the nameserver IP address.

    Other and older TCP/IP implemenations, if I remember correctly, allow to specify a name for the nameserver, but they were not Unix based.
  • 11. Re: /etc/hosts is ignored.
    usr080678 Newbie
    Currently Being Moderated
    hi dude,

    ideally i should have replid for actual poster, hosts file is alternate option for DNS which works within host only, IP and host name can be update in hosts file wherever we don't have DNS server as resolver.

    i assume he is trying to use hosts file from some application which may not be possible, if we get full scenario can look out.

    tc
  • 12. Re: /etc/hosts is ignored.
    800381 Explorer
    Currently Being Moderated
    Soundar wrote:
    hi dude,

    ideally i should have replid for actual poster, hosts file is alternate option for DNS which works within host only, IP and host name can be update in hosts file wherever we don't have DNS server as resolver.

    i assume he is trying to use hosts file from some application which may not be possible, if we get full scenario can look out.

    tc
    Of course it's possible. Offhand, I'm pretty certain that's exactly what gethostbyname() and getipnodebyname() do - go through /etc/nsswitch.conf and query the proper data store(s).

    The fact that nslookup does a N ame S erver LOOKUP means it deliberately ignores /etc/nsswitch.conf and therefor /etc/hosts.
  • 13. Re: /etc/hosts is ignored.
    946717 Newbie
    Currently Being Moderated
    I don't have a scenario. What I thought was this: when any application attempts to resolve a name, a.example.com, it will look for /etc/hosts first, then if it could not find any entry to match, then look for DNS based on the setting in /etc/nsswitch.conf: hosts: file dns. In this way, I can manually put an entry in /etc/hosts, if there is no such line in DNS. I understand /etc/hosts only works on local machine.

    So, if I could not immeidately update DNS, and also /etc/hosts get ignored, then how application could resolve a host name or ip address. That is why I got confused.
  • 14. Re: /etc/hosts is ignored.
    946717 Newbie
    Currently Being Moderated
    I don't have a scenario. What I thought was this: when any application attempts to resolve a name, a.example.com, it will look for /etc/hosts first, then if it could not find any entry to match, then look for DNS based on the setting in /etc/nsswitch.conf: hosts: file dns. In this way, I can manually put an entry in /etc/hosts, if there is no such line in DNS. I understand /etc/hosts only works on local machine.

    So, if I could not immeidately update DNS, and also /etc/hosts get ignored, then how application could resolve a host name or ip address. That is why I got confused.
1 2 Previous Next

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points