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.

3
  • Using IP address of A and B. Nov 26, 2012 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. Nov 26, 2012 at 11:56
  • 1
    The response packets would have different destination ports because the NATed original packets would have different source ports. Nov 26, 2012 at 12:18

3 Answers 3

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
                          +--------------------+
1
  • 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 Apr 20, 2021 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.

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.

2
  • 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 Nov 26, 2012 at 12:39
  • you are right , Now answer edited.
    – KK Patel
    Nov 26, 2012 at 12:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .