0

My level of knowledge is really basic, but as I understand when you search up say a website you send a server a request for the information of that webpage, then the server sends back packets which contain all that information. I was told these packets know where to go by the IP address you gave to the server upon the request, but that IP only gets the packets to your router, how does the router then know which device in the network requested those packets? I understand that each device has a MAC address but since you did not send the Mac address in the original request, the packets being sent back can't contain it surely? I tried looking online but really couldn't find any explanation for this. If someone could simply explain it to me I would be very grateful :)

2
  • Duplicate of superuser.com/questions/710132/… and superuser.com/questions/105838/…
    – Dharman
    Commented May 5, 2022 at 21:59
  • "but that IP only gets the packets to your router" No, the destination IP address on a packet is the address of the destination host, just like the source address on a packet is the host address of the source host. This is Networking 101. Also, not all data-link protocols use MAC addressing, and routers strip off the frame from the packet, losing any data-link addressing. You could also search for ARP.
    – Ron Maupin
    Commented May 5, 2022 at 23:44

1 Answer 1

0

IP packets work very much like the U.S. Postal Service. Consider each packet an envelope with a TO: and FROM: address. When you mail the letter, it goes to your local post office. The local post office looks at the TO: address's zip code. The local post office then routes it to the next nearest post office to that zip code, and then the next, and the next, etc, until the letter arrives at the local post office of the recipient.

When your computer sends an IP packet, say an HTTP GET request to google.com, the packet first leaves your network interface, whether its WiFi or Ethernet, and arrives at your router. Well, actually, first your computer has to resolve google.com to an IP address via DNS, but that's another discussion... Your router then consults it's ARP (address resolution protocol) table to see if it's a local device connected to WiFi or the router's switch. If not, then it's sent up-stream to the router's assigned gateway IP address (which is assigned by your ISP).

The packet arrives at your local ISP's edge router. That router consults its routing tables to determine if it's an up-stream, peer, or down-stream route. It's up-stream, so the edge router sends the packet to the next router upsteam, and again, and again, until it gets to your ISP's main router, which is likely connected to a high-capacity fiber-optic backbone.

The packet then travels to Google's nearest geographical datacenter and the whole routing process is reversed until it gets to one of many Google HTTP servers.

Each time the packet stops at a router to determine the next port to go out on, we call that a "hop". You can actually see these hops in action by using the traceroute utility built in to most operating systems.

In Windows: tracert google.com

In Linux/MacOS: traceroute google.com

BTW, you're correct that every device on any network has a unique MAC (media access control) address. These IP address to MAC address conversions are stored in ARP tables. They are cleared when a switch or router is reset. In order to discover a device's MAC address for a given IP address, your network card sends out a WHOIS packet to the network broadcast address. The switch knows to send these packets to every port and if the device that has this MAC address is connected, it will respond "right here!" :-)

2
  • That actually explains EVERYTHING apart from the one bit he asked about. For which the correct answer is given at superuser.com/questions/105838/… - precis: unique port allocation. You can see this for instance in PHP which will have a $_SERVER['REMOTE_ADDR'] AND $_SERVER['REMOTE_PORT']
    – Codemonkey
    Commented May 17 at 6:52
  • The question/answer you provided was in regards to NAT routers, i.e. home WiFi routers. The question was pertaining to Network Address Translation (NAT). That is not at all what the OP in this discussion is asking about. The OP's question is "How do packets know which device to go to?" It may seem similar to the question you posted, but it is not the same. The scenario he provided was a request being made to an internet server and a response given to a client. This has to do with Internet routing, not local area networks. I think my response clearly answers the question.
    – Designly
    Commented Jul 12 at 17:22

You must log in to answer this question.