I am trying to learn about how ARP protocol works in LANs. So, here is the physical structure of my network: enter image description here

So, when I try to ping PC3 from PC1, I expected the first packet to timeout because PC1 at first does not have the MAC address for PC3, so it should do an ARP request to get the MAC address first.

Now, when I pinged, all the packets arrived successfully!

enter image description here

My question is: Why is there no timeout? How did the packet arrive without knowing PC3's MAC address?

  • The "delay because of ARP" can happen once a remote subnet comes into play. Before passing on the packet, intermediate routers might have to resolve their respective next hops (might be ARP, or an appropriate mechanism for the given data link layer to the given next hop). The last hop router, connected to the the destination network, might have to ARP-resolve the destination host first, and/or the destination host might first have to ARP-resolve its default gateway, before sending a response back. This can sum up to so much delay that your local Ping application detects a timeout. Sep 28 at 8:29

short answer: the first packet is not sent out before ARP completes. In order to send a packet, the sender (usually operating system) needs to fill out its IP and Ethernet header. Thus it cannot send a packet before MAC of P3 is known, i.e. ARP completes.

long answer:

The idea of what happens on the host is following.

  • application (ping) gets an address (this can be an IP address or host name, in the latter case there are more steps)
  • application creates an ICMP echo request packet with destination IP (i am not quite sure, but according to here application only creates an ICMP without IP header)
  • application invokes corresponding OS syscall to send the packet to the provided IP address
  • OS gets a packet and provided IP address, OS invokes its routing function to determine next hop
    • OS determines from what interface to send packet (interface can also be provided as an option for ping, at least for ping6)
    • OS constructs IP header for the packet with corresponding source and destination
    • OS determines next hop. Since the destination IP is in the same subnet, routing function determines that next hop is the same as destination IP (if it was not, OS would have determined next hop from the routing table)
  • next OS invokes its layer 2 (Ethernet) processing function for the "next hop" (here next hop is also destination IP).
    • It checks ARP table to get layer 2 addresses of next hop. If there is no entry, it starts ARP resolution. Note, the packet is not yet sent. It cannot be sent because OS cannot possibly put anything meaningful in dst mac.
    • OS waits for ARP resolution. If successful, the entry is inserted in the ARP table. OS constructs layer 2 header for the packet. Now the packet can be sent.
    • if ARP resolution fails, OS will inform the application and ping will show appropriate error message.
  • Thank you! I got it. Sep 26 at 13:59

Each host maintains an ARP cache, where it stores for a predefined amount of time (quite large) this information.

Thus if a communication occurred recently between the two hosts, the address is already in the cache.

Additionally some host (depending on their operating system) emit a gratuitous arp when their interface comes UP. I.E. they advertise to the whole LAN their IP address and MAC address to the other hosts, precisely to allow the information to be put in cache.

I don't know if packet tracer generate gratuitous arp, though.


when I try to ping PC3 from PC1, I expected the first packet to timeout

The attempt of using PC3's address as destination triggers the ARP request. ping's ICMP echo request can only be sent after the ARP has succeeded. Before knowing the destination's MAC address, there is nothing to even send the echo request to.

How did the packet arrive without knowing PC3's MAC address?

The MAC was known before sending the first ping. Due to ping trying to use the destination address the IP stack resolves that address before sending the first echo request packet.

If the ARP request failed (for an unused address), ping doesn't timeout for lack of reply but for lack of address resolution.

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.