Difference between specifying IP in host file vs u

2019-07-04 16:57发布

问题:

Is there any difference between the following when a intranet URL in accessed in IE

Add an entry in drivers/etc/host file for a name and IP vs Use IP directly

e.g. it works with the following link if I have a host entry as (XYZ 10.0.10.200)

http://XYZ/SiteDirectory/ABC/Default.aspx

but when I tried to use IP instead of name

http://10.0.10.200/SiteDirectory/ABC/Default.aspx

It gives me 404 not found error

回答1:

Yes, there's a difference.

The web server is using HTTP/1.1 and "shared virtual hosting". When the client connects it sends an additional Host: header which contains the hostname part of the URL that the user supplied.

The web server looks at the header to find out which virtual host's data to serve.

In this case, the web server is configured to recognise and serve content from the "XYZ" domain, but doesn't know about any domain called 10.0.10.200



回答2:

Smells like the webserver is using virtual hosts, so that it serves different pages if the client went to "www.foo.com" or "www.bar.com", even though they have the same IP-address.



回答3:

As far as I can see there should be no difference. With a host name the order is hosts file before DNS so it should be used.

Is there another line in the host file with the same hostname?

What happens when you do a tacert? (trace route)