๐ ARP and Default Gateway
Everything Hosts Do to Speak on the Internet โ Part 1 & Part 2
Series: Networking Fundamentals for Cloud & DevOps โ Part 3 of 6
We already know that IP addresses are used at Layer 3 and MAC addresses are used at Layer 2. But there is an important practical question: what does a host do when it knows the destination IP but doesn't know the destination MAC?
The answer is ARP.
Part 1 โ When the Destination Is on the Same Network
Suppose we have two hosts:
-
Host A โ MAC
a2a2, IP10.1.1.22, mask255.255.255.0 -
Host B โ MAC
b3b3, IP10.1.1.33, mask255.255.255.0
With a /24 mask (255.255.255.0), the network is 10.1.1.0/24. Both hosts belong to the same network, so they can communicate directly at Layer 2.
1. A Wants to Send Data to B
Suppose A wants to send data to B. A already knows B's IP address (10.1.1.33) โ maybe learned from DNS, or the application already knows it.
So A can create the Layer 3 IP header: SRC IP = 10.1.1.22, DST IP = 10.1.1.33.
But there is a problem: A doesn't know B's MAC, and Ethernet / Layer 2 needs a destination MAC address.
IP address is known, but MAC address is unknown โ use ARP.
2. ARP = Address Resolution Protocol
ARP = Address Resolution Protocol. ARP basically asks:
"Who has IP 10.1.1.33? Tell me your MAC address."
A sends an ARP Request. Conceptually:
Host A โ My IP =
10.1.1.22, My MAC =a2a2โ "Who has10.1.1.33? Please tell me your MAC."
The important point is that A knows the destination's IP, but needs to discover the corresponding MAC.
3. Why Is the ARP Request Broadcast?
A doesn't know B's MAC yet, so A cannot send the ARP request directly to B's unicast MAC address. Instead, it uses the special Ethernet broadcast MAC ff:ff:ff:ff:ff:ff โ meaning "send this to everyone on the local network."
ARP Request
A โโโโโโโโโโโโโโโโโโโโโโโโ Everyone
โ
โโโ B
โโโ C
โโโ D
โโโ ...
Every device on the local network receives the ARP request. But only the device whose IP address matches 10.1.1.33 cares about it.
4. Host B Responds
B sees "Who has 10.1.1.33?" and knows its own IP (10.1.1.33) and MAC (b3b3). So B sends an ARP Reply directly back to A: 10.1.1.33 โ b3b3.
"I am 10.1.1.33, and my MAC address is b3b3."
This response is unicast, because B now knows A's MAC address.
5. ARP Cache
A stores the discovered mapping in its ARP cache: 10.1.1.33 โ b3b3. Similarly, B can learn 10.1.1.22 โ a2a2.
Now, if A wants to communicate with B again, it doesn't need to immediately broadcast another ARP request โ it can simply check its ARP cache (10.1.1.33 โ b3b3) and construct the Ethernet frame.
ARP gives the host the Layer 2 address it needs after knowing the Layer 3 destination.
6. A Can Finally Send the Actual Data
A now knows both Destination IP = 10.1.1.33 and Destination MAC = b3b3. So it creates a Layer 3 header (SRC IP = 10.1.1.22, DST IP = 10.1.1.33) and a Layer 2 header (SRC MAC = a2a2, DST MAC = b3b3).
The resulting structure is:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ L2 Header โ
โ SRC MAC: a2a2 โ
โ DST MAC: b3b3 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ L3 Header โ
โ SRC IP: 10.1.1.22 โ
โ DST IP: 10.1.1.33 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Data โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
And it is sent: A โโโโโโโโโโโโโโโโโโโโโโโโโโ B
7. What Happens When B Receives It?
B receives the Ethernet frame and first checks the destination MAC (DST MAC = b3b3). That's B's own MAC, so B accepts the frame.
The Layer 2 header is processed and removed (L2 โ). B then checks the Layer 3 destination (Destination IP = 10.1.1.33) โ that's B's own IP address, so the IP header is processed and removed too (L3 โ).
The remaining data moves upward to the appropriate protocol/application:
L2 โ remove ยท L3 โ process/remove ยท L4 โ process ยท L7 โ application
The Most Important Distinction
This is one of the most important things to remember:
IP Address answers: "Which host ultimately should receive this data?"
MAC Address answers: "Which device should receive this frame on this local network/hop?"
L3 โ IP โ end-to-end destination. L2 โ MAC โ current hop.
ARP connects these two worlds by resolving IP address โ MAC address.
Part 2 โ What Happens When the Destination Is on Another Network?
Now consider a more realistic situation. Host A wants to communicate with Host C, but C is on a different network.
Host A Router Host C
10.1.1.22 10.1.1.1 10.9.9.44
MAC a2a2 MAC e5e5 MAC c4c4
โ โ โ
โโโโโโโ Local network โโโโโโโโโโโโโโโโ Other networks โโโโโโโโ
A wants to send data to Destination IP = 10.9.9.44. A checks its subnet (10.1.1.0/24) and realizes 10.9.9.44 is not in its network โ so A needs the default gateway / router.
This is the key difference from Part 1:
A does NOT ARP for C. A ARPs for its default gateway.
1. A Knows C's IP
The Layer 3 destination remains C: SRC IP = 10.1.1.22, DST IP = 10.9.9.44. Notice that the destination IP is still the final destination โ A does not replace C's IP with the router's IP.
2. A ARPs for the Gateway
A asks:
"Who has 10.1.1.1? Tell me your MAC."
The router replies 10.1.1.1 โ e5e5, and A stores this in its ARP cache (10.1.1.1 โ e5e5). Now A knows the MAC address of the device that should receive the frame.
3. A Creates the Frame
Now notice the important part:
L3: SRC IP = 10.1.1.22 DST IP = 10.9.9.44
L2: SRC MAC = a2a2 DST MAC = e5e5
IP says:
"Ultimately go to C"
โ
A โโโโโโโโโโโโโโโโโโโโโโ Router
MAC says:
"This particular frame goes to the router"
This is one of the most important concepts in these networking fundamentals. The IP packet is intended for the final destination, but the Ethernet frame is intended for the next hop.
4. Router Receives the Frame
The router receives the Ethernet frame and sees DST MAC = e5e5 โ that's its own MAC address, so it accepts the frame and removes/processes the Layer 2 header.
Now it looks at the Layer 3 destination (DST IP = 10.9.9.44) and checks its routing table to determine where the packet should go next. This connects directly to what we learned earlier:
Routers make forwarding decisions using Layer 3 destination IP addresses and routing tables.
5. Router Forwards It Hop-by-Hop
There may be multiple routers between A and C:
A
โ
โผ
Router 1
โ
โผ
Router 2
โ
โผ
Router 3
โ
โผ
C
At every hop, the Layer 2 / MAC addresses change. But the Layer 3 destination remains 10.9.9.44:
Hop 1 โ MAC: A โ Router 1 IP: A โ C
Hop 2 โ MAC: Router 1 โ Router 2 IP: A โ C
Hop 3 โ MAC: Router 2 โ Router 3 IP: A โ C
So the mental model is:
MAC = current hop. IP = final destination.
This is exactly why we previously described:
L2 โ hop-to-hop. L3 โ end-to-end.
ARP in One Picture
The complete idea can now be summarized as:
Same network:
A โโ ARP for B's MAC โโโ B
โ
โโโ IP known
MAC unknown
Different network:
A โโ ARP for gateway's MAC โโโ Router
โ
โผ
Other network
โ
โผ
C
The crucial difference:
Same network โ ARP for destination host. Different network โ ARP for default gateway.
The Complete Mental Model
When a host wants to send an IP packet:
1. Know the destination IP
โ
2. Check: Is destination in my local network?
โ
โโโโโดโโโโโ
YES NO
โ โ
โ โ
ARP for ARP for
destination default gateway
MAC MAC
โ โ
โโโโโโฌโโโโโ
โ
Build Ethernet frame
โ
Send to next hop
And remember the hierarchy:
- L4 โ Port โ which service?
- L3 โ IP โ which host/network ultimately?
- L2 โ MAC โ which device on this hop?
- L1 โ Bits โ physical transmission
For your Cloud + DevOps learning, this becomes extremely important when reasoning about:
- VPC routing
- Subnets
- Default routes
- VPC routers
- Security Groups
- NACLs
- Load Balancers
- Connectivity troubleshooting
The AWS abstraction changes, but the underlying question remains the same:
Where is the destination, and what is the next hop needed to reach it?
Part 3 of 6 โ Networking Fundamentals for Cloud & DevOps
A prerequisite for understanding AWS VPC routing, subnets, gateways, and connectivity troubleshooting.
Top comments (0)