0

I learned that inside a packet there is information about the sender's public IP and MAC and the receiver's public IP and MAC, and that at each hop, the sender's and receiver's MAC are changed along the way.

Example: Imagine that the public IP of my router/gateway is 101.1.98.2 and the public IP of my friend's router/gateway is 98.1.19.0 and in my friend's network there are 3 devices, I send a message to him, if the destination and source MAC is changed during each hop, when it arrives at the router/gateway how will it know which device the message is for, if the destination MAC has been changed.

1
  • 1
    "I learned that inside a packet there is information about the sender's public IP and MAC and the receiver's public IP and MAC" No, MAC addresses are on the frame header, not inside the packet that has IP addresses on its header. Not every hop will have a MAC address. For example, it is common for DSL to use PPPoA, and neither PPP nor ATM use MAC addressing. A router strips of the frame, losing any layer-2 addressing, and builds a new frame for the next hop, and the next hop layer-2 protocol may not use MAC addressing.
    – Ron Maupin
    Oct 20, 2023 at 12:25

2 Answers 2

3

This is the role of the ARP protocol: find the MAC associated with the IP address we want to talk to.

Assuming MAC-based network (not all networks use MAC addresses)

When receiving a packet a router performs those steps:

  • check if the destination IP address match a subnet directly connected
    • if yes then the destination IP address is the next hop
    • if no check the routing table for a route to the destination and get the address of the next hop

To send the packet to the next hop (being either the final destination or the next router - the process is the same)

  • perform an ARP resolution to find the MAC address associated with the IP address of the next hop
  • send the packet to this MAC address

The ARP resolution simply works by shouting out loud on the media "Who has IP address X.X.X.X? please tell me" Then the owner of the IP address answers: "this is me, my MAC address is Y.Y.Y.Y.Y.Y.".

The sender saves this information in a cache to not repeat the discovery phase for each and any packet.

1

inside a packet there is information about the sender's public IP and MAC and the receiver's public IP and MAC

An (IP) packet header stores the sender's IP address (public or private, possibly translated) and the destination's IP address (public or private, possibly translated). It does not hold any MAC addresses.

MAC addresses are part of the frame header used on MAC-based networks on the data link layer (L2) for delivery inside that network.

at each hop, the sender's and receiver's MAC are changed along the way.

It may appear like that but it isn't really. As per above, a MAC frame is used in some networks for local delivery, but not in all networks. Regardless of its form, an IP packet is always encapsulated by some kind of data link layer frame as its payload.

Each hop that receives a packet discards the encapsulating frame, routes the packet and re-encapsulates it as required for the egress network. Ingress and egress frames may look very similar to each other (apart from source & destination L2 addresses), but they may also be vastly different since IP may be transported by a wide variety of L2 networks.

how will it know which device to deliver the packet to?

The last hop delivers the packet by IP address. If a MAC address is required it's looked up using ARP (IPv4) or NDP (IPv6).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.