Networking – How does a packet reach its destination

internetnetworking

Inside a router network it's easy to route all the packages. The router knows all the clients. However, on the internet, there are so many IP addresses.

I send a packet from my computer to the IP 1.2.3.4. It reaches the router. It checks it against its rules and sees that this isn't on the local network. Then it routes it through the Ethernet port. What happens next? Then it reaches the server, and the server sends a packet in return. Finally it reaches the router. How does the router know which computer (mine) to send it to?

Best Answer

In a nut-shell, when a router doesn't know how to route a packet it'll send the packet to the default gateway/the next "hop".

Basically, when your router can't find a valid rules (or more formally, it's route table) it will send the packet to the default gateway, which will typically send it upstream to your ISP.

Once the packet arrives at your ISP's routers, much like your own router, they will have their own route tables. But this time they'll be more detailed. Knowing about other customers and other ISP's.

This will continue on until the final router that has the final destination rule attached to it, sending it onto the specific computer/Interface.

All along this way, the packet includes source information indicating where the original packet came from. Your router (likely, with NAT) would had converted this source information from your local machine's internal only IP address (e.g. 192.168.1.25) to your WAN IP address given to you by your ISP (e.g. 121.147.148.55) and this WAN IP will be what's contained within the packet's source information.

Thus, all the upstream routers can simply perform the same routing as above, but in reverse to send your packet back to you. However, once it reaches your router. Your router has it's own special rules to know that that certain packet should be forwarded back to your local machine with it's internal only IP address. This is called Network Address Translation.

Related Question