Do Routers Change MAC Address of Packets When Forwarding?

mac addressrouterrouting

enter image description here

Lets say host A wants to send a packet to host B through R1(interface 1 then 2) and R2 (interface 3), so my questions is:

When the packet is forwarded inside R1 (from interface 1 to interface 2), ready to be sent to R2, does the pack's source MAC(A's MAC address) and destination MAC(interface 1's MAC address) get changed to interface 2's MAC address as new source address and interface 3(of R2) as new destination MAC address? If they do get changed, why router need to change source and destination MAC address?

Best Answer

isn't a router only deal with IP address

A router with Ethernet (or Ethernet-like) interfaces needs to deal with MAC addresses because it needs to send and receive IP packets over those Ethernet interfaces and MAC addresses are a core part of Ethernet.

MAC addresses only have meaning within an Ethernet network.

Logically what happens at R1 is.

  1. The destination MAC address is checked. For a Unicast MAC address* if it doesn't match the frame is dropped by the network card, if it does match the Ethernet frame is stripped and the packet is passed up to the IP stack. This check is important to prevent packet duplication.
  2. The IP address is examined and determined to not be one of the local interfaces of the router.
  3. The IP address is looked up in the routing table and an interface and next-hop IP address is chosen.
  4. What happens next depends on the nature of the connection between R1 and R2. If the connection is Ethernet then the IP packet will be encapsulated in an Ethernet frame with the router's interface as source MAC and a MAC address looked up using the next-hop IP address as destination MAC address. On the other hand if the link is a serial point to point interface then there may be no MAC addresses involved at all and other protocols may have their own addressing scheme.

* Broadcast and multicast packets need more special handling, but that is outside the scope of this question.

Related Topic