Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a router with three computers connected to it via Wi-Fi. One day, computer A requests the file "index.php" from a server with IP address XYZ. Then the second computer, B, requests the file "home.html" from the same server, and computer C requests "picture.jpg" from the same server. If all these requests are made at the exact same time, how does the router know which file to send to which computer? Could these simultaneous requests cause problems such as sending "home.html" to computer C instead of B?

share|improve this question
    
Is there an actual problem you are having? If so, please edit your question with what is actually happening? This is not a site for hypothetical situations to be pondered and discussed. –  CharlieRB Jan 28 '13 at 12:43
    
It would take a great deal of effort to make all three computers have the same private LAN ip address. One has to ask why you are asking about this ridiculous example one that wouldn't about in the real world(and if it did then the configuration is still ridiculous). Unless you clarify an ACTUAL problem I have to downvote this question. –  Ramhound Jan 28 '13 at 14:09
    
@Ramhound: I fear you may have misread the question, although the title is indeed confusing. This is not about multiple machines trying to obtain the same address from a DHCP server, but about how requests made to the same IP are distinguished when they originate from the same network. That's a very 'real world' scenario. –  Marcks Thomas Jan 28 '13 at 15:23
    
@MarcksThomas - I would argue that router must be the DHCP server in this question otherwise it the question makes no sense. In any case the question need to be clarified and the title updated once that is done –  Ramhound Jan 28 '13 at 15:28
add comment

closed as not a real question by CharlieRB, BBlake, Dave M, Simon Sheehan, Keltari Jan 28 '13 at 15:46

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

Sender's IP address is stored in its messages, so that the receiver can send back a response to the appropriate computer. In that case, the router just routes packets.

When the computers on a private LAN behind a single IP address, the router also performs Network Address Translation. In that case, the router maintains a translation table for routing the packets to the appropriate computer.

share|improve this answer
add comment

Whenever a client visits a website, it attempts to open a TCP connection between itself and the server. This connection is uniquely identified by its destination IP address, destination port, source IP and source port. For a client behind IP 1.2.3.4 visiting superuser.com, the connection could appear as: 1.2.3.4:41952 - 69.59.197.21:80.

Web servers generally run on port 80, the default port for HTTP traffic, so clients would send their requests to view a web page to that port. If the server would use the same port to send its reply, browsing the web would interfere with the operation of a web server the client might be running himself. Fortunately, the client initiating the connection can use whatever source port is available. This port will be reserved as temporarily in use until both machines agree on closing the connection. The IANA suggests to use the range 49152 to 65535 for these so-called 'ephemeral ports', a recommendation most operating systems adhere to nowadays.

Below is a screenshot of a server showing one SSH and two HTTP connections, as well as the ephemeral ports the machine is responding to.

iftop

While the operating system ensures no connections are opened on source ports already in use, it cannot reserve them for the entire local area network. However, the router can. Though not technically required, in the most common NAT setup, the router rewrites both the source address and port of all outgoing packets, hence 'network address (port) translation', maintaining a table of all open connections. Some routers even allow you to view this table directly, for instance using telnet:

conntrack

By reassigning port numbers, the router can keep track of every connection individually and forward replies to the appropriate host. For example, this is what happens when machines A and B simultaneously try to access superuser.com from the same network, accidentally using the same ephemeral port.

  • Host A opens a TCP connection to superuser.com. src: 10.0.0.1:41952, dest: 69.59.197.21:80
  • The router rewrites this to src: 1.2.3.4:41952, dest: 69.59.197.21:80 and notes the translation in the connection table.
  • Host B also opens a TCP connection to superuser.com. src: 10.0.0.2:41952, dest: 69.59.197.21:80
  • The router notices the source port is in use and rewrites to src: 1.2.3.4:41953, dest: 69.59.197.21:80.
  • The web server reponds to both 1.2.3.4:41952 and 1.2.3.4:41953.
  • The router matches incoming traffic against its connection table and forwards packets to the appropriate machine, e.g. for B: src: 69.59.197.21:80, dest: 10.0.0.2:41952.

In conclusion, as long as your NAT is working correctly, simultaneous requests from different computers on your network that risk being mixed up are rewritten by the router to be easily distinguishable, making sure the right web page ends up at the right browser.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.