Switch Behavior – What Happens When Destination MAC Address is Unknown?

ip addressipv4ipv6mac addressrouting

Say I just connected my computer to the internet through a home/office LAN network. I then proceed to ping google.com. Of course, the DNS converts google.com to the destination IP address, but how is the destination MAC address known? Please explain how the packet reaches Google's server and how does the response find its way back.

Best Answer

I think you are confused. The destination MAC address for any destination not on your LAN is the MAC address of the gateway configured in your source host.

MAC addresses are layer-2 addresses, and they are only relevant, or even used, on your layer-2 LAN. Layer-3 addresses, e.g. IPv4 or IPv6 addresses, are used to communicate with a host on another LAN.

ARP (Address Resolution Protocol) is used to resolve a layer-3 address to a layer-2 address in order to communication on a LAN. A host will maintain an ARP cache, but if there is no entry in the cache for the layer-3 address, the host will send an ARP request with that layer-3 address to find the corresponding layer-2 address.

ARP request: "Who has the layer-2 address for this layer-3 address?"

ARP reply: "I do, and this is the layer-2 address for that layer-3 address."

If the destination layer-3 address is on a different layer-3 network, the host will use the layer-2 address of its configured gateway, and it will use ARP if it does not already have the layer-2 address of the gateway.

Packets are layer-3 datagrams, and they do not contain layer-2 addresses, which are contained in the layer-2 frames that encapsulate layer-3 packets. Packets are routed by layer-3 devices called routers. Routers strip off the layer-2 frames from the layer-3 packets before routing the packets, and they will build new layer-2 frames for the next leg of the packets' journey. A complete discussion of routing is far too large and broad to be discussed here.

Your title is actually a different question. Switches do not get involved at layer-3 at all, so they do not use ARP. Switches maintain MAC address tables to relate a switch interface to a MAC address. Every time a frame comes into a switch interface, the switch will update or create a MAC address table entry of the source MAC address and the interface on which it arrived. The switch will use this MAC address table to look up the destination MAC address to see if it has a destination interface for the frame. If not, it floods the frame to all other interfaces.