Skip to content

Linux Foundations / Follow traffic and find the fault ยท Step 28 of 46

Lesson: arpSwitch
โ† Linux Foundations

Network operations

arp

Inspect the ARP cache that maps IPv4 addresses to hardware addresses on your local network.

On an Ethernet or Wi-Fi network, an IP address is not enough to deliver a frame. Your machine also needs the neighbour's MAC (hardware) address. IPv4 uses the Address Resolution Protocol (ARP) to find it.

How ARP works

Your host broadcasts a question on the local network: "Who has 192.168.1.1?" The owner replies with its MAC address. The answer is stored in the ARP cache so the question need not be asked for every packet.

ARP works only on the local link. To reach a remote address, your machine looks up the MAC address of the gateway, not of the far server. IPv6 uses Neighbor Discovery instead of ARP.

Viewing the cache

$ arp -n
Address       HWtype  HWaddress          Flags Mask  Iface
192.168.1.1   ether   52:54:00:aa:bb:cc  C           enp3s0

-n shows numeric addresses. The C flag marks a completed entry and M marks a permanent one. An entry shown as incomplete means no reply has arrived.

The modern command

arp belongs to net-tools, which may not be installed. Use ip neigh:

$ ip neigh show
192.168.1.1 dev enp3s0 lladdr 52:54:00:aa:bb:cc REACHABLE

Common states are REACHABLE (recently confirmed), STALE (known but needs checking before it is trusted again), FAILED (no answer) and PERMANENT (added by hand). STALE is normal and not an error.

Changing entries

These need root:

$ sudo arp -d 192.168.1.1
$ sudo arp -s 192.168.1.9 52:54:00:11:22:33
$ sudo ip neigh flush dev enp3s0

-d deletes an entry and -s adds a static one. flush clears learned entries on an interface. They are relearned as needed.

Clearing an entry helps after you replace a device that keeps the same IP address, though caches usually correct themselves in time.

ARP has no authentication, so a hostile device on your network can send false replies. This is called ARP spoofing. See the networking basics guide for how addresses fit together.

Try it

  1. Run ip neigh show.
  2. Ping your gateway with ping -c 1 and its address, then look again.
  3. Find the MAC address and state of the gateway entry.

Check your understanding

arp

All 4 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.