Computer Network 📂 Network Layer · 5 of 6 64 min read

Routers, ARP & ICMP Explained: How Packets Find Their Way — Animated Deep Dive

Discover how routers forward packets hop-by-hop, how ARP resolves IP addresses to MAC addresses on local networks, and how ICMP enables ping, traceroute, and error reporting. Features fully animated diagrams for packet forwarding, NAT, ARP request/reply, ping probes, and traceroute path discovery. Includes real-world incidents and a practitioner's golden rules checklist.

Section 01

What Is a Router? — The Postal Sorting Office of Networking

The Postal Sorting Office
Imagine a massive postal sorting office at the centre of a city. Every parcel that arrives has a destination address written on it. Workers read that address, look it up in a sorting guide, and place the parcel on the correct outbound conveyor belt — heading toward the next sorting office closer to the destination.

A router works exactly like this. It receives data packets, reads their destination IP address, looks it up in its routing table, and forwards the packet out the correct interface — one hop closer to the destination. The packet may cross dozens of routers before it arrives. No single router needs to know the full journey — only the next hop.

A router operates at Layer 3 (Network Layer) of the OSI model. Unlike a switch that forwards frames by MAC address within one network, a router makes intelligent forwarding decisions across different networks using IP addresses. Every time you load a webpage, your packets pass through 10–20 routers on average.

📌
Three Things a Router Always Does

1. Receives an incoming packet on one interface.
2. Looks up the destination IP in its routing table to find the best next hop.
3. Forwards the packet out the appropriate interface, decrementing the IP TTL by 1.

Router Internal Architecture

📋
Routing Table (RIB)
Routing Information Base
A database of known networks, the cost to reach them, and which interface / next-hop to use. Populated by static routes or dynamic protocols (OSPF, BGP, RIP).
Forwarding Table (FIB)
Forwarding Information Base
A hardware-optimised version of the routing table, used for line-rate packet forwarding. Modern routers use TCAM (Ternary Content-Addressable Memory) for nanosecond lookups.
📸
ARP Cache
Address Resolution Protocol
Maps IP addresses to MAC addresses for the next hop on each directly connected network segment. Routers must resolve the MAC of the next-hop before forwarding.

Routing Table — Longest Prefix Match

When a packet arrives, the router finds the most specific matching route — not just any match. This is called Longest Prefix Match (LPM).

🔎 LPM Example — Packet to 192.168.10.45
Route 1
0.0.0.0/0 → Default route via 10.0.0.1  [0 bits match — least specific]
Route 2
192.168.0.0/16 → via 10.0.0.2  [16 bits match]
Route 3
192.168.10.0/24 → via 10.0.0.3  [24 bits match]
WINNER
192.168.10.0/24 — longest match wins → packet goes via 10.0.0.3

Section 02

🏭 Animated: How a Router Forwards Packets

The animation below shows a packet travelling from a laptop through three routers to reach a web server. Watch how each router decrements the TTL, looks up the next hop, rewrites the MAC addresses, and forwards the packet.

▶ Packet Forwarding Animation — End-to-End Journey
Ready

💡 Each router reads the destination IP, looks up its routing table, rewrites Layer-2 MAC header, decrements TTL and forwards. The IP header (Layer 3) stays intact — only the MAC frame changes.

What Changes at Each Hop?

📝 Layer 3 — IP Header (UNCHANGED)
FieldValue
Source IP192.168.1.10 ✓ same
Destination IP203.0.113.5 ✓ same
TTLDecremented by 1 each hop
ProtocolTCP/UDP/ICMP ✓ same
💾 Layer 2 — MAC Frame (REWRITTEN every hop)
FieldValue
Source MACRouter's outgoing port MAC
Destination MACNext-hop router's MAC
Frame scopeOnly valid on one link segment
Resolved viaARP (see Section 04)
⚠️
TTL = 0? Packet Dropped + ICMP Time Exceeded Sent

If a packet's TTL reaches zero at a router, the router drops the packet and sends an ICMP Time Exceeded message back to the original sender. This prevents packets from looping forever inside a misconfigured network. The traceroute command deliberately exploits this: it sends packets with TTL=1, 2, 3… forcing each router to reply with ICMP Time Exceeded, mapping the path.

Real-World Context: The Facebook 2021 Outage

Facebook's Routers Disappeared from the Internet
A routine BGP configuration change caused Facebook's routers to withdraw all their routes from the global Internet routing table. From every other router on Earth, Facebook's IP addresses simply ceased to exist.

Because even Facebook's internal systems relied on the same BGP infrastructure, engineers couldn't remotely access tools to fix it. They had to physically drive to data centres, badge through doors, and manually restore routing. The outage lasted 6 hours and cost an estimated $60 million in revenue. 3.5 billion users were affected.

