Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ip

ping

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.

like image 794
swalog Avatar asked Feb 28 '11 12:02

swalog


1 Answers

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.

like image 191
Aaron Digulla Avatar answered Sep 22 '22 12:09

Aaron Digulla