Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have Ubuntu 11.10 running on VirtualBox and I've set up a virtual named server.
I'm able to access this site from Windows 7, but I'm not able to access the site from Ubuntu.

My HOSTS file is located in /etc/ folder and looks like this:       localhost       ubuntu-VirtualBox

But whenever I try to access from the server, I get redirected to a site saying that this domain is for sale.

What could be the cause of the hosts file not working?


This is my /etc/nsswitch.conf

# /etc/nsswitch.conf
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.

passwd:         compat
group:          compat
shadow:         compat

#hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4
hosts:          files dns
networks:       files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis
share|improve this question
Is your file really named 'HOSTS'? It should be lower-case: /etc/hosts – rvs Jan 29 '12 at 10:01
No, it's lowercase, I just used uppercase here to make it stand out. – Steven Jan 29 '12 at 11:44
up vote 9 down vote accepted

First, check that nsswitch.conf is correct:

$ grep hosts /etc/nsswitch.conf
hosts:          files dns

Make sure that it says "files dns", otherwise it will not look in your hosts file before asking DNS.

If it is correct in nsswitch I have before seen that an invisible character somehow got into my hosts file, causing it to look perfectly normal but the invisible character made it not work.
So try deleting the line and then create it again - by hand, don't paste.

Next thing you can try is to test what it looks it up for by pinging:

$ ping
PING ( 56(84) bytes of data.

If you see the correct IP address there, it does resolve correctly and your browser is the one causing trouble. Do not use host, dig or nslookup, they ignore /etc/hosts! Use ping to have the IP address resolved as most applications would see it.

share|improve this answer
Thanks. I change it, but I still get the same result. If I ping, I get the following message: ping: unknown host – Steven Jan 29 '12 at 11:48
@Steven: Are you trying to ping the full URL Ping only the name – Khaled Jan 29 '12 at 12:02
@Khaled, Ah. Yes, that worked. – Steven Jan 29 '12 at 12:12
@Steven: So, the name should be resolvable now from the browser also. – Khaled Jan 29 '12 at 12:36
Invisible character. Thanks. Been banging my head against the wall for an hour now. – Swader Jul 22 '13 at 1:54

Run curl -Iv

You should get something like (plus a bunch more lines):

* About to connect() to port 80
*   Trying connected
* Connected to ( port 80
> HEAD / HTTP/1.1
> User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
> Host:
> Accept: */*
< HTTP/1.1 200 OK

Actually, here's a thought: are you hitting "" or ""? If it's the latter, you don't have an entry like that in your hosts file, and it will fail. If you're going to "" but your web server is redirecting that to "", that too will fail.

Note the "200 OK" at the end of my curl output snippet. If you're getting, say, a 301, you're getting redirected to someplace else by your web server configuration.

share|improve this answer

I had to log out and back in after I added the entries to /etc/hosts

share|improve this answer

You mentioned named. If you're expecting to use that DNS service, that needs to be in your resolv.conf file.

share|improve this answer

By default your file permissions of file "/etc/hosts" are 600. Try this command: sudo chmod 644 /etc/hosts

share|improve this answer

Your Answer


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.