Computer Networks / Lecture / Lecture 13
Lecture · Computer Networks

Operating Principles of the ICMP and ARP Protocols

You type ping 8.8.8.8 — and in an instant the reply “Reply from 8.8.8.8: time=34ms” arrives. It is ICMP that brings this reply. But before the packet leaves your computer, one more small “survey” takes place: “Who has 192.168.1.1? Tell me your MAC address!” — that is ARP. Today you will meet two “invisible helpers” of the network: one reports errors and diagnostics, the other binds an IP address to a MAC address.

:ik-kitob: Lecture 13 ⏱ 2 academic hours (80 minutes) 🚇 Packet simulators ⚡ Who is there? Answer!
13

Lesson goals and plan

By the end of the lesson you will…

  • explain the task and main types of ICMP messages (Echo Request/Reply, Destination Unreachable, Time Exceeded, Redirect)
  • read the results of ping and tracert (traceroute) and guess where the problem in the network is
  • explain the TTL field and the mechanism of tracert through ICMP Time Exceeded
  • describe step by step the process of an ARP request (broadcast) and reply (unicast)
  • read the arp -a table and explain dynamic and static entries and the ageing of the ARP cache
  • determine whom ARP is sent to when accessing a local or a remote address, and model it in Python
  • name the danger of ARP spoofing and ways to protect against it

Plan (according to the syllabus)

  1. The tasks of the ICMP protocol in network diagnostics and in carrying service messages
  2. The process of mapping an IPv4 address to a MAC address with the ARP protocol and the interaction of the protocols in a local network

Today’s lesson is a “diagnostics day”. In each simulator first make your own prediction: where will the packet go, who will answer? Then click the button and check. This habit will later help you find real network faults quickly :ik-quti:

Why does the first ping sometimes start with “Request timed out” while the following ones work perfectly?

If you send a ping from a freshly powered-on computer to a neighbouring printer, sometimes the first reply is delayed or lost. The reason is simple: the computer does not yet know the printer’s MAC address. It first shouts to the whole local network “Who has 192.168.1.40?” (ARP), and only when the answer comes does it send the ICMP packet. By the end of this lesson you will see with your own eyes in a simulator how these two protocols “cooperate”.

Key terms

First try to recall the meaning of the term yourself, then click the card to check.

The tasks of the ICMP protocol in network diagnostics and in carrying service messages

The IP protocol works on the “best effort” principle: if a packet is lost, IP itself does not know it and tells nobody. This gap is filled by ICMP — the network’s “messenger post”: if a router cannot deliver a packet, it writes to the sender with the reason.

Definition

ICMP (Internet Control Message Protocol) is a protocol that carries error and control (service) messages in IPv4 networks (RFC 792). An ICMP message is carried inside an IP packet (the “Protocol” field in the IP header = 1), but it is not a transport protocol like TCP or UDP — there are no ports. It is usually considered part of the network (3rd) layer. For IPv6 there is a separate version — ICMPv6.

How is an ICMP message structured?

At the beginning of every ICMP message there are three fields: Type (the type, 1 byte), Code (a clarifying code, 1 byte) and Checksum (the checksum, 2 bytes). After that comes additional data depending on the message type. In error messages the IP header and the first 8 bytes of the original packet that caused the problem are also included — so that the sender knows which packet “died”.

IP header Protocol = 1, TTL, Src, Dst Type1 byte Code1 byte Checksum2 bytes Data partID, Seq or the original packet An ICMP message is the “cargo” (payload) of an IP packet
Figure 13.1. An ICMP message is carried inside an IP packet

The most important ICMP messages

