开发者

Why does the resolved IP of youtube.com direct to google.com? [duplicate]

This question already has answers here: Understanding IP . The requested URL was not found on this server (3 answers) Close开发者_运维问答d 8 years ago.

This might be a really stupid question, but I'm curious.

A ping of youtube.com showed the resolved IP to be 74.125.127.93. Now, if you access this IP in a browser http://74.125.127.93/ you would expect the youtube page to show up. Instead the search engine shows up.

Can someone explain what's going on behind the curtain? Thanks.


Because there are many server names but only a few IP addresses.

Let me explain. IPv4 allows 2^32 (4 billion) different IP addresses. Sounds like a lot but most of them can't be used. IP-addresses are always allocated in blocks. The smallest block is 255 addresses (8 bit - 1 address for broadcasts), the biggest one is 16 million addresses (2^24-1). Medium sized blocks have 64k addresses (16 bit).

If you're an ISP, you get a fixed set of addresses. But of course you always ask for a block that is larger than what you absolutely need - otherwise you'll run out of addresses and that's really bad for an ISP. You could ask for two 16 bit blocks but joining the two blocks is always a hassle.

Last week, we ran out of IPv4 blocks. So ... you have a 64k block and can't get more. But you have 150'000 customers which want to run a web server.

The solution: virtual servers. You tell your DNS "x.y.com" is 13.242.251.17 and "a.y.com" is the same address and "b.y.com", too.

When a client makes a request, it will do a DNS query which always returns the same IP. Then it sends a HTTP request to the IP it just got. The trick is that the HTTP request contains the server name. So even though all the requests go to the same IP address, the web server can still figure out who you really want.

As long as you give it the name. If you use the IP instead, you get the default service which is the Google search engine.

[EDIT] With telnet, you can try this yourself. Start it with telnet 74.125.127.93 80 and then type:

GET http://www.google.com/index.html HTTP/1.1

Hit enter twice. You will get a redirect for the Google homepage of your country. Now type:

GET http://www.youtube.com/ HTTP/1.1

Hit enter twice. This time, the YouTube homepage will be returned.


Google owns Youtube.
They probably use the same load-balancing server together with name-based virtual hosts for detecting which site you are trying to browse to.
This can be achieved by looking at the host header supplied by the client (which is the domain you are trying to browse to). Since the host header is different, you don't always get to the same site when going directly with the ip as when you go through the domain.


Google is using virtual hosting -- two (or more) services on the same IP address where the web server to handle a request is determined by the URL of the request.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