3

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:

127.0.0.1       localhost
127.0.1.1       ubuntu-VirtualBox
192.168.0.97     mysite.com

But whenever I try to access mysite.com 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?

Update

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
JdeBP
  • 3,970
  • 17
  • 17
Steven
  • 275
  • 2
  • 9
  • 21

5 Answers5

9

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 mysite.com
PING mysite.com (192.168.0.97) 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.

bishop
  • 1,077
  • 10
  • 16
Frands Hansen
  • 4,617
  • 1
  • 16
  • 29
1

Run curl -Iv http://mysite.com

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

* About to connect() to mysite.com port 80
*   Trying 192.168.0.97... connected
* Connected to mysite.com (192.168.0.97) 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: mysite.com
> Accept: */*
>
< HTTP/1.1 200 OK

Actually, here's a thought: are you hitting "mysite.com" or "www.mysite.com"? 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 "mysite.com" but your web server is redirecting that to "www.mysite.com", 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.

cjc
  • 24,533
  • 2
  • 49
  • 69
1

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

user155875
  • 11
  • 1
0

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

Magellan
  • 4,431
  • 3
  • 29
  • 53
0

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