packageip-addresssendethernetmac-address

How does a computer know where to send the packet to, only with an IP not MAC


With a normal Ethernet cable (patch cable) you use Ethernet Frames (https://en.wikipedia.org/wiki/Ethernet_frame) to send data to other computers/devices in my LAN network. In the Ethernet frame, there is a source mac address and a destination mac address. And it has a payload. The payload contains an IP package (https://en.wikipedia.org/wiki/Network_packet). How does my computer when I enter the command ping 192.168.86.40 connects to the computer and send packages without knowing the mac address used to send Ethernet frames. You need a destination mac address to send Ethernet frames which contains IP packages. And if I set up my network with a static IP address, subnet master, and a gateway IP what the mac address is for the gateway to connect. Does the computer use the broadcast mac address FF:FF:FF:FF to figure out what the gateway mac address is?

The QUESTION is: How does a computer know where to send the packet to, only with an IP address not MAC address to send Ethernet frames that contain IP packets


Solution

  • IPv4 uses ARP (Address resolution protocol) - the source node sends an ARP request as broadcast, asking for the destination IP's MAC address. The request is received by the destination node (ignored by anyone else) and replied to with its MAC address.

    Once the MAC address is known, the source can encapsulate the IP packet in an Ethernet frame and send away.

    ARP is only usable for any local IP address, ie. an address residing in the same subnet as the sender. If your local IP address is e.g. 192.168.86.2/24 the destination 192.168.86.40 is local.

    Sending to an IP address outside your local subnet requires a gateway (router) - this can simply be the default gateway or another, specific gateway as indicated by the local routing table. ARP is only used for resolving the gateway IP address here. The IP packet is encapsulated using the gateway's MAC address as destination and sent out.

    The gateway repeats this process - either resolving the destination IP by ARP when it's local or using its routing table to find the next hop gateway, resolve its IP address and forward to that MAC. These steps repeat until the destination is reached.

    Accordingly, the answer to your question is:

    Of course, there are other link layers than Ethernet but the general process is identical with all MAC-based networks.