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.
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:
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:
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.
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.