4

HTTP servers usually operate at port 80. Yet NAT routers as most are these days assign port to outgoing requests so they would know when request is returned that which computer connected to it, it's suppose to be. They do it cause they can only use one public IP even though all computers behind router are given public IP address they are local IP address. Meaning they only work for everyone behind that router.

So how does server handles this. It only works at port 80, and router sends at whatever ports it wishes to do based on what is available and how it is programmed.

My understanding:

  1. Computer A to router. 22.22.22.22.22:80

  2. Router to World: 12.68.191.1.102:1 -ISP given IP address:Port to distinguish between computers connected to it.

Now what

Or maybe there is a difference between port and source port.

Hennes
  • 65,142

3 Answers3

1

You're confusing source ports and destination ports. When the request is sent to the HTTP server, the destination port is 80 since that's what web servers typically listen on. NAT routers can choose whatever source port they want. When they receive replies, they use the destination port (and other information), which should match the source port they choose for the outbound packets, to know which connection the packets are associated with.

Your computer has to do the same thing. Say you fire up two different browsers and you point each at superuser.com. How do you think your computer tells which TCP connection incoming packets belong to?

  • So you are saying that even though server listens at port 80, and that is what the destination port would be for request made by a computer/router, The server can send back data at different ports..or in other words server only listens at port 80 but reply at all ports. – Muhammad Umer Mar 05 '13 at 05:10
  • The server replies to whatever requests it gets. When it forms a reply, it sets the destination port of its reply equal to the source port of the request. The source port of its replies is 80. – David Schwartz Mar 05 '13 at 05:11
0

Nothing to do with ports here. If a HOST with a public address (q.w.e.r) resquests a page to SERVER at a.b.c.d (usually at port 80, or whatever), the server opens a connection to que requesting host and sends the reply. The request may have already traversed +100 routers before reaching the server.

Cigarrillo
  • 11
  • 4
0

The server always receives the data on port 80 - the router does not rewrite the port, only the source address - at least in the "typical" case.

The truth is the server does NOT know which machine behind the NAT router is requesting the traffic initially, but there are a few things it can do to find out -

  1. It can look at information the browser sends to the server as part of the request, and use things like the REFERER (referrer) field to see the last page the browser visited and the browser identification string. (There are no doubt others, it is possible to "fingerprint" a client reasonably uniquely if you are desperate)

  2. The first time the browser visits the site (or logs in or whatever), cookies can (and generally are) used by the server to track the browsers movement through the site. These cookies can be used to differentiate machines / sessions.

davidgo
  • 70,654
  • what is REFERER? I wanna know. – Muhammad Umer Mar 05 '13 at 05:05
  • 1
    LMGTFU - https://en.wikipedia.org/wiki/HTTP_referer (In a nutshell the browser tells the server the last page you visited using a "Referer" field in the header of an HTML request. "REFERER" is actually the correct spelling for the field - it was a typo in the original specification document which has manifested. If you use PHP you can generally get this information through the variable $_SERVER['HTTP_REFERER'] – davidgo Mar 05 '13 at 05:11
  • lol i didn't mean to call out spelling or anything. I want to know more about this. Thanks Man. – Muhammad Umer Mar 05 '13 at 05:21