Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was just thinking and that idea came to my mind.

Let say I have hosts A and B inside my local area network. I have a Router, and a host C in the internet. I know that when initiating the connection, the source port is chosen randomly, but what happens if two hosts chose the same when initiating to the same host:port?

A:10123 -> C:80
B:10123 -> C:80

How would the router know which packets belongs to each one?


share|improve this question
Using IP address of A and B. – Laurentiu Roescu Nov 26 '12 at 11:52
But when the response packets arrive to the router, they have no information about how to route them back to the local host. – NullOrEmpty Nov 26 '12 at 11:56
The response packets would have different destination ports because the NATed original packets would have different source ports. – David Schwartz Nov 26 '12 at 12:18
up vote 3 down vote accepted

Just because hosts A and B chose port 10123 doesn't mean that is the port that the router uses. The router connects to host C from a source port of it's own choosing. So the connection looks more like this:

A:(src:10123, dest:80) -> | A:10123 -> C:43775 | -> C:80
B:(src:10123, dest:80) -> | B:10123 -> C:43776 | -> C:80
share|improve this answer
Thanks. That was my doubt, the source port. – NullOrEmpty Nov 29 '12 at 1:33

I am with Laurentiu the Router will send the Packet based on the IP Address from A or B. The Response Packet would look like this:

Source IP: C
Source Port: 80
Destination IP: A (or B)
Destination Port 10123

the Router would Route the Packet to the right Host.

If the Router is configured with PAT the Router would assign the NAT/PAT IP and new random Source Ports for the outgoing Packets.

share|improve this answer

Router has routing table with ip address . It remember the particular ip address to find which host made request and route that response packet to that particular host.

share|improve this answer
what you describe is the ARP Table. This is the way hosts communicate in Layer 2. The Routing Table contains Hosts and Networks and their Next Hop Address to reach this Host/Network. And in the ARP or Routing Table is no Information about the Host who requests a Packet. This is stored in a NAT Table – user1008764 Nov 26 '12 at 12:39
you are right , Now answer edited. – K.K Patel Nov 26 '12 at 12:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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