Source: Facebook Engineering Blog, October 2021; New York Times, "Facebook's Services Are Back Online After a Six-Hour Outage" — Oct 5, 2021.

Section 03

Types of Routers & NAT

🏠
Home / SOHO Router
Combines router, switch, Wi-Fi access point, DHCP server, and NAT in one box. Your ISP assigns one public IP; all home devices share it via NAT. Examples: TP-Link Archer, Asus RT-AX.
NAT + DHCP + Wi-Fi + Firewall
🏢
Enterprise Edge Router
Connects an organisation's internal network to the ISP. Runs BGP to exchange routes. Handles traffic shaping, QoS, and policy routing. Examples: Cisco ASR 1000, Juniper MX Series.
BGP + QoS + Redundant links
🔌
Core / Backbone Router
Forwards hundreds of gigabits per second inside an ISP's backbone. Runs OSPF/IS-IS internally, BGP externally. Pure packet forwarding — no NAT, no DHCP. Examples: Cisco CRS, Juniper PTX.
Line-rate forwarding + MPLS

How NAT Works — Network Address Translation

🔄 NAT Translation Animation — Many Private IPs → One Public IP
Step 0 — Initial state

💡 NAT rewrites the source IP+port on outbound packets and reverses the translation on replies. The NAT table maps (private IP : port) ↔ (public IP : port).


Section 04

ARP — Address Resolution Protocol

IP addresses identify a destination logically. But data travels over physical hardware — Ethernet cables and Wi-Fi — using MAC addresses. Before a device can send a frame to its neighbour, it must answer a critical question: "I know the IP address of the next hop — but what is its MAC address?"

ARP (RFC 826, 1982) solves this. It maps IPv4 addresses to MAC addresses on a local network segment. Every device maintains an ARP cache to avoid broadcasting this question repeatedly.

Shouting a Name in a Room
You know your friend's name (their IP address) but not their face (MAC address). You stand in the middle of the room and shout: "Hey, is John Smith here? If so, please wave so I can see you!"

Everyone hears the shout (broadcast), but only John waves back (unicast reply). Now you know which face belongs to the name. You write it in your notebook (ARP cache) so you don't have to shout again for a while.

ARP Message Format

📥 ARP Packet Structure
Hardware Type
0x0001 = Ethernet. Identifies the Layer-2 technology in use.
Protocol Type
0x0800 = IPv4. Identifies the Layer-3 protocol being resolved.
Operation
1 = ARP Request (broadcast)  |  2 = ARP Reply (unicast)
Sender MAC
MAC address of the sender. Always filled — receivers update their ARP cache with this.
Sender IP
IP address of the sender.
Target MAC
In a Request: FF:FF:FF:FF:FF:FF (unknown, broadcast). In a Reply: filled with actual MAC.
Target IP
The IP address being resolved. The device with this IP answers.

Section 05

🏭 Animated: ARP Full Working — Request & Reply

▶ ARP Protocol Animation — Step by Step
Ready — Click Play

💡 ARP works only on the local subnet. To reach a different network, the host sends an ARP for its default gateway MAC — the router handles the rest.

ARP Edge Cases & Variants

🧰
Gratuitous ARP
GARP — Self-announcement
A device ARPs for its own IP. Used on boot to detect IP conflicts, and by failover systems (e.g., HSRP/VRRP) to announce a new MAC for a virtual IP — updating all neighbour ARP caches instantly.
🚫
Proxy ARP
Router answers on behalf of host
A router answers ARP requests for a remote IP with its own MAC, allowing hosts without a default gateway configured to still communicate. Enabled by default on many Cisco interfaces (ip proxy-arp).
🔐
ARP Spoofing (Attack)
Man-in-the-Middle vector
An attacker broadcasts fake ARP replies poisoning neighbour caches — e.g., "192.168.1.1 is at MY MAC." All traffic intended for the gateway flows through the attacker. Mitigated by Dynamic ARP Inspection (DAI) on managed switches.
⚠️
Real Incident: ARP Spoofing in the 2013 Spamhaus DDoS

During the 300 Gbps DDoS attack against Spamhaus in 2013 — at the time the largest DDoS in internet history — attackers used ARP cache poisoning alongside DNS amplification to redirect and amplify traffic. ARP's lack of authentication makes it a perennial vector for LAN-level attacks. Source: Cloudflare Blog, "The DDoS That Almost Broke the Internet" — March 2013.

ARP vs NDP — IPv4 vs IPv6

