This discussion is archived
4 Replies Latest reply: Jul 27, 2012 2:39 AM by 422096 RSS

Entry in /etc/hosts not reachable due to modifications in /etc/resolv.conf

422096 Newbie
Currently Being Moderated
Good morning,
My "/etc/hosts" file looks as follows:
Prompt# cat /etc/hosts
<shortcut> xxx.xxx.xxx.xxx
My "/etc/resolv.conf" originally looked as follows:
Prompt# cat /etc/resolv.conf
domain <own_domain>
nameserver 10.0.0.6
When I tried:
Prompt# ping <shortcut>
this was working fine.

Now when I modify my "/etc/resolv.conf" into:
domain <own_domain>
nameserver 10.0.0.1
the ping seems not to work anymore.

Does anybody know how I can force my machine to check the /etc/hosts file without first checking DNS when I do a "ping <something>"?
Thanks
Dominique
  • 1. Re: Entry in /etc/hosts not reachable due to modifications in /etc/resolv.conf
    user171873 Explorer
    Currently Being Moderated
    I'm not sure I understand all of this about the DNS change but with respect to reading /etc/hosts before the DNS you should check the "hosts" line in the /etc/nsswitch.conf file. If "files" appears before dns in that line, the system should consult the /etc/hosts file before the DNS. The manual nsswitch.conf manual page describes this file in detail. Perhaps more detail than you'd like in fact.

    You should also be aware that there is a name service cache which can satisfy requests before consulting any name service. If you change the nsswitch.conf file the cache may still contain data from the old configuration. If you change the nsswitch.conf "hosts" line, you may need to do a "nscd -i hosts" command to clear the hosts cache before you can see the result of the change.
  • 2. Re: Entry in /etc/hosts not reachable due to modifications in /etc/resolv.conf
    Nik Expert
    Currently Being Moderated
    Hi.

    Generaly */etc/hosts* file have format:

    # IP_Address hostname

    XXX.XXX.XXX.XXX shortcat


    Possible, you hae wrong /etc/hosts

    Regards/
  • 3. Re: Entry in /etc/hosts not reachable due to modifications in /etc/resolv.conf
    422096 Newbie
    Currently Being Moderated
    Hello,
    It is now more than a week that I didn't hear from my collegues after I informed them about the "nscd -i" command. It seems that this command cleared their DNS cache and as a result, has solved their problem.

    Thanks for the support
    Dominique
  • 4. Re: Entry in /etc/hosts not reachable due to modifications in /etc/resolv.conf
    422096 Newbie
    Currently Being Moderated
    Good morning,
    I have finally received feedback from my collegues.
    It seems that the permissions of the file "/etc/nsswitch.conf" were wrong, causing the machine not to read that file.
    So it seems that the following happened:
    User requested "ping <other_machine>", and the machine did the following:
    - First try to read /etc/nsswitch.conf. As the permissions were wrong, this did not succeed
    - Then read the /etc/resolv.conf file. As this file existed, the DNS was used for retrieving the mentioned <other_machine>, which failed.
    - The "ping" command failed.

    Now the problem is solved by setting the permissions of "/etc/nsswitch.conf" to:
    -rw-r--r-- 1 root root 1696 Jan  3  2012 /etc/nsswitch.conf
    Thanks again for your support

Legend

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