Reputation: 23
So I wondered how do packets know its destination if there is IP masquerading which hides the IP of the singe device in a network, but one of the threads explained it to me: "Basically the client registers it's own local address and a unique port on a network address translator (NAT) device/"router" when sending the request. So when the server replies with only the public ip address, it uses the reserved port to see where in the subnet to send the info."
Okay, but how this "request" (which is SYN in 3-way handshake I believe) know which device should he ask for connection?
Example: I want to send some data to Computer1 in some network. There are 3 more computers in that network: Computer2, Computer3 and Computer4. The first thing I do to perform TCP connection with Computer1 is 3-way handshake (during which I put my own local address and unique port in NAT device, but Computer1 still doesn't know I want to connect him)
So from Computer1's perspective: "some device sent his local address and unique port in my NAT router, because he wanted to connect with either me, Computer2, Computer3 or Computer4 (and probably send some data later on). But how do I know if it's me or one of my 3 colleagues? In packet header there was only IP address of our router."
I'm new to networking and watched couple of tutorials but still don't get it. I would be glad if someone explained it to me, don't get angry at me if it's already been covered.
Upvotes: 1
Views: 2370
Reputation: 182753
So from Computer1's perspective: "some device sent his local address and unique port in my NAT router, because he wanted to connect with either me, Computer2, Computer3 or Computer4 (and probably send some data later on). But how do I know if it's me or one of my 3 colleagues? In packet header there was only IP address of our router."
It doesn't know and it doesn't care. All it needs to do is be able to send a response to the correct originating machine. To do that, it needs to get the packet to a machine that does know and does care, and that's the NAT router.
How does the NAT router know? Because it saw the local source address of the original packet that created the request.
How does the server reach the NAT router? It simply addresses response packets to the source address of the request it received, which will be that NAT router's public address.
Upvotes: 1
Reputation: 146
Routers accomplish this task using forwarding tables to determine where a packet should go and be received. When a packet reaches a router, it will look at the destination address to determine where to send the packet. Basically Is an orchestrated concept that all routers can compute, when sending and receiving data they also keep logs and update these tables in coordination with mac, device, IP, and DNS addresses as well as location data in some cases.
As far as your question goes your 3 colleagues sending a packet over the same router to a destination. Each computer has a dynamic IP, and MAC address assigned to each computer. Knowing where each packet comes from the routers NAPT, or IP Masquerading which updates the translation table with this data.
This question has been answered in different context here below.
Sources:
https://superuser.com/questions/710132/how-does-a-packet-reach-its-destination/710148
https://superuser.com/questions/105838/how-does-router-know-where-to-forward-packet
Upvotes: 0