Table 13.1. The main types of ICMPv4
TypeNameWhen it is sentIn real life
8Echo RequestThe “are you alive?” requestsent by ping
0Echo ReplyThe reply to an Echo RequestThe “Reply from…” line
3Destination UnreachableThe destination could not be reached. Codes: 0 — network, 1 — host, 3 — port unreachable, 4 — fragmentation needed but the DF flag is set“Destination host unreachable”
11Time ExceededThe TTL reached 0 (code 0) or the fragments were not reassembled in time (code 1)tracert uses this message
5RedirectA router: “it is better to go to this address through another gateway”When there are two routers on one segment
12Parameter ProblemAn incorrect field in the IP headerRarely seen
Did you know?

An ICMP error message is never sent in response to another ICMP error. Otherwise two devices would write endless “errors about errors” to each other and flood the network. Also, no error message is returned for packets sent to a broadcast address.

ping — the “are you alive?” question

ping sends an ICMP Echo Request to the target address and waits for an Echo Reply. The time that passes until the reply arrives is called RTT (Round-Trip Time). In Windows, 4 requests are sent by default.

cmd — ping result
C:\Users\Talaba> ping 8.8.8.8

Pinging 8.8.8.8 with 32 bytes of data:
Reply from 8.8.8.8: bytes=32 time=34ms TTL=117
Reply from 8.8.8.8: bytes=32 time=33ms TTL=117
Reply from 8.8.8.8: bytes=32 time=41ms TTL=117
Reply from 8.8.8.8: bytes=32 time=35ms TTL=117

Ping statistics for 8.8.8.8:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 33ms, Maximum = 41ms, Average = 35ms
Table 13.2. “Translating” ping messages
On the screenMeaningWhat to do
Reply from … time=34msAn Echo Reply came, there is connectivityEverything is fine; look at the size of the time
Request timed out.No reply came within the set timeThe host is off, a firewall blocks ICMP, or the packet was lost
Reply from 192.168.1.1: Destination host unreachable.The router (or your own computer) could not find a route to the host — ICMP type 3Is the address correct? Is the host in this network?
Reply from 10.0.0.1: TTL expired in transit.The TTL ran out along the way — ICMP type 11There may be a routing loop
Ping request could not find host …DNS could not turn the name into an IPThis is not ICMP, it is a DNS problem (Lecture 15)
Tip

TTL=117 in the reply is the remaining TTL value of the packet that reached you. Many systems start TTL at 64, 128 or 255. If it is 117, it probably started from 128 and passed through about 11 routers on the way. This is an estimate, not a strict rule.

tracert — the packet’s “metro map”

tracert (traceroute in Linux/macOS) uses a very clever trick: it sends the first packet with TTL = 1. The first router reduces the TTL to 0, drops the packet and returns ICMP Time Exceeded to the sender — and thereby “reveals” its own address. Then TTL = 2, 3, … and so on, until the destination answers with an Echo Reply. tracert in Windows sends 3 ICMP Echo Requests at each step; traceroute in most Linux systems by default uses UDP packets (at the end a “Port Unreachable” comes).

:ik-xarita: Tracert simulator: from Andijan to 8.8.8.8 (a teaching example)

With every click the TTL increases by 1. Watch at which “station” the packet dies and who returns the ICMP message.

TTL = 0
cmd — tracert 8.8.8.8
C:\Users\Talaba> tracert 8.8.8.8

Tracing route to dns.google [8.8.8.8]
over a maximum of 30 hops:

Click the button…

Note

The addresses 198.51.100.x and 203.0.113.x in the simulator are addresses reserved for documentation and teaching examples (RFC 5737). The real route will differ depending on your provider. If a * sign appears in tracert, that router is configured not to send ICMP replies; this is not always a fault.

What else is ICMP needed for?

:ik-olcham:

Path MTU Discovery

If a packet is too big and the “don’t fragment” (DF) flag is set, the router sends type 3 code 4. The sender reduces the packet size. Blocking ICMP completely makes some websites “hang”.

:ik-takror:

Detecting loops

If a packet circulates because of a routing error, the TTL runs out and the “TTL expired in transit” message points to the problem.

:ik-taqiq:

Closed port

If a UDP packet arrives at a closed port, the host returns type 3 code 3 (Port Unreachable).

