9

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?

Cheers.

NullOrEmpty
  • 389
  • 2
  • 5
  • 16

3 Answers3

11

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:

                                  router
                          +--------------------+
A:(src:10123, dest:80) -> | A:10123 -> C:43775 | -> C:80
B:(src:10123, dest:80) -> | B:10123 -> C:43776 | -> C:80
                          +--------------------+
longneck
  • 23,082
  • 4
  • 52
  • 86
  • I get what you are trying to say, and I think you're totally correct, but, I think this diagram would be a little more specific if it included the fact that there is a Public IP on the router, D, that is what the router uses as the third address, like: A:10123 -> D:43775 | -> C:80 B:10123 -> D:43776 | -> C:80 – JeffFromOhio Apr 20 '21 at 13:25
1

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.

KK Patel
  • 385
  • 4
  • 17
user1008764
  • 1,176
  • 2
  • 8
  • 12
0

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.

KK Patel
  • 385
  • 4
  • 17
  • 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. – KK Patel Nov 26 '12 at 12:46