Showing raw Markdown: the renderer could not load.
## Goal
You capture your own Domain Name System (DNS) query and Hypertext Transfer Protocol (HTTP) request, then take each packet apart layer by layer. By the end you can point at the Ethernet, Internet Protocol (IP), Transmission Control Protocol (TCP) and HTTP headers in a real capture and say which Open Systems Interconnection (OSI) layer each one belongs to.
## Objectives
- Capture your own traffic with Wireshark, or with `tcpdump` as an alternative.
- Identify the Ethernet, IP, User Datagram Protocol (UDP) or TCP, and application headers in a captured frame.
- Map each header field you see to its OSI layer and protocol data unit (PDU).
- Describe encapsulation and decapsulation from real data, including the demultiplexing fields (EtherType, IP Protocol, port).
- Find the TCP maximum segment size (MSS) in a SYN segment and explain why it is 1460 bytes on standard Ethernet.
## Prerequisites
- A computer you own or administer, running Linux, macOS or Windows 10/11, connected by Ethernet or Wi-Fi.
- **Wireshark 4.0 or later** ([wireshark.org](https://www.wireshark.org/)). On Windows, the installer also installs Npcap, the capture driver.
- Alternative for Linux and macOS: **tcpdump 4.99 or later** (check with `tcpdump --version`). macOS ships with it.
- **curl 7.68 or later**. On Windows 10/11, `curl.exe` is built in.
- A DNS lookup tool: `dig` (BIND 9) on Linux and macOS, or `nslookup` on Windows.
- Permission to capture packets: administrator rights, or membership in the `wireshark` group on Linux (Step 2).
- Lesson: [The OSI Model: How Networks Talk](lesson.md), especially the worked example.
> [!WARNING]
> **Authorization and ethics.** Capture only traffic on your own computer and on a network you own or are explicitly allowed to monitor. Capturing other people's traffic without permission can break the law and workplace or campus rules, even on a shared Wi-Fi network. On a work or school network, check the acceptable use policy first, or do the lab at home. Capture files can contain private data (for example, the DNS names other apps look up). Don't share them, and delete them in the Cleanup section.
>
> **Cost:** free. You only use open-source tools and send a few kilobytes of traffic.
## Architecture
<figure class="diagram" style="--dg-w: 900px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 900 420" width="900" height="420" role="img" aria-labelledby="osi-lab-architecture-title osi-lab-architecture-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="osi-lab-architecture-title">Lab architecture: what you capture and where</title>
<desc id="osi-lab-architecture-desc">Your computer, 192.0.2.10, runs dig and curl at layer 7. Their requests go down the operating system network stack (layer 4 TCP or UDP, layer 3 IP, layer 2 Ethernet) to the network interface, which is the capture point for Wireshark and tcpdump. From there, frames go to the router, the default gateway at 192.0.2.1, which forwards them to the DNS resolver at 198.51.100.53 on UDP port 53 and to the example.com web server at 203.0.113.80 on TCP port 80.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="899" height="419" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<rect class="dg-panel" x="24" y="24" width="384" height="372" rx="14" fill="#f0f0ec"/>
<g class="dg-icon-neutral" transform="translate(44 40) scale(1.2500)" fill="none" stroke="#17171c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 16V7a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v9m16 0H4m16 0 1.28 2.55a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45L4 16"/></g>
<text x="86" y="56" font-size="16" class="dg-text" fill="#17171c" font-weight="700">Your computer</text>
<text x="86" y="76" font-size="13" class="dg-muted" fill="#5c5c68" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">192.0.2.10</text>
<g class="dg-l7"><rect class="dg-tint" x="42" y="100" width="348" height="64" rx="12" fill="#f3eefc" stroke="#c5a9f0" stroke-width="1.2"/>
<g class="dg-icon" transform="translate(58 118) scale(1.1667)" fill="none" stroke="#6d28d9" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="20" height="16" rx="2"/><path d="M2 9h20"/><path d="M6 6.5h.01"/><path d="M9 6.5h.01"/></g>
<text x="98" y="128" font-size="15" class="dg-ink" fill="#6d28d9" font-weight="700">Applications</text>
<text x="98" y="148" font-size="13" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">dig · curl</text>
</g>
<g class="dg-l7"><rect class="dg-solid" x="328" y="118" width="46" height="28" rx="14" fill="#6d28d9"/><text x="351.0" y="137" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">L7</text></g>
<path class="dg-line" d="M216.0 168V186M210.0 175l6-7 6 7M210.0 179l6 7 6-7" stroke="#cfcfc8" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<rect class="dg-card" x="42" y="190" width="348" height="92" rx="12" fill="#ffffff" stroke="#e3e3dd"/>
<g class="dg-icon-neutral" transform="translate(58 204) scale(1.0833)" fill="none" stroke="#17171c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="16" height="16" x="4" y="4" rx="2"/><rect width="6" height="6" x="9" y="9" rx="1"/><path d="M15 2v2"/><path d="M15 20v2"/><path d="M2 15h2"/><path d="M2 9h2"/><path d="M20 15h2"/><path d="M20 9h2"/><path d="M9 2v2"/><path d="M9 20v2"/></g>
<text x="96" y="222" font-size="14.5" class="dg-text" fill="#17171c" font-weight="700">Operating system network stack</text>
<g class="dg-l4"><rect class="dg-solid" x="52" y="240" width="104" height="28" rx="14" fill="#c2410c"/><text x="104.0" y="259" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">L4 · TCP/UDP</text></g>
<g class="dg-l3"><rect class="dg-solid" x="164" y="240" width="104" height="28" rx="14" fill="#b45309"/><text x="216.0" y="259" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">L3 · IP</text></g>
<g class="dg-l2"><rect class="dg-solid" x="276" y="240" width="104" height="28" rx="14" fill="#15803d"/><text x="328.0" y="259" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">L2 · Ethernet</text></g>
<path class="dg-line" d="M216.0 286V304M210.0 293l6-7 6 7M210.0 297l6 7 6-7" stroke="#cfcfc8" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<g class="dg-l1"><rect class="dg-tint" x="42" y="308" width="348" height="70" rx="12" fill="#ebf3f7" stroke="#9ac3d9" stroke-width="1.2"/>
<g class="dg-icon" transform="translate(58 318) scale(1.0833)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="m15 20 3-3h2a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h2l3 3z"/><path d="M6 8v1"/><path d="M10 8v1"/><path d="M14 8v1"/><path d="M18 8v1"/></g>
<text x="96" y="336" font-size="15" class="dg-ink" fill="#0369a1" font-weight="700">Network interface</text>
</g>
<g class="dg-l6"><rect class="dg-solid" x="56" y="346" width="320" height="24" rx="12" fill="#a21caf"/>
<g class="dg-icon-on" transform="translate(66 350) scale(0.6667)" fill="none" stroke="#ffffff" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></g>
<text x="88" y="362.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="600">Capture point: Wireshark · tcpdump</text>
</g>
<rect class="dg-card" x="436" y="168" width="186" height="68" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-icon-neutral" transform="translate(452 184) scale(1.2500)" fill="none" stroke="#17171c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6.01 18H6"/><path d="M10.01 18H10"/><path d="M15 10v4"/><path d="M17.84 7.17a4 4 0 0 0-5.66 0"/><path d="M20.66 4.34a8 8 0 0 0-11.31 0"/></g>
<text x="492" y="198" font-size="15" class="dg-text" fill="#17171c" font-weight="700">Router</text>
<text x="492" y="217" font-size="12.5" class="dg-muted" fill="#5c5c68" font-weight="500">Default gateway</text>
<text x="529.0" y="258" font-size="13" class="dg-text" fill="#17171c" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">192.0.2.1</text>
<rect class="dg-card" x="664" y="60" width="212" height="100" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-icon-neutral" transform="translate(680 76) scale(1.2500)" fill="none" stroke="#17171c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/></g>
<text x="720" y="90" font-size="15" class="dg-text" fill="#17171c" font-weight="700">DNS resolver</text>
<text x="720" y="109" font-size="12.5" class="dg-muted" fill="#5c5c68" font-weight="500"></text>
<text x="680" y="140" font-size="13" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">198.51.100.53</text>
<g class="dg-l4"><rect class="dg-solid" x="790" y="124" width="70" height="28" rx="14" fill="#c2410c"/><text x="825.0" y="143" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">UDP 53</text></g>
<rect class="dg-card" x="664" y="262" width="212" height="100" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-icon-neutral" transform="translate(680 278) scale(1.2500)" fill="none" stroke="#17171c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="2" rx="2"/><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6 6h.01"/><path d="M6 18h.01"/></g>
<text x="720" y="292" font-size="15" class="dg-text" fill="#17171c" font-weight="700">Web server</text>
<text x="720" y="311" font-size="12.5" class="dg-muted" fill="#5c5c68" font-weight="500">example.com</text>
<text x="680" y="342" font-size="13" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">203.0.113.80</text>
<g class="dg-l4"><rect class="dg-solid" x="790" y="326" width="70" height="28" rx="14" fill="#c2410c"/><text x="825.0" y="345" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">TCP 80</text></g>
<path class="dg-line" d="M390 343H422V202.0H436" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M622 202.0H643V110.0H664" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M643 202.0V312.0H664" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M427 196.0l7 6-7 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M655 104.0l7 6-7 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M655 306.0l7 6-7 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<circle class="dg-solid dg-l6" cx="390" cy="343" r="5" fill="#a21caf"/>
</svg></figure>
*Figure 1. What you capture and where. The capture point is your own network interface, so you see every header your computer sends and receives.*
Wireshark and `tcpdump` copy each frame as it passes your network interface. You see the full frame with every header, exactly as your computer sends or receives it.
> [!NOTE]
> The addresses in this lab are documentation values, the same ones the lesson uses: IP addresses from RFC 5737 and Media Access Control (MAC) addresses from the RFC 7042 documentation block (`00:00:5e:00:53:xx`). **Your real values will differ.** Your computer probably has a private address such as `192.168.1.x`, and `example.com` resolves to real public addresses. Write your own values down as you go.
## Steps
### Step 1 — Find your interface, addresses and MTU
You need to know which interface carries your traffic before you capture on it. You also want your own IP and MAC addresses and your gateway, so you can recognise them in the capture. The maximum transmission unit (MTU) lets you predict the MSS before you see it.
On Linux:
```bash
ip -4 route show default
ip link show <interface>
resolvectl dns
```
`<interface>` is the name after `dev` in the first command's output (for example `enp3s0` or `wlp2s0`). If `resolvectl` isn't available, run `cat /etc/resolv.conf` instead.
Expected output:
```text
default via 192.0.2.1 dev enp3s0 proto dhcp src 192.0.2.10 metric 100
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
link/ether 00:00:5e:00:53:10 brd ff:ff:ff:ff:ff:ff
Global:
Link 2 (enp3s0): 198.51.100.53
```
On macOS and Windows, use these commands instead:
| Information | macOS | Windows (Command Prompt) |
|---|---|---|
| Interface and gateway | `route -n get default` (lines `gateway:` and `interface:`) | `ipconfig /all` (`Default Gateway`) |
| Your MAC address and MTU | `ifconfig <interface>` (lines `ether` and `mtu`) | `ipconfig /all` (`Physical Address`); `netsh interface ipv4 show subinterfaces` (MTU) |
| DNS server | `scutil --dns \| grep nameserver` | `ipconfig /all` (`DNS Servers`) |
Write down: interface name, your IPv4 address, your MAC address, the gateway's IP address, one IPv4 DNS server address and the MTU. With an MTU of 1500, the lesson predicts an MSS of 1500 − 20 (IPv4) − 20 (TCP) = 1460 bytes.
> [!NOTE]
> Windows shows MAC addresses with dashes (`00-00-5E-00-53-10`). Wireshark shows the same address with colons.
### Step 2 — Prepare a folder and capture permission
Capturing packets needs special privileges because a capture can see all traffic on the interface. Give yourself only the permission you need, and keep the lab files in one folder so cleanup is easy.
```bash
mkdir -p ~/osi-lab
cd ~/osi-lab
```
Expected output: none. The commands succeed silently.
Then set up capture permission for your system:
- **Linux, Wireshark:** if Wireshark lists no interfaces or says you don't have permission, add yourself to the `wireshark` group (on Debian and Ubuntu, first run `sudo dpkg-reconfigure wireshark-common` and answer **Yes**). Then log out and back in.
```bash
sudo usermod -aG wireshark "$USER"
```
Remember whether you did this: Cleanup undoes it.
- **Linux and macOS, tcpdump:** you run `tcpdump` with `sudo` in Step 3. No setup is needed.
- **macOS, Wireshark:** accept the **ChmodBPF** component when the installer offers it.
- **Windows, Wireshark:** make sure Npcap was installed with Wireshark.
> [!TIP]
> Never run the whole Wireshark graphical application as root or administrator. Wireshark has a lot of protocol-parsing code, and running it with full privileges increases the damage a malicious packet could do. The group-based setup only gives the small capture helper (`dumpcap`) the rights it needs.
Check the group membership on Linux (after logging back in):
```bash
id -nG
```
Expected output (your list will differ, but must include `wireshark`):
```text
learner wheel wireshark
```
### Step 3 — Start the capture
You only want two kinds of traffic: DNS (UDP port 53) and plain HTTP (TCP port 80). A **capture filter** tells the capture engine to keep only those packets, so your file stays small and holds as little unrelated data as possible.
**Wireshark:** open Wireshark. On the welcome screen, type this in the capture filter box ("…using this filter"), then double-click your interface from Step 1:
```text
tcp port 80 or udp port 53
```
Expected result: the packet list opens and stays empty or shows a few DNS packets from other apps. The status bar shows the interface name and a packet count.
**tcpdump (Linux and macOS):** run this in a terminal and leave it running.
```bash
cd ~/osi-lab
sudo tcpdump -i <interface> -nn -Z "$USER" -w osi-lab.pcap 'tcp port 80 or udp port 53'
```
- `<interface>` is the interface name from Step 1.
- `-nn` prints addresses and port numbers instead of names.
- `-Z "$USER"` makes `tcpdump` drop root privileges and write the file as you, so you can read and delete it without `sudo`.
- `-w osi-lab.pcap` writes raw packets to a file instead of printing them.
Expected output:
```text
tcpdump: listening on enp3s0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
```
`EN10MB (Ethernet)` means each captured packet starts with an Ethernet header. You'll see it on Wi-Fi too: in normal (non-monitor) mode, the operating system hands Wi-Fi frames to the capture as Ethernet frames.
### Step 4 — Generate DNS and HTTP traffic
Now you create the traffic you'll dissect. You query DNS directly at your resolver so the query crosses the network instead of being answered from a local cache. Then you fetch a page over plain HTTP: with HTTP Secure (HTTPS), encryption would hide the HTTP layer from you. The `-4` option forces IPv4 so your results match the lesson.
Open a **second** terminal and run:
```bash
dig @<dns-server> example.com A +short
curl -4 -s -o /dev/null -w '%{http_code} %{remote_ip}\n' http://example.com/
```
- `<dns-server>` is the IPv4 DNS server address from Step 1.
- `-o /dev/null` discards the page body; `-w` prints the HTTP status code and the server's IP address.
On Windows, run these in Command Prompt instead:
```bat
nslookup example.com <dns-server>
curl.exe -4 -s -o NUL -w "%{http_code} %{remote_ip}\n" http://example.com/
```
Expected output (Linux and macOS; real addresses differ, and you may see more than one):
```text
203.0.113.80
200 203.0.113.80
```
`200` means the web server answered the request successfully.
### Step 5 — Stop the capture and list the packets
Stop the capture so the file is complete, then get an overview before you zoom in on single packets.
**Wireshark:** click the red square (**Stop**), then **File → Save As** and save as `~/osi-lab/osi-lab.pcapng`. Type `dns || http || tcp.port == 80` in the display filter bar and press Enter.
**tcpdump:** press **Ctrl+C** in the first terminal, then read the file back. You don't need `sudo` to read it.
```bash
tcpdump -nn -r osi-lab.pcap
```
Expected output (abbreviated; your times, addresses and sequence numbers differ):
```text
reading from file osi-lab.pcap, link-type EN10MB (Ethernet), snapshot length 262144
10:15:02.120000 IP 192.0.2.10.41000 > 198.51.100.53.53: 6699+ [1au] A? example.com. (40)
10:15:02.135000 IP 198.51.100.53.53 > 192.0.2.10.41000: 6699 1/0/1 A 203.0.113.80 (56)
10:15:02.150000 IP 192.0.2.10.50514 > 203.0.113.80.80: Flags [S], seq 1000000, win 64240, options [mss 1460,sackOK,TS val 1000 ecr 0,nop,wscale 7], length 0
10:15:02.165000 IP 203.0.113.80.80 > 192.0.2.10.50514: Flags [S.], seq 2000000, ack 1000001, win 65535, options [mss 1460,sackOK,TS val 5000 ecr 1000,nop,wscale 10], length 0
10:15:02.180000 IP 192.0.2.10.50514 > 203.0.113.80.80: Flags [.], ack 1, win 502, options [nop,nop,TS val 1001 ecr 5000], length 0
10:15:02.195000 IP 192.0.2.10.50514 > 203.0.113.80.80: Flags [P.], seq 1:75, ack 1, win 502, options [nop,nop,TS val 1001 ecr 5000], length 74: HTTP: GET / HTTP/1.1
10:15:02.210000 IP 203.0.113.80.80 > 192.0.2.10.50514: Flags [P.], seq 1:79, ack 75, win 1050, options [nop,nop,TS val 5010 ecr 1001], length 78: HTTP: HTTP/1.1 200 OK
```
You should recognise the story: a DNS question and answer, the TCP three-way handshake (`[S]`, `[S.]`, `[.]`), the HTTP request and the HTTP response. More packets follow (the rest of the page and the connection close). You may also see DNS packets from `curl` itself and from other apps.
### Step 6 — Dissect the DNS query
DNS is the simplest packet in the capture: one UDP datagram carrying one question. Use it to practise reading the layers from the outside in.
**Wireshark:** filter on `dns`, then click the first query (`Standard query … A example.com`). The packet details pane shows one line per layer:
```text
Frame 1: 82 bytes on wire (656 bits), 82 bytes captured (656 bits) on interface enp3s0, id 0
Ethernet II, Src: 00:00:5e:00:53:10, Dst: 00:00:5e:00:53:01
Internet Protocol Version 4, Src: 192.0.2.10, Dst: 198.51.100.53
User Datagram Protocol, Src Port: 41000, Dst Port: 53
Domain Name System (query)
```
Wireshark may add a vendor name in front of each MAC address. Expand each line with the arrow and find: the Ethernet **Type**, the IP **Protocol** and **Time to Live** (TTL), and the UDP **Destination Port**.
**tcpdump:** add `-e` to print the Ethernet header and `-v` to print IP header details.
```bash
tcpdump -nn -e -v -r osi-lab.pcap 'udp port 53'
```
Expected output (first packet shown):
```text
10:15:02.120000 00:00:5e:00:53:10 > 00:00:5e:00:53:01, ethertype IPv4 (0x0800), length 82: (tos 0x0, ttl 64, id 4242, offset 0, flags [DF], proto UDP (17), length 68)
192.0.2.10.41000 > 198.51.100.53.53: 6699+ [1au] A? example.com. (40)
```
Read it layer by layer:
| Layer | What you see | Meaning |
|---|---|---|
| L2 Data Link | `00:00:5e:00:53:10 > 00:00:5e:00:53:01`, `ethertype IPv4 (0x0800)` | Your MAC address sends to the gateway's MAC address. EtherType `0x0800` says "the payload is IPv4." |
| L3 Network | `192.0.2.10 > 198.51.100.53`, `ttl 64`, `proto UDP (17)` | IP addresses identify the two hosts end to end. Protocol `17` says "the payload is UDP." |
| L4 Transport | `.41000 > .53` | A random source port on your side; port 53 is DNS. The PDU is a **datagram**. |
| L7 Application | `A? example.com.` | The DNS question itself: "what is the IPv4 address of example.com?" |
Check the destination MAC address: it is your gateway's MAC address, even though the DNS server may be on another network. If your DNS server is your home router, the gateway and the DNS server are the same device.
> [!NOTE]
> `length 82` is the frame without the 4-byte frame check sequence (FCS). Most network cards check and remove the FCS before the capture sees the frame, so captures usually don't show it.
### Step 7 — Read the MSS in the TCP handshake
In the lesson, you calculated that 1460 bytes of application data fit in one TCP segment on a 1500-byte MTU link. TCP announces that number in the **MSS option** of the SYN (synchronize) segment, the first packet of the handshake. Now you see it on the wire.
**Wireshark:** apply this display filter, then click the first packet (your SYN, sent from your IP address):
```text
tcp.flags.syn == 1
```
Expand **Transmission Control Protocol → Options**. Expected result:
```text
TCP Option - Maximum segment size: 1460 bytes
```
You can also filter directly on the value with `tcp.options.mss_val == 1460`.
**tcpdump:**
```bash
tcpdump -nn -e -v -r osi-lab.pcap 'tcp[tcpflags] & tcp-syn != 0'
```
The filter keeps segments with the SYN flag set: your SYN and the server's SYN-ACK. Expected output:
```text
10:15:02.150000 00:00:5e:00:53:10 > 00:00:5e:00:53:01, ethertype IPv4 (0x0800), length 74: (tos 0x0, ttl 64, id 4244, offset 0, flags [DF], proto TCP (6), length 60)
192.0.2.10.50514 > 203.0.113.80.80: Flags [S], cksum 0x42da (correct), seq 1000000, win 64240, options [mss 1460,sackOK,TS val 1000 ecr 0,nop,wscale 7], length 0
10:15:02.165000 00:00:5e:00:53:01 > 00:00:5e:00:53:10, ethertype IPv4 (0x0800), length 74: (tos 0x0, ttl 64, id 4245, offset 0, flags [DF], proto TCP (6), length 60)
203.0.113.80.80 > 192.0.2.10.50514: Flags [S.], cksum 0xa590 (correct), seq 2000000, ack 1000001, win 65535, options [mss 1460,sackOK,TS val 5000 ecr 1000,nop,wscale 10], length 0
```
Find `mss 1460` in your SYN. Now look at the raw bytes of the same frame to see the encapsulation in hexadecimal:
```bash
tcpdump -nn -XX -c 1 -r osi-lab.pcap 'tcp[tcpflags] == tcp-syn'
```
Expected output (the bytes in your capture differ):
```text
10:15:02.150000 IP 192.0.2.10.50514 > 203.0.113.80.80: Flags [S], seq 1000000, win 64240, options [mss 1460,sackOK,TS val 1000 ecr 0,nop,wscale 7], length 0
0x0000: 0000 5e00 5301 0000 5e00 5310 0800 4500 ..^.S...^.S...E.
0x0010: 003c 1094 4000 4006 2bcd c000 020a cb00 .<..@.@.+.......
0x0020: 7150 c552 0050 000f 4240 0000 0000 a002 qP.R.P..B@......
0x0030: faf0 42da 0000 0204 05b4 0402 080a 0000 ..B.............
0x0040: 03e8 0000 0000 0103 0307 ..........
```
- Bytes 0–13 are the Ethernet header: destination MAC, source MAC, then `0800` (IPv4).
- `45` starts the IPv4 header: version 4, header length 5 × 4 = 20 bytes. The tenth byte of the IP header, `06`, is the Protocol field (TCP).
- Inside the TCP options, `02 04 05b4` is the MSS option: kind 2, length 4, value `0x05b4` = 1460.
> [!NOTE]
> Each side announces the largest segment it is willing to *receive*, so the SYN-ACK can show a different MSS. Values below 1460 are normal on virtual private networks (VPNs), PPP over Ethernet (PPPoE) links and some cloud or mobile networks, because their MTU is smaller or a middlebox lowers ("clamps") the MSS. On packets you send, `tcpdump -v` may print `cksum … (incorrect -> …)`. That is normal: the network card fills in the checksum after the capture point (checksum offload).
### Step 8 — Dissect the HTTP request layer by layer
The HTTP request is the clearest example of full encapsulation: application data inside a TCP segment, inside an IP packet, inside an Ethernet frame. You now read all four headers of one frame.
**Wireshark:** apply the display filter `http.request` and click the `GET / HTTP/1.1` packet. Expand each line of the packet details pane:
```text
Frame 6: 140 bytes on wire (1120 bits), 140 bytes captured (1120 bits) on interface enp3s0, id 0
Ethernet II, Src: 00:00:5e:00:53:10, Dst: 00:00:5e:00:53:01
Internet Protocol Version 4, Src: 192.0.2.10, Dst: 203.0.113.80
Transmission Control Protocol, Src Port: 50514, Dst Port: 80, Seq: 1, Ack: 1, Len: 74
Hypertext Transfer Protocol
```
Click a line in the details pane: Wireshark highlights the matching bytes in the bytes pane at the bottom. Click **Ethernet II**, then **Internet Protocol**, then **Transmission Control Protocol**, then **Hypertext Transfer Protocol**, and watch the highlight move inwards through the frame. That is encapsulation, seen from the outside in.
**tcpdump:**
```bash
tcpdump -nn -e -v -r osi-lab.pcap 'tcp dst port 80 and tcp[tcpflags] & tcp-push != 0'
```
The filter keeps segments you sent to port 80 that carry data (PSH flag set). Expected output:
```text
10:15:02.195000 00:00:5e:00:53:10 > 00:00:5e:00:53:01, ethertype IPv4 (0x0800), length 140: (tos 0x0, ttl 64, id 4247, offset 0, flags [DF], proto TCP (6), length 126)
192.0.2.10.50514 > 203.0.113.80.80: Flags [P.], cksum 0x4260 (correct), seq 1000001:1000075, ack 2000001, win 502, options [nop,nop,TS val 1001 ecr 5000], length 74: HTTP, length: 74
GET / HTTP/1.1
Host: example.com
User-Agent: curl/8.5.0
Accept: */*
```
Check that the sizes add up:
| Piece | Bytes in this example | Where you read it |
|---|---|---|
| HTTP request (application data) | 74 | TCP `length 74` / Wireshark `Len: 74` |
| TCP header (20 + 12 bytes of timestamp options) | 32 | IP total length − IP header − data |
| IPv4 header | 20 | IP `Header Length: 20 bytes` |
| IP packet (IP total length) | 74 + 32 + 20 = 126 | IP `length 126` |
| Ethernet header | 14 | |
| Frame as captured (without FCS) | 126 + 14 = 140 | `length 140` / `Frame 6: 140 bytes` |
Then look at the server's response (`HTTP/1.1 200 OK`) and compare its IP header with your request. The source and destination are swapped, and the TTL is usually **lower** than the value the server started with (often 64 or 128). Every router on the path decremented it by one.
> [!NOTE]
> The TCP header in data segments is often 32 bytes rather than 20 because many systems add the timestamp option to every segment. Your sizes may differ: different curl versions send slightly different headers (for example, a different `User-Agent`).
### Step 9 — Map what you saw to the OSI layers
Pulling everything together turns what you saw into the model. Copy this table into your notes and fill the last column with the values from **your** capture.
| OSI layer | PDU | Wireshark line | Field to record | Example value | Your value |
|---|---|---|---|---|---|
| 7 Application | Data | Hypertext Transfer Protocol | Request line and `Host` | `GET / HTTP/1.1`, `example.com` | |
| 4 Transport | Segment | Transmission Control Protocol | Source port, destination port, MSS in the SYN | `50514`, `80`, `1460` | |
| 4 Transport | Datagram | User Datagram Protocol | Destination port of the DNS query | `53` | |
| 3 Network | Packet | Internet Protocol Version 4 | Source and destination IP, TTL, Protocol | `192.0.2.10`, `203.0.113.80`, `64`, `6` | |
| 2 Data Link | Frame | Ethernet II | Source and destination MAC, Type | `00:00:5e:00:53:10`, `00:00:5e:00:53:01`, `0x0800` | |
| 1 Physical | Bit | Frame (capture metadata) | Bytes on wire | `140` | |
> [!NOTE]
> The **Frame** line in Wireshark isn't a protocol header. It is information that the capture tool adds (arrival time, length, interface). It's the closest thing you see to Layer 1, because the capture only sees bits after the network card has turned signals back into bytes.
Layers 5 and 6 have no row of their own: with plain HTTP over TCP, no separate session or presentation protocol appears on the wire. With HTTPS, Transport Layer Security (TLS) would sit between TCP and HTTP (see the Challenge).
## Verification
You have completed the lab when every check below passes.
1. The capture file exists and contains packets. Wireshark: the saved file reopens and shows packets. tcpdump:
```bash
tcpdump -nn -r osi-lab.pcap 2>/dev/null | wc -l
```
Expected output: a number of at least 7 (the exact number varies).
2. Your SYN carries an MSS that matches your MTU. Wireshark: the filter `tcp.flags.syn == 1 && tcp.flags.ack == 0` shows your SYN, with an MSS of 1460 on a 1500-byte MTU. tcpdump:
```bash
tcpdump -nn -r osi-lab.pcap 'tcp[tcpflags] == tcp-syn'
```
Expected output: a line that contains `Flags [S]` and `mss 1460` (or MTU − 40 if your MTU isn't 1500).
Then check your understanding against the capture:
- [ ] You found EtherType `0x0800` in the Ethernet header of your IPv4 frames.
- [ ] You found IP Protocol `17` in the DNS query and `6` in the HTTP request.
- [ ] The destination MAC address of your outgoing frames is your gateway's MAC address, not the server's.
- [ ] You can explain why the MSS is 1460: 1500 (MTU) − 20 (IPv4 header) − 20 (TCP header).
- [ ] Your Step 9 table is complete, with your own values.
## Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Wireshark shows no interfaces, or "You don't have permission to capture on that device." | Your user isn't allowed to capture (Linux `wireshark` group, macOS ChmodBPF, Windows Npcap). | Linux: complete Step 2, then log out and back in (`id -nG` must list `wireshark`). macOS: reinstall Wireshark and accept ChmodBPF. Windows: reinstall Npcap from the Wireshark installer. |
| `tcpdump: <interface>: You don't have permission to capture on that device` | You ran `tcpdump` without `sudo`. | Run the Step 3 command with `sudo`. |
| `tcpdump: osi-lab.pcap: Permission denied` | `tcpdump` dropped root privileges and can't write to the current folder. | Use the `-Z "$USER"` option as shown and run the command from `~/osi-lab`, which you own. |
| The capture stays empty after Step 4. | You are capturing on the wrong interface (for example a disconnected Ethernet port, a Docker bridge or a VPN interface). | Check the interface that carries the default route (Step 1), and capture on that one. In Wireshark, pick the interface whose traffic sparkline moves. |
| No HTTP packets, only TCP port 443 or TLS. | You used `https://`, or something redirected you to HTTPS. Encryption hides the HTTP layer. | Use exactly `http://example.com/` with `curl`, not a browser. Browsers often upgrade to HTTPS automatically. |
| No DNS query in the capture. | You ran `dig` without `@<dns-server>`, so the answer came from a local cache (for example `systemd-resolved` on `127.0.0.53`) or through DNS over HTTPS. | Run `dig @<dns-server> example.com A` with the DNS server from Step 1. If you captured on loopback (`lo`), you only see the query to the local cache. |
| The MSS is very large (for example 65495 on Linux), or MAC addresses are all zeros. | You captured on the loopback interface, which has a very large MTU and no real network card. | Capture on your physical interface (Step 1). |
| The packets show `ethertype IPv6 (0x86dd)` and an MSS of 1440. | `curl` connected over IPv6. The IPv6 header is 40 bytes, so the MSS is 1500 − 40 − 20 = 1440. | Add `-4` to `curl` as shown in Step 4, or keep the IPv6 capture as an extra comparison. |
| No Ethernet header (`link-type RAW`) and an MSS below 1460. | A VPN is active, and you captured on its tunnel interface. | Disconnect the VPN for the lab, or capture on the physical interface. A smaller MSS through a VPN is expected. |
## Challenge (optional)
Repeat the capture with HTTPS: use the capture filter `tcp port 443` and run `curl -4 -s -o /dev/null https://example.com/`. Without step-by-step help, answer these questions from the capture:
1. Which headers can you still read (Ethernet, IP, TCP), and where does the encrypted part start?
2. Find the TLS Client Hello. Which piece of information about the website is still visible in plain text? (Hint: look for the Server Name Indication, SNI, extension.)
3. How does this match the lesson's statement that "encryption at one layer only protects the layers above it"?
## Cleanup
Stop any capture that is still running (Wireshark: **Stop**; tcpdump: **Ctrl+C**), then check that no `tcpdump` process is left:
```bash
pgrep -a tcpdump
```
Expected output: none (no process is listed).
Delete the capture files and the lab folder. They may contain private data.
```bash
rm -rf ~/osi-lab
```
On Windows, delete the folder where you saved `osi-lab.pcapng` in File Explorer.
If you added yourself to the `wireshark` group **only for this lab** (Step 2), remove the membership and log out and back in:
```bash
sudo gpasswd -d "$USER" wireshark
```
Expected output:
```text
Removing user learner from group wireshark
```
If you installed Wireshark, Npcap or ChmodBPF only for this lab, you can uninstall them with your system's package manager or the Wireshark uninstaller.
> [!NOTE]
> Wireshark also remembers recently opened files. To clear the list, use **File → Open Recent → Clear Recent Files**.
## What you learned
- A capture tool shows you every header of a frame, so you can see encapsulation directly instead of only in diagrams.
- Each layer's header tells the receiver what comes next: EtherType `0x0800` means IPv4, IP Protocol `6` means TCP and `17` means UDP, and the destination port picks the application.
- Your outgoing frames go to the gateway's MAC address, while the IP addresses identify the real endpoints.
- The SYN segment announces the MSS, 1460 bytes on a standard 1500-byte Ethernet link: 1500 − 20 (IPv4) − 20 (TCP).
- Encryption hides the layers above it. Plain HTTP shows the request in clear text; HTTPS shows only the lower layers and the TLS handshake.
- Capturing traffic is powerful and sensitive: capture only your own traffic, keep files private and delete them when you're done.