1

If the host is receiving packets from a server, these packets have a destination IP address of the host and it is first received by the gateway present in the host network. Now the gateway checks the ARP, indexes using the IP address of the host to find the MAC address of the host, now it changes the link-layer (4-layer internet model) destination address (MAC address) to that of the host MAC address found from the ARP table. Then it forwards the frame to the layer 2 switch. But my question is, how can it forward the frame to the layer 2 switch since the frame has a destination MAC address of the host, not the MAC address of the switch. obviously gateway cannot forward the packet directly to the host since they are not connected and all packets have to go through the switch to reach the destination host. So what am I missing? have I understood something wrongly?

2

Assuming that the link layer between router and host is indeed a MAC-based link layer, and with layer-2 switching through a switch, then, yes, you are correct about how the router looks up the IP address, sees that this subnet is directly connected to one of its interfaces, and so it looks up the ARP table and sets the MAC address to be the MAC address for the host. Note, though, that the IP address lookup is layer 3 logic, whereas the router than passes it to the network interface card for that interface connected to the subnet, and the layer 2 logic is what finds the correct MAC address for the host.

Your confusion I think is because you are thinking that the router needs to send the MAC frame to the switch by setting the MAC address to the MAC address of the switch. No, the router just needs to know the interface to send out the MAC frame, and the MAC address of the host. There is no additional "routing" done at that time that needs the MAC address of the switch in order to make that the "destination". The layer 2 destination is the host, and the host MAC address is the right one to use.

So then the router spits out the layer 2 frame on that interface, and the switch will receive it and look at the MAC address. The switch also maintains an ARP table mapping the known MAC addresses to ports, and can then pass the frame on, out of the right port for the host.

ps. You may wonder, what is the purpose of the MAC address of the switch itself? This is for cases where the switch itself is the end-point, e.g., the switch supports configuration over a http interface. But that is different from the cases where the switch is just passing through the layer 2 frames to the intended destination, out of one of its ports

| improve this answer | |
  • how does the router/gateway know which interface it has to forward the frame, in case there are multiple layer 2 switches? and what is the use of having a mac address for the switch since we are not using it here, does it have any other purpose? – pal May 7 at 8:08
  • The router will know based on the routing table. The routing table for directly connected networks would have the interface, so it just pushes the frame out there. For your second question, I already answered it in the "ps" (last paragraph) of my answer. – auspicious99 May 7 at 8:16
  • The router's layer 3 logic doesn't care if there are one or more switches on the way to the host, or if it is directly connected. All it cares about is to pass the IP packet down the protocol stack to the layer 2 logic for the correct interface (that info from the routing table). Then layer 2 adds the host's MAC address, passes it down to layer 1 to go out of that interface. – auspicious99 May 7 at 8:22
1

A router doesn't change MAC addresses. It routes packets. On reception, it strips the MAC frame off the packet, it has done its job (transporting the packet from the previous hop). Then the router consults its routing table, determines the next hop address (and interface), and passes the packet to it.

"Passing the packet" on a MAC-based link layer requires a MAC frame to encapsulate the packet. Among other details, the MAC frame requires a destination MAC, which is the MAC of the next hop which is determined by ARP for IPv4 or NDP for IPv6. The next hop can be a gateway towards the destination, or the destination itself if it's local.

Any switch that is located between the router and the destination/next hop is completely transparent to the link layer. The switch uses the destination MAC to forward the frame to its local destination. The frame itself isn't changed.

Not all networks are MAC-based. The ubiquitous Ethernet or Wi-Fi are, but e.g. a serial link isn't. Point-to-point connections don't need such addressing, generally.

| improve this answer | |
0

Packets received from server .. server will send packets to Gateway ip address which is configured on servers network adapter properties .. packet will reach gateway

For example if gateway is configured on router . Packet will reach router from router packet will do route table verification if destination is directly connected network then ARP table is verified .

ARP table maps ip address ==>mac address table

Further packet will reach to L2 switch from router . In L2 switch mac address table is verified.

Mac address table maps mac address ==> switch ports

If destination ip address is not directly connected network . Then it will verify route table and forwards packet to next hop as per routing table.

| improve this answer | |

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.