/etc/hosts file not being used before DNS server query

12,481

Turns out I am a massive buffoon;

The host command just seems to ignore the /etc/hosts file and perform queries against your configured DNS servers directly. If I ping www.somesite.com I am using my /etc/hosts file entry, and after installing wireshark I can see that chrome is too.

Hope that helps someone!

Share:
12,481

Related videos on Youtube

jwbensley
Author by

jwbensley

Updated on September 18, 2022

Comments

  • jwbensley
    jwbensley over 1 year

    I have upgraded to Ubuntu 12.10 and I have made entries in /etc/hosts, but instead of looking into the hosts file, queries to my configured DNS server are being made first.

    How can I make Ubuntu query the /etc/hosts file first?

    Thanks.

    • NickTux
      NickTux over 11 years
      Is this helps ?
    • jwbensley
      jwbensley over 11 years
      Thanks for the suggestion NikTh but that's not my problem. My entires aren't being removed, they are always there, they just aren't being used. If I execute host www.somesite.com where "www.somesite.com" is an entry in my hosts file, I seem to always get the IP given out by my DNS server which is different to that in my hosts file. Sometimes it works, mostly it doesn't though.
    • Reza Zamani
      Reza Zamani over 11 years
      Did you check if files is listed BEFORE dns under hosts in /etc/nsswitch.conf? This is the definition of the order in which they will be queried.
    • jwbensley
      jwbensley over 11 years
      Good suggestion; cat nsswitch.conf | grep hosts hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4