FeatureARP (IPv4)NDP / ICMPv6 (IPv6)
ProtocolStandalone (EtherType 0x0806)Part of ICMPv6 (Type 135/136)
Discovery methodBroadcast to 255.255.255.255Multicast to Solicited-Node address
AuthenticationNone — spoofableSEND (optional crypto)
Router discoveryRequires separate DHCP/ICMPBuilt-in (RA/RS messages)
Broadcast trafficHigh — affects all LAN hostsLow — targeted multicast only
Cache entry nameARP CacheNeighbour Cache

Section 06

ICMP — Internet Control Message Protocol

IP is a best-effort protocol. It makes no guarantees about delivery. So how does a sender know if something went wrong? Enter ICMP (RFC 792). ICMP is a diagnostic and error-reporting companion to IP — it rides inside IP packets (Protocol number 1) and is used by network devices to report errors, test reachability, and discover path characteristics.

ICMP is not a transport protocol — it carries no user data. It is the network's built-in feedback mechanism. Without ICMP, problems like "no route to host" or "TTL exceeded" would be completely invisible to the sender.

💡
ICMP Lives Inside IP

ICMP is encapsulated inside an IPv4 packet with Protocol=1. It is not a transport layer protocol — it has no port numbers, no sessions, no ordering. It is Layer 3 signalling: the network infrastructure talking to itself and to endpoints about what went wrong (or right).

ICMP Message Types

TypeCodeNameTriggered ByUsed In
00Echo ReplyResponse to Type 8ping
30–15Destination UnreachableNo route / port closed / filteredError detection
40Source Quench (deprecated)Congestion — router buffer fullLegacy flow control
50–3RedirectBetter route exists via another gatewayRouting optimisation
80Echo RequestUser sends pingping
110Time ExceededTTL reached 0 at routertraceroute
120Parameter ProblemBad IP header fieldError detection
13/140Timestamp Request/ReplyClock synchronisation probeLegacy timing

Destination Unreachable — Code Details

🚫 ICMP Type 3 — Destination Unreachable Codes
Code 0
Net Unreachable — No route to the destination network exists in the routing table.
Code 1
Host Unreachable — Network is reachable but the specific host does not respond (ARP fails).
Code 2
Protocol Unreachable — The host does not support the transport protocol (e.g., destination has no UDP stack).
Code 3
Port Unreachable — No application is listening on the destination port. Classic UDP response.
Code 4
Fragmentation Needed — Packet is too large and the Don't Fragment (DF) bit is set. Used in Path MTU Discovery.
Code 13
Communication Administratively Prohibited — A firewall/ACL blocked the packet.

Section 07

🏭 Animated: ICMP Echo (ping) — Full Working

▶ ICMP ping Animation — Echo Request / Reply with RTT
Ready

💡 Each ping sends ICMP Type 8 (Echo Request). The destination replies with ICMP Type 0 (Echo Reply). RTT = total round-trip time. Three probes shown to simulate a real ping command.


Section 08

🏭 Animated: traceroute — ICMP Time Exceeded in Action

traceroute exploits ICMP Type 11 (Time Exceeded). It sends packets with TTL=1 first — the first router drops it and replies "Time Exceeded." Then TTL=2 — the second router replies. And so on, mapping each hop.

▶ traceroute Animation — Mapping the Path Hop by Hop
Ready

💡 Linux: traceroute uses UDP probes. Windows: tracert uses ICMP Echo Requests. Both exploit the TTL mechanism identically.


Section 09

ICMP in the Real World — Attacks, Firewalls & Incidents

💔
Ping of Death (CVE-1996)
Sending an ICMP Echo Request larger than 65,535 bytes caused stack overflows in early Windows/Unix kernels, crashing systems. The fragmentation reassembly code didn't handle oversized ICMP packets. Patched in all modern OS, but remains a classic.
ICMP Type 8 | Fragmentation exploit
💥
ICMP Flood / Smurf Attack
Attacker spoofs victim's IP as source, sends broadcast pings to many networks. Every host replies to the victim — amplified DDoS. The 1998 Smurf attack overwhelmed major internet backbones. Mitigated by blocking directed broadcasts and BCP38 source address filtering.
ICMP Amplification | Broadcast abuse
🔌
ICMP Tunnelling
Tools like icmptunnel embed TCP/IP data inside ICMP payload fields, creating a covert channel that bypasses firewalls allowing ICMP but blocking TCP. Used by malware for C2 communication. The 2020 SolarWinds attackers used similar covert channels.
ICMP payload abuse | C2 evasion
🚫
Should You Block ICMP? — The Firewall Dilemma

