Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
    
Have you checked /etc/nsswitch.conf? –  Karlson Feb 5 '12 at 16:09
    
Yes. #hosts: db files nisplus nis dns hosts: files mdns4_minimal [NOTFOUND=return] dns –  ClemPi Feb 5 '12 at 16:13
1  
The line is commented. Uncomment it and put files before db. –  Nikhil Mulley Feb 5 '12 at 16:16
1  
How about posting it? –  Karlson Feb 5 '12 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 '12 at 17:00

4 Answers 4

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).

share|improve this answer

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.

share|improve this answer
    
Thank you for your answer, but my host.conf file contains : multi on and order hosts,bind –  ClemPi Feb 5 '12 at 18:38

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

share|improve this answer
    
Does nscd keep a cache across reboots? I thought it was in memory only. –  Gilles Feb 5 '12 at 22:48
    
This command doesn't do anything and return 0. –  ClemPi Feb 6 '12 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 '12 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 '12 at 22:00
    
Yes and it still fail. –  ClemPi Feb 6 '12 at 22:27

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.

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.