Security

Attackers use ICMP too: finding live hosts by “sweeping the network with ping” (ping sweep), and ICMP flood (filling the channel with a large number of requests). That is why organizations often restrict incoming Echo Requests from outside, but it is recommended not to close types 3 and 11 completely — they are needed for the network to work properly.

The process of mapping an IPv4 address to a MAC address with the ARP protocol and the interaction of the protocols in a local network

Imagine: in a dormitory you know the room number (IP), but to hand over a letter you must recognize the person’s face (MAC). You go out into the corridor and shout “Who lives in room 312?” — and only that person answers “It’s me!”. This is exactly how ARP works.

Definition

ARP (Address Resolution Protocol) is a protocol that determines, in a local network (on one link segment), the MAC address of a device with a known IPv4 address. The reason: delivering Ethernet and Wi-Fi frames requires a MAC address, while applications work with an IP address. ARP is the “interpreter” between these two worlds. ARP messages are placed directly in an Ethernet frame (EtherType 0x0806), not in an IP packet. In IPv6 the place of ARP is taken by Neighbor Discovery based on ICMPv6.

ARP step by step

  1. Checking the cache

    PC-A (192.168.1.10) wants to send a packet to 192.168.1.40. First it looks at its own ARP cache: is there a MAC for this IP? If there is, it sends the frame immediately; ARP is not needed.

  2. ARP Request — broadcast

    If it is not in the cache, the request “Who has 192.168.1.40? Tell 192.168.1.10” is sent. The destination MAC address of the Ethernet frame is FF-FF-FF-FF-FF-FF, that is, every device in the segment receives it. The request also contains the sender’s own IP and MAC address.

  3. Everyone checks, one answers

    Each device compares the target IP in the request with its own. Those that do not match quietly drop the frame. The owner of 192.168.1.40 (usually) also records the sender’s IP–MAC pair in its own cache.

  4. ARP Reply — unicast

    The reply “192.168.1.40 is at 00-1B-A9-4C-21-77” is sent only to PC-A, to its MAC address.

  5. Writing to the cache and sending

    PC-A adds the pair to the cache as a dynamic entry and sends the waiting packet. The entry ages after a while (in Windows usually tens of seconds, on Cisco routers 4 hours by default) and at the next access ARP is performed again.

The most important question: whose MAC address is asked for?

ARP works only inside the local segment — a broadcast does not pass through a router. Therefore:

The target is in my own network

192.168.1.10/24 → 192.168.1.40: the network part is the same (192.168.1.0/24). ARP asks for the MAC address of 192.168.1.40 itself directly.

The target is in another network

192.168.1.10/24 → 8.8.8.8: another network. The packet is handed to the default gateway (192.168.1.1), so ARP asks for the gateway’s MAC address. In the frame the destination MAC is the router, while the destination IP in the IP header is 8.8.8.8.

Remember

At every “hop” the packet is wrapped in a new Ethernet frame and the MAC addresses change, while the IP addresses stay the same along the whole way (except for NAT — in Lecture 15). In the metro analogy: the IP is the final station, the MAC is the next station.

Simulator: ARP broadcast and ARP cache

Send pings from PC-A to different addresses. Watch what happens when the cache is empty, and that on the next ping ARP is not needed. The “Pass time” button ages the entries in the cache. At the end see what happens when the attacker (PC-C) sends a forged ARP reply.

:ik-wifi: ARP laboratory — the 192.168.1.0/24 network

Ping from PC-A:
ARP cache of PC-A (arp -a)
Internet AddressPhysical AddressTypeTTL
Log
Send a ping…

Reading the arp -a table

cmd — arp -a
C:\Users\Talaba> arp -a

Interface: 192.168.1.10 --- 0x7
  Internet Address      Physical Address      Type
  192.168.1.1           c8-3a-35-08-90-01     dynamic
  192.168.1.40          00-1b-a9-4c-21-77     dynamic
  192.168.1.255         ff-ff-ff-ff-ff-ff     static
  224.0.0.22            01-00-5e-00-00-16     static
  224.0.0.251           01-00-5e-00-00-fb     static
  255.255.255.255       ff-ff-ff-ff-ff-ff     static