Many network admins block all ICMP at the firewall — but this breaks critical functionality. ICMP Type 3 Code 4 (Fragmentation Needed) is essential for Path MTU Discovery — blocking it causes TCP connections to silently stall when crossing links with smaller MTUs. RFC 4890 defines exactly which ICMP types should be permitted through firewalls and which can be safely blocked. The rule: never block Types 3, 11, and 12 from outside. Type 8 (ping) is optional.

Path MTU Discovery — ICMP Type 3 Code 4 in Action

🔂 Path MTU Discovery — ICMP "Fragmentation Needed" Message

When a large packet hits a smaller MTU link and the DF bit is set, the router returns ICMP Type 3 Code 4, telling the sender to reduce its packet size.


Section 10

How Routers, ARP & ICMP Work Together

These three protocols are deeply intertwined. When you type a URL, here is the complete sequence that happens before a single byte of webpage arrives:

1
DNS → IP Address
Your OS resolves the hostname to an IP address (e.g., 142.250.80.46 for google.com) via DNS. Now it has a destination IP.
2
Routing Decision — Is it local or remote?
The OS compares the destination IP to its subnet. It's on a different network → must go through the default gateway (your router).
3
ARP — Resolve the Gateway's MAC
Your OS checks its ARP cache for the gateway's MAC. Cache miss → broadcasts ARP Request. Gateway replies with its MAC. Now the Ethernet frame can be constructed.
4
Packet sent — Router receives it
The router receives the frame, strips the L2 header, looks up the destination IP in its FIB, decrements TTL, ARPs for the next hop's MAC, and forwards.
5
Across the Internet — ICMP handles errors
If any router finds no route, it sends ICMP Destination Unreachable. If TTL hits 0, ICMP Time Exceeded is sent. If MTU is too small, ICMP Fragmentation Needed triggers Path MTU Discovery.
6
Destination receives, TCP handshake begins
The server receives the IP packet, delivers it to the TCP stack, and the three-way handshake begins. All built on the foundation of Routers + ARP + ICMP.

Quick-Reference Comparison

FeatureRouterARPICMP
OSI LayerLayer 3Layer 2/3 boundaryLayer 3
PurposeForward packets between networksResolve IP → MAC on local segmentError reporting & diagnostics
ScopeInter-network (global)Local subnet onlyEnd-to-end (global)
TransportIP datagram forwardingEtherType 0x0806IP Protocol 1
Stateful?Routing table is statefulARP cache (soft-state)Fully stateless
Security riskRoute hijacking (BGP)ARP spoofing / MITMPing flood / tunnelling
Key toolip route, show ip routearp -a, ip neighping, traceroute

Section 11

Golden Rules — Routers, ARP & ICMP

📌 Non-Negotiable Rules for Every Network Engineer
1
The IP header's Dst IP never changes across hops — only the MAC frame does. Confusing Layer 2 (MAC) and Layer 3 (IP) addressing is the most common misconception. Routers rewrite MAC at each hop; they never touch the source/destination IP unless NAT is involved.
2
ARP is local-only. You never ARP for a remote host's IP — you ARP for your gateway's IP. If a host is missing a default gateway, it can talk to local hosts but nothing beyond its subnet. Always check arp -a first when diagnosing connectivity failures.
3
Never block ICMP Type 3 (Destination Unreachable) or Type 11 (Time Exceeded) at firewalls. Blocking these silently breaks Path MTU Discovery and hides routing problems. Blocking ping (Type 8) is a separate, acceptable policy choice.
4
An ARP cache entry typically lives for 20 minutes. After that, it is re-resolved. In high-availability setups (HSRP/VRRP failover), use Gratuitous ARP immediately after failover to flush stale MAC entries from all hosts on the segment.
5
Enable Dynamic ARP Inspection (DAI) on managed switches. DAI validates ARP packets against the DHCP snooping binding table, dropping packets with spoofed IP/MAC mappings. It is your primary defence against ARP poisoning attacks.
6
TTL is your first diagnostic clue. A ping returning TTL=118 (from a 128-start) means the packet crossed 10 routers. TTL=64 start is Linux/macOS default; TTL=128 is Windows default. Use traceroute to pinpoint exactly where packets die.
7
Routers use Longest Prefix Match — specificity beats generality. A /32 host route always wins over a /24 network route which always wins over a /0 default. If traffic behaves unexpectedly, always check for a more-specific route that might be overriding your expected path.
🎓
The Complete Picture

Routers are the post offices of the Internet — they read IP addresses and forward packets toward their destination, hop by hop.

ARP is the name-to-face lookup — it resolves "I know the IP, what's the MAC?" on each local link, making physical delivery possible.

ICMP is the network's nervous system — it carries error signals (unreachable, TTL expired, fragmentation needed) and diagnostic probes (ping, traceroute) that make the invisible visible. Together, they form the complete foundation of IP networking.