Loading
0x30Lesson 4 of 14

Connect IP addresses to the local link

See how ARP finds the MAC address of the next hop.

15 min 6-question quiz 1 code exercise
By the end of this lesson you can
  • Explain why a host needs both an IP address and a MAC address to send a packet.
  • Trace an ARP request and reply.
  • Decide which IP address a host resolves for local and remote destinations.

Here's a gap in the story so far. Your laptop knows the destination's IP address, but a frame needs a destination MAC address, and nothing has told the laptop what that is.

The Address Resolution Protocol (ARP) fills that gap. It works by asking everyone on the network.

Try it

Watch an ARP exchange

The laptop (192.168.1.10) wants to reach its gateway at 192.168.1.1, but its ARP cache is empty. Predict each step before revealing it.

Message 1 of 4Predicted 0/0
Laptop
Printer
Gateway

Predict: The laptop has no idea which device owns 192.168.1.1. How does it ask?

Which address does it look up?

This is the part that trips people up. A host never ARPs for a destination on another network, because ARP broadcasts don't cross routers. It uses the rule from the previous lesson:

  • Same subnet: ARP for the destination itself.
  • Different subnet: ARP for the default gateway, and send the frame there.

So a packet to a server on another continent is sent in a frame addressed to your router. The IP header holds the server's address, and the Ethernet header holds the router's.

next_hop.py
1import ipaddress
2
3interface = ipaddress.ip_interface("192.168.1.10/24")
4gateway = "192.168.1.1"
5
6def next_hop(destination):
7    if ipaddress.ip_address(destination) in interface.network:
8        return destination
9    return gateway
10
11for destination in ["192.168.1.50", "203.0.113.8", "8.8.8.8"]:
12    print(f"{destination} -> ARP for {next_hop(destination)}")
Output
192.168.1.50 -> ARP for 192.168.1.50
203.0.113.8 -> ARP for 192.168.1.1
8.8.8.8 -> ARP for 192.168.1.1

Try it

Who gets the ARP request?

Your laptop is 192.168.1.10/24 and its gateway is 192.168.1.1. For each destination, decide which address it needs to resolve.

0 of 4 sortedScore 0/0
  • “The printer at 192.168.1.40”

  • “A web server at 203.0.113.8”

  • “A file server at 192.168.2.40”

  • “The gateway at 192.168.1.1”

Key takeaways

  • ARP turns a local IPv4 address into a MAC address.

  • Requests are broadcast, and replies go straight back to the asker.

  • Off-subnet traffic is framed to the gateway, so that's the address a host resolves.

Lesson quiz

6 questions · pass with 5 correct · up to 50 XP

Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.

Practice: model networking concepts

Use small Python programs to model packet, address, and protocol behavior. These exercises run locally in your browser and do not send network traffic.

Exercise 1

Choose the address to resolve

+25 XP

The host below is 192.168.1.10/24 with gateway 192.168.1.1. Read a destination IP address and print ARP for <address> with the address the host must resolve.

  • A local printer
  • A remote server
  • A similar-looking network
main.py
Loading editor…

Python runs in a sandboxed browser worker with a 60 second time limit. Its runtime loads from the Pyodide CDN; your code stays in this browser.

Questions about this lesson

Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.

Loading posts…