1

I want to know how a web server can distinguish between requests of different DNS names on the same server (same IP)?

for example, in my university there are two websites:

fea.kau.edu.sa
engineering.kau.edu.sa

and when I use nslookup on Windows, I got the same IP address for both domain names. Can you explain please?

Eng.Fouad
  • 139
  • 1
  • 2
  • 8

3 Answers3

8

HTTP 1.1 requires that all client systems send a header, Host, which indicates to the server which hostname they are sending the request for.

This allows the server to read that header, and respond with content for the appropriate site.

Without this feature, a different IP address would be needed for each different site; we would have run out of IPv4 space even sooner if we didn't have this in place.

Shane Madden
  • 114,520
  • 13
  • 181
  • 251
6

Fire up your favourite packet tracer (something like wireshark) and watch what actually happens when you connect.

A very simple request might look like this:

GET / HTTP/1.1
Host: www.example.com
​

(note the empty line at the end if you want to re-create this yourself by using, say, telnet. You can see a lot of this stuff also over in wikipedia)

The Host: part of the request tells the web server which site to access.

There's a lot of stuff shown in these headers, so you might want to get to know them with a browser plugin like Firebug

Mark Henderson
  • 68,823
  • 31
  • 180
  • 259
  • What happens if the IP is accessed directly? For example, if I enter `http://216.58.213.238` instead of `http://google.com` in my browser? – bweber Sep 02 '16 at 08:20
2

Simple.

Since a long tim, every HTTP request.... ...INCLUDES THE DOMAIN.

Basically the PAYLOAD (not tcp, the http request structure) tells the web serve rwhat the domiain is for.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

has the fields transmitted by the browse. There is one "HOSTNAME".

Most other protocols - do not care.

TomTom
  • 51,649
  • 7
  • 54
  • 136