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?

1
  • Router works on Layer 3, works on IP , doesn't care for MAC Commented Apr 6, 2020 at 18:50

5 Answers 5

3

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 within a directly attached network. 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. They look up the destination address in their routing table and then forward to the next gateway - a router leading further towards the destination or the destination itself if it is connected locally.

Forwarding to the next gateway over a MAC-based network means using the gateway's destination MAC address (determined by ARP/v4 or NDP/v6) in the frame encapsulating the actual IP packet.

Only when the destination is local to a router - on the last hop - does the router resolve the destination's MAC/L2 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 encapsulate the packet in a frame addressed to the next hop's MAC address instead.

4

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.

1

Sender doesnt know MAC address of the destination and it doesnt need to.

It only needs to know MAC address of the router which will route packet to the next subnet.

So packet hops from router to router using Layer 3 network address IP because routers "understand" only Layer 3 IP addresses (they dont care for source or destination MAC address of incoming packet).

Router checks destination IP address and routing table to find NIC which will be used and IP address of router packet is send to.

From this IP address, router Layer 2 MAC address is retrieved (ARP) and is put in the Ethernet header as destination MAC address. Because packet on the subnet are handled by switch, which only "understands" Layer 2 MAC address.

This repeats till packet arrives to router connected to destination subnet.

When packet arrives to the last router, which is connected to the same subnet our destination IP resides. This last router determines IP address resides on this subnet. Layer 2 MAC address of destination is retrieved and packet is sent on dedicated NIC with correct IP and MAC address of the destination.

2
  • routers "understand" only Layer 3 IP addresses - routers need to work with L2 addresses as well, as required on their interfaces (as you wrote later).
    – Zac67
    Commented Dec 1, 2023 at 17:36
  • Well maybe semantics could be better. I meant routers dont have logic to interpret MAC addresses, and they dont care of Ethernet header content. they only have to find out MAC address of next destination and put it in Ethernet packet header. Commented Dec 1, 2023 at 18:00
0

If layer 3 interface for that specific network is configured on router then router will discover physical address of compute,

Arp works as fallows

When a new computer joins a LAN, it is assigned a unique IP address to use for identification and communication. When an incoming packet destined for a host machine on a particular LAN arrives at a gateway of router . Router looks for ARP table to find a MAC address that matches the IP address and forwards the traffic .By flooding the broadcast message to all host connected in systems a ARP table is created in router belong to layer 3 gateway configuration on router . A table called the ARP cache maintains a record of each IP address and its corresponding MAC address.if gateway is not configured on router mean it will just forward traffic on basis of routing table to next hop

enter image description here https://i.sstatic.net/XxOgj.png If layer 3 interface for that specific network is configured on router then router will discover physical address of compute,

Arp works as fallows

When a new computer joins a LAN, it is assigned a unique IP address to use for identification and communication. When an incoming packet destined for a host machine on a particular LAN arrives at a gateway of router . Router looks for ARP table to find a MAC address that matches the IP address and forwards the traffic .By flooding the broadcast message to all host connected in systems a ARP table is created in router belong to layer 3 gateway configuration on router . A table called the ARP cache maintains a record of each IP address and its corresponding MAC address.if gateway is not configured on router mean it will just forward traffic on basis of routing table to next hop

enter image description here https://i.sstatic.net/XxOgj.png Router#sh ip arp Protocol Address Age (min) Hardware Addr Type Interface Internet 172.16.10.1 - 00D0.5839.C102 ARPA GigabitEthernet0/1 Internet 172.16.10.2 1 0060.478D.1107 ARPA GigabitEthernet0/1 Internet 192.168.10.1 - 00D0.5839.C101 ARPA GigabitEthernet0/0 Internet 192.168.10.2 0 0060.2F0A.B64D ARPA GigabitEthernet0/0 Router#sh ip arp Protocol Address Age (min) Hardware Addr Type Interface Internet 172.16.10.1 - 00D0.5839.C102 ARPA GigabitEthernet0/1 Internet 172.16.10.2 1 0060.478D.1107 ARPA GigabitEthernet0/1 Internet 192.168.10.1 - 00D0.5839.C101 ARPA GigabitEthernet0/0 Internet 192.168.10.2 0 0060.2F0A.B64D ARPA GigabitEthernet0/0

-1

If layer 3 interface for that specific network is configured on router then router will discover physical address of compute,

Arp works as fallows

When a new computer joins a LAN, it is assigned a unique IP address to use for identification and communication. When an incoming packet destined for a host machine on a particular LAN arrives at a gateway of router . Router looks for ARP table to find a MAC address that matches the IP address and forwards the traffic .By flooding the broadcast message to all host connected in systems a ARP table is created in router belong to layer 3 gateway configuration on router . A table called the ARP cache maintains a record of each IP address and its corresponding MAC address.if gateway is not configured on router mean it will just forward traffic on basis of routing table to next hop

enter image description here

Router#sh ip arp Protocol Address Age (min) Hardware Addr Type Interface Internet 172.16.10.1 - 00D0.5839.C102 ARPA GigabitEthernet0/1 Internet 172.16.10.2 1 0060.478D.1107 ARPA GigabitEthernet0/1 Internet 192.168.10.1 - 00D0.5839.C101 ARPA GigabitEthernet0/0 Internet 192.168.10.2 0 0060.2F0A.B64D ARPA GigabitEthernet0/0

1
  • 3
    While you are generally correct, your answer has some inconsistencies and misleading details. For example, first you say ARP is a protocol, then you say it is a program. Please consider editing your answer.
    – Ron Trunk
    Commented Jul 17, 2020 at 12:22

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.