Home > Mobile >  What's the different use IP directly and config the local host?
What's the different use IP directly and config the local host?

Time:10-31

I try to use IP directly access a URL by HTTP protocol, there are two methods here:

  1. Use the URL which the domain replace with its IP
  2. Config the IP and domain pair in local host of system

When the http request arrived the server, from the point of the server view, what's the different between the both request?

CodePudding user response:

There would be no difference to the server. It is up to the client to resolve domain names to their IP addresses and there are a few ways to do that. One is to use a DNS server, another is to use the hosts file.

To add on, the domain is most certainly sent in the HTTP request. The browser (or other HTTP client) is responsible for that. If you use the IP, then no domain will arrive at the server, meaning it will serve up whatever is configured as the default content for the IP. The domain info is what allows the server to server multiple domains on a single IP.

CodePudding user response:

Consider a Client connects to a Server.

First thing your computer does, is to analize the address you input. If you wrote an IP, nothing to do now. If you wrote a domain, it will 'resolve' domain.

Resolving domain (DNS) means to 'translate' your URL into an IP. When computer resolves the domain, it will only use the new IP it got.

Client is sending packages with meta-data, that includes where this package is from (client's ip), where it may reach (server's ip), destin port etc.

Domain is not included on network packages. Only IPs are included. That means the server could never know if user connected to it using a domain or its ip directly.

  • Related