Table 13.3. The columns and entries of arp -a
EntryNote
Interface: 192.168.1.10 --- 0x7The cache of which network card is being shown (if there are several cards, a separate table for each)
dynamicLearned through ARP, ages after a while
staticSet manually or by the system, does not age. The broadcast (.255) and multicast (224.x.x.x → 01-00-5e-…) addresses are here
arp -d *Clearing the cache (administrator rights are needed)
arp -s 192.168.1.1 c8-3a-35-08-90-01Adding a static entry — a simple protection against ARP spoofing

The “dance” of the protocols in a local network

Now we combine the two protocols. When you open a website in a browser (or send a simple ping), the following sequence takes place in the local network:

:ik-plus:

Gratuitous ARP

When a device connects to the network it sends an ARP for its own IP: if a reply comes — there is an IP conflict. A DHCP client also checks this way before accepting an address (Lecture 14).

:ik-qalqon:

Proxy ARP

A router answers with its own MAC address on behalf of a host in another segment. It is found in old networks and is rarely used today.

:ik-ayg-oqchi:

ARP spoofing

ARP has no authentication: whoever answers is “right”. Protection: Dynamic ARP Inspection on the switch, static entries for important devices, encrypted protocols (HTTPS, VPN).

Modeling ICMP and ARP logic in Python

Writing the logic of a protocol in code is the best way to understand it deeply. In every task use input() without a prompt and click the :ik-tekshir: Check button. Python’s standard ipaddress module makes working with IP addresses easier.

Mini-boss: ARP spoofing detector

The number of lines n of the arp -a output is input, then n lines in the form “IP MAC type”. If the same MAC address appears with several different IPs (except the broadcast ff-ff-ff-ff-ff-ff and the multicast addresses starting with 01-00-5e), for each such MAC print “Shubhali: MAC (IP1, IP2…)” — the IPs in input order, the MACs in the order of first appearance. If there is no suspicious MAC — “Toza”. +40 XP

Common mistakes

MisconceptionIn fact
“The ping did not go through — so the server is not working”Many servers and the Windows firewall block ICMP Echo. If the site opens in the browser but ping does not go through, that may be a normal situation.
“ICMP is ping and nothing else”ping is only one use of ICMP. Error messages, MTU discovery and Redirect are also ICMP.
“ARP works across the Internet”ARP works only in the local segment. For a remote address the gateway’s MAC address is requested.
“ARP is a 3rd-layer protocol and travels inside IP”ARP is carried directly in an Ethernet frame (EtherType 0x0806) — it is a “bridge” between the 2nd and 3rd layers.
“The MAC address does not change along the whole way”At every hop the frame is built anew: the source and destination MACs change, while the IPs stay.
“If I close ICMP completely, it will be safer”If type 3 code 4 disappears, Path MTU Discovery breaks and some connections “hang”.

Reinforcement

// REMEMBER IN 1 MINUTE

  1. ICMP — the service and error messages of an IP network; inside IP, Protocol = 1, no ports.
  2. ping: Type 8 → Type 0; tracert: TTL = 1, 2, 3… and Type 11 (Time Exceeded).
  3. Type 3 — Destination Unreachable (0 network, 1 host, 3 port, 4 fragmentation needed).
  4. ARP: IPv4 → MAC; the request is broadcast (FF-FF-…), the reply is unicast; the result goes into the ARP cache.
  5. For a remote address ARP asks for the gateway’s MAC address. ARP has no authentication → the risk of spoofing.
