2

I added an entry to my hosts file for the development of a website.

I put a new line in /etc/hosts

xx.xx.xx.xx www.mysite.com

But even after a reboot when I use chrome or firefox the host name is not resolved to the IP I put in the file.

I'm running Fedora 14 x86_64.

9
  • Have you checked /etc/nsswitch.conf?
    – Karlson
    Feb 5, 2012 at 16:09
  • Yes. #hosts: db files nisplus nis dns hosts: files mdns4_minimal [NOTFOUND=return] dns
    – ClemPi
    Feb 5, 2012 at 16:13
  • 1
    The line is commented. Uncomment it and put files before db. Feb 5, 2012 at 16:16
  • 1
    How about posting it?
    – Karlson
    Feb 5, 2012 at 16:27
  • 1
    If you are running on the same machine as the hosts file can you post getent hosts www.mysite.com
    – Karlson
    Feb 5, 2012 at 17:00

5 Answers 5

3

If your browser connects through a proxy, the proxy makes the name resolution, not the machine running your browser, so you'll need to put this website in the “no proxy” list.

3
  • I think there is no proxy, but I'm sure there is a DHCP server.
    – ClemPi
    Feb 6, 2012 at 21:18
  • @ClemPi The DHCP may be returning a proxy setting. Check if your browsers are running them. Feb 6, 2012 at 21:23
  • How can I do that ?
    – ClemPi
    Feb 6, 2012 at 22:27
2

Hum, don't you have /etc/resolv.conf?

There should be a line:

lookup file bind

Meaning the system's resolver will look in /etc/hosts (file) first and if it can't found will ask the configured name server(s) in the same file (bind is a DNS server). The order is important.

No need to reboot it will look in the /etc/resolv.conf each time to know how to resolve names.

Usually the dhcp client will override the content of /etc/resolv.conf, one some systems (most? all?) you can create /etc/resolv.conf.tail, its content will be appended to /etc/resolv.conf after the override.

So unless I'm all wrong or your system is different, you know how to fix it now :)

EDIT: on some systems now they seem to use /etc/nsswitch.conf for the resolution order, so not everything is in /etc/resolv.conf.

EDIT2: "The introduction of the GNU C Library 2.0 was accompanied by the introduction of the “Name Service Switch” (NSS). Refer to man 5 nsswitch.conf and The GNU C Library Reference Manual for more details." Seems like another GNU weirdness, argh. There used to be one way to do stuff, which made learning and administration easier. Sounds like windows practices (don't care about others, everyone uses our stuff).

1

Some linux distros also use /etc/host.conf to order the resolver's lookups.

The default seems to be order bind,hosts, which would tell your resolver to use DNS before the hosts database.

If you have an /etc/host.conf file, check the order statement.

1
  • Thank you for your answer, but my host.conf file contains : multi on and order hosts,bind
    – ClemPi
    Feb 5, 2012 at 18:38
1

Something is caching the wrong information on the way. Try nscd -i hosts and try again.

5
  • Does nscd keep a cache across reboots? I thought it was in memory only. Feb 5, 2012 at 22:48
  • This command doesn't do anything and return 0.
    – ClemPi
    Feb 6, 2012 at 19:02
  • @Gilles it depends on the distribution. RH surprised me by making it reboot-save, whereas in SLES a restart of nscd will clear all caches.
    – Nils
    Feb 6, 2012 at 21:58
  • @ClemPi the command clears the hosts-cache in the Name Service Cache Daemon. A return value of zero indicates that it worked without error. So did you retry?
    – Nils
    Feb 6, 2012 at 22:00
  • Yes and it still fail.
    – ClemPi
    Feb 6, 2012 at 22:27
0

ALL common versions of *NIX use a file /etc/nsswitch.conf to determine the order that files are queried in.

The line:

    hosts:          files dns myhostname mdns4_minimal [NOTFOUND=return] 

is where this is done. In many instatllions "dns" is listed ahead of "files" like this:

    hosts:          dns files myhostname mdns4_minimal [NOTFOUND=return] 

Try changing it to have "files" first like in the first example.

The change affects the system instantly. If you are running bind or some form of DNS locally, stop/restart it so that it will flush its own cache.

We process billions of transactions daily and found that bind (as much as I love it) and no dns caching server or number of them has been able to keep up with our lookups, so we had to go to using our /etc/hosts file for some of what we do.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .