2

so if I send a packet from a host to another from the same network we know the mac address of both the source and destination.

However if the receiver is in a remote network the destination mac address will be first the router's mac then changed to the actual destination (let's assume there's one router connecting the networks).

My Question is: if the final mac address is not mentioned in the initial packet (but instead replaced with the router), how does the router know it?

Now I know there's the arp protocol that translate the IP address into a mac address, but from my understanding the mac address is associated with the nic and I think that a single device can have multiple nics and thus multiple mac addresses, so how does it choose the correct one? unless each nic is connected to a different network, and in that case what's even the use of a mac address?

2

A router doesn't know nor does it care about the MAC address of a remote destination. MAC addresses are used only for delivery in layer-2 segments like Ethernet. Those addresses are of no consequence to any node outside that segment.

Instead, communication across separate segments uses layer-3 addresses (IP) with routers. Routers forward based on the destination's layer-3 address. Only when the destination is local to a router (on the last hop) does the router resolve the destination's layer-2 address, encapsulate the L3 packet in a frame addressed to the L2 address and send it over.

Intermediate routers (using MAC-based network segments) resolve the next hop router's IP address and encapsulated the packet in a frame addressed to the next hop's MAC address instead.

2

The router is a host on the LAN, and it does the same thing as any other host to resolve the layer-3 (IP) address to the layer-2 address (MAC for IEEE protocols). For IPv4 on an IEEE network, that would be ARP (Address Resolution Protocol), or for IPv6 on an IEEE network, that would be NDP (Neighbor Discovery Protocol).


See this question and this question for related answers.


Remember that not all layer-2 protocols use MAC addressing. Some use something else, like DLCI or VPI/VCI, and some do not use any addressing, like PPP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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