:ik-oyin:The “ping” in an online gameThe 40 ms on the game screen is the round-trip time (RTT) to the server. The very same concept is in the ping command too.
:ik-bino:The university computer roomWhen a computer is switched on it learns the MAC addresses of the gateway and the printer through ARP — that is why the first print job may start more slowly.
:ik-wifi:Open Wi-Fi in a caféAn attacker can pretend to be the router with ARP spoofing. HTTPS and a VPN protect your data by encrypting it.

Final test

Review questions

Why does an IP network need ICMP?

IP works on the “best effort” principle and does not itself report that a packet was lost. ICMP delivers error messages (unreachable, TTL expired) and service messages (echo, redirect) to the sender.

Which fields are in the header of an ICMP message?

Type (1 byte), Code (1 byte), Checksum (2 bytes); then a part that depends on the type (Identifier and Sequence in Echo, the header of the original packet in error messages).

What do the time and TTL values in a ping result mean?

time — the RTT, i.e. the time from sending the request to the return of the reply; TTL — the remaining TTL value of the arriving reply packet, from which the number of routers along the way can be estimated.

How does tracert work?

It sends requests with TTL = 1, 2, 3…. Every router where the TTL expires returns an ICMP Time Exceeded; when the destination is reached, an Echo Reply (or, in UDP traceroute, a Port Unreachable) arrives.

Which codes of the Destination Unreachable message do you know?

0 — network, 1 — host, 3 — port unreachable, 4 — fragmentation needed but the DF flag is set (important for Path MTU Discovery).

How are an ARP request and reply sent?

The request — broadcast (FF-FF-FF-FF-FF-FF), the reply — unicast to the requester’s MAC address. The reply is added to the ARP cache as a dynamic entry.

When a computer accesses a remote server, whose MAC address does it ask for with ARP, and why?

The default gateway’s. A broadcast does not pass through a router, and the frame must first be delivered to the router anyway.

What is the difference between dynamic and static entries in the arp -a table?

Dynamic — learned through ARP, ages after a while; static — set manually or by the system (broadcast, multicast), does not age.

What is gratuitous ARP used for?

Detecting an IP conflict and updating the caches in the network with a new MAC (for example, when switching to a backup router).

How can one protect against ARP spoofing?

Dynamic ARP Inspection on the switch, static ARP entries for important devices, network segmentation and encrypted protocols (HTTPS, VPN).

Independent work

The independent study topics in the course syllabus: “Data Link Layer: Error Detection, MAC, ARP and Link Protocols.” (6 hours) and “The Role of DHCP, ICMP, NAT and IPv6 Technologies in the Network.” (6 hours; in this lesson — the ICMP part).

  1. On your own computer run arp -a, arp -d * (as administrator), then ping the gateway and arp -a again. Explain with screenshots what changed.
  2. Run tracert to the address in your variant, record the RTT of each hop in a table and explain where the largest delay appears.
  3. Using Wireshark (or a similar program), “capture” one ARP Request/Reply pair and one ICMP Echo Request/Reply pair and describe their fields (Type, Code, Sender MAC/IP, Target MAC/IP).
Assessment criteria (individual assignment)
CriterionPoints
The task is fully completed, the command results (screenshots or code) are attached2
ICMP/ARP messages are interpreted correctly (type, code, direction)1
The conclusions are well founded and shown with a table or diagram1
The formatting is tidy, the terms are used correctly1

Summary

ICMPThe “messenger” of IP: error and service messages, inside IP, no ports.
pingEcho Request (8) → Echo Reply (0); shows RTT and TTL.
tracertFinds the routers along the path with TTL = 1, 2, 3… and Time Exceeded (11).
Type 3Destination Unreachable: network, host, port, fragmentation needed.
ARPIPv4 → MAC in the local segment; the request is broadcast, the reply is unicast.
ARP cachearp -a: dynamic entries age, static ones stay.
GatewayFor a remote address the gateway’s MAC address is requested; the IP stays, the MAC changes at every hop.
SecurityARP has no authentication → spoofing; filter ICMP with care.

Your lesson results

Your results are saved in this browser. Read all the sections and complete the exercises and assignments.

My personal notes