Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 2 of 6 · Lab · 25 min · revision 1

Lab: one web request, every layer, in your first capture

Build a client-router-server network in Linux network namespaces without touching your host network, capture one HTTP request on both sides of the router, read every header it carries, and trigger a real Path MTU Discovery exchange.

Contentsand lesson path

What you will learn

  • Map protocols and devices to OSI and TCP/IP layers and explain encapsulation, header overhead and MTU using a real capture.
  • Analyse captures with display filters, conversation and stream views, decoding Ethernet, IP, TCP and UDP headers.

Prerequisites: Networking Basics

01. Goal and setup

The previous lesson claimed that a router builds a new Ethernet frame but keeps the IP addresses, that every header byte comes out of the MTU budget, and that a router facing a too-small link tells the sender with an ICMP message. This lab proves all three with packets you capture yourself.

You will build network namespaces (separate copies of the Linux network stack, each with its own interfaces and routes) and connect them with veth pairs, which behave like a cable with a network card at each end. client and server each run one program; the shell you start in Step 0 is itself a fresh namespace and plays the router. Addresses come from the RFC 5737 documentation ranges.

You need Linux (a VM is fine) with iproute2, tcpdump, curl, ethtool and Python 3. The outputs were recorded on Ubuntu 22.04 (tcpdump 4.99.1, curl 7.81.0, Python 3.10.12) with option A of Step 0.

Text · Lab topology: fixed MACs and two RFC 5737 subnets
[client ns]              [router: your lab shell]               [server ns]
c-eth0                   r-eth0              r-eth1             s-eth0
192.0.2.10/24  <-veth->  192.0.2.1/24        198.51.100.1/24 <-> 198.51.100.10/24
02:..:01:10              02:..:01:01         02:..:02:01        02:..:02:10

02. Step 0: Open a lab shell in its own network namespace

Creating interfaces needs the CAP_NET_ADMIN capability and capturing needs CAP_NET_RAW. Do not run this lab with plain sudo in your normal shell: the router steps would add addresses and enable forwarding on your real host. Start a shell with its own empty network namespace instead:

  • Option A, no sudo. unshare -c -n --keep-caps bash creates a user namespace in which you keep your user ID but hold network capabilities, plus a new network namespace. Recent Ubuntu releases can restrict this through AppArmor (kernel.apparmor_restrict_unprivileged_userns); if Step 1 fails with Operation not permitted, use option B.
  • Option B, root on a VM you own. sudo unshare -n bash gives a root shell in a new network namespace; the host interfaces stay untouched. The recording machine had no root, so option B was not run there.

Capture commands include -Z root: on Debian and Ubuntu, tcpdump started as root otherwise switches to a tcpdump user that cannot write into your lab directory. In option A tcpdump is not root and ignores the flag.

Terminal · Pick one way to open the lab shell
# Option A: no sudo needed
unshare -c -n --keep-caps bash
# Option B: on a VM where you have root
sudo unshare -n bash
Terminal · Inside the lab shell: an empty namespace and the tool versions
ip -br link
tcpdump --version | head -n 1
curl --version | head -n 1 | cut -d " " -f 1,2
python3 --version
Expected output (versions differ by distribution)
lo               DOWN           00:00:00:00:00:00 <LOOPBACK>
tcpdump version 4.99.1
curl 7.81.0
Python 3.10.12

03. Step 1: Build the client, router and server

The block writes a tiny HTTP server, starts two sleep infinity processes whose only job is to hold the client and server namespaces open, and wires everything together. The MAC addresses are fixed and start with 02 (locally administered), so frames are easy to read. echo 1 > /proc/sys/net/ipv4/ip_forward turns the lab shell into a router; without it, the shell drops packets not addressed to itself. The sleep 1 gives Python time to bind before ss -tln checks it.

Terminal · Write srv.py, build the topology and start the server
mkdir -p ~/pca-lab02 && cd ~/pca-lab02
cat > srv.py <<'PY'
from http.server import BaseHTTPRequestHandler, HTTPServer
class H(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header("Content-Type", "text/plain")
        self.end_headers()
        self.wfile.write(b"hello-from-server\n")
    def do_POST(self):
        body = self.rfile.read(int(self.headers["Content-Length"]))
        self.send_response(200)
        self.end_headers()
        self.wfile.write(b"received %d bytes\n" % len(body))
    def log_message(self, *args): pass
HTTPServer(("198.51.100.10", 8080), H).serve_forever()
PY
unshare -n sleep infinity & C_PID=$!
unshare -n sleep infinity & S_PID=$!
sleep 0.5
ip link add c-eth0 address 02:00:00:00:01:10 type veth peer name r-eth0 \
  address 02:00:00:00:01:01
ip link add r-eth1 address 02:00:00:00:02:01 type veth peer name s-eth0 \
  address 02:00:00:00:02:10
ip link set c-eth0 netns $C_PID
ip link set s-eth0 netns $S_PID
ip link set lo up
ip addr add 192.0.2.1/24 dev r-eth0 && ip link set r-eth0 up
ip addr add 198.51.100.1/24 dev r-eth1 && ip link set r-eth1 up
echo 1 > /proc/sys/net/ipv4/ip_forward
nsenter -t $C_PID -n sh -c "ip link set lo up && ip addr add 192.0.2.10/24 \
  dev c-eth0 && ip link set c-eth0 up && ip route add default via 192.0.2.1"
nsenter -t $S_PID -n sh -c "ip link set lo up && ip addr add 198.51.100.10/24 \
  dev s-eth0 && ip link set s-eth0 up && ip route add default via 198.51.100.1"
nsenter -t $S_PID -n python3 srv.py & HTTP_PID=$!
sleep 1
nsenter -t $S_PID -n ss -tln
Expected output
State  Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0      5      198.51.100.10:8080      0.0.0.0:*

04. Step 2: Capture on both sides of the router

Predict before running. The client will send curl http://198.51.100.10:8080/. For the first SYN packet, write down the source MAC, destination MAC, source IP, destination IP and TTL you expect in client.pcap, and what will be different for the same packet in server.pcap.

Two flags prevent a silently empty capture. When tcpdump writes to a file, the kernel holds captured packets in a buffer and hands them over in batches; stop tcpdump right after a short exchange and the waiting packets are never saved. --immediate-mode asks for each packet as it arrives, and -U writes it to the file at once. tcpdump's counters go to standard error, saved here in a log file.

Terminal · Capture on c-eth0 and s-eth0 while sending one GET
nsenter -t $C_PID -n tcpdump -Z root --immediate-mode -U -i c-eth0 \
  -w client.pcap "tcp port 8080" 2> client.log &
TC_PID=$!
nsenter -t $S_PID -n tcpdump -Z root --immediate-mode -U -i s-eth0 \
  -w server.pcap "tcp port 8080" 2> server.log &
TS_PID=$!
sleep 1
nsenter -t $C_PID -n curl -sS http://198.51.100.10:8080/
sleep 1
kill -INT $TC_PID $TS_PID; wait $TC_PID $TS_PID
tail -n 3 client.log server.log
Expected output (illustrative: the counts can differ by a packet or two)
hello-from-server
==> client.log <==
12 packets captured
12 packets received by filter
0 packets dropped by kernel

==> server.log <==
12 packets captured
14 packets received by filter
0 packets dropped by kernel

0 packets dropped by kernel means the capture kept up. On Linux, "received by filter" can be a little higher than "captured", because it also counts matching packets that tcpdump had not read yet when it stopped.

05. Step 3: Compare Layer 2 and Layer 3 across the router

Read the first packet of each file. -e prints the Ethernet header, -nn keeps addresses and ports numeric, and -v prints the IP header fields. Reading a saved file needs no privileges, so you could also open these files in Wireshark on another machine.

Terminal · Read the SYN in client.pcap and server.pcap
tcpdump -r client.pcap -e -nn -v -c 1
tcpdump -r server.pcap -e -nn -v -c 1
Expected output (illustrative: times, ports, IDs and sequence numbers vary; long lines wrapped)
reading from file client.pcap, link-type EN10MB (Ethernet), snapshot length 262144
10:57:15.450241 02:00:00:00:01:10 > 02:00:00:00:01:01, ethertype IPv4 (0x0800), length
  74: (tos 0x0, ttl 64, id 52993, offset 0, flags [DF], proto TCP (6), length 60)
    192.0.2.10.56756 > 198.51.100.10.8080: Flags [S], cksum 0xec76 (incorrect ->
      0xdc27), seq 3030322063, win 64240, options [mss 1460,sackOK,TS val 2632591937 ecr
      0,nop,wscale 7], length 0
reading from file server.pcap, link-type EN10MB (Ethernet), snapshot length 262144
10:57:15.450272 02:00:00:00:02:01 > 02:00:00:00:02:10, ethertype IPv4 (0x0800), length
  74: (tos 0x0, ttl 63, id 52993, offset 0, flags [DF], proto TCP (6), length 60)
    192.0.2.10.56756 > 198.51.100.10.8080: Flags [S], cksum 0xec76 (incorrect ->
      0xdc27), seq 3030322063, win 64240, options [mss 1460,sackOK,TS val 2632591937 ecr
      0,nop,wscale 7], length 0

Check your prediction field by field:

  • Layer 2 is local to each link. On c-eth0 the frame goes from the client (02:00:00:00:01:10) to the router's r-eth0 (02:00:00:00:01:01). On s-eth0 the router has built a new frame from r-eth1 (02:00:00:00:02:01) to the server (02:00:00:00:02:10).
  • Layer 3 is end to end. Both copies show 192.0.2.10.56756 > 198.51.100.10.8080 and the same IP identification (id 52993 in this run). Only the TTL changed, from 64 to 63, because one router forwarded the packet.
  • The lengths add up. The frame is length 74. Without the 14-byte Ethernet header that leaves the IPv4 length 60: a 20-byte IPv4 header and a 40-byte TCP header. The TCP header is 20 fixed bytes plus 20 bytes of options (mss 4, sackOK 2, TS 10, nop 1, wscale 3). The SYN carries no data, so TCP length 0. No FCS appears: the virtual card, like most real ones, hands frames to the capture without it.
  • The checksum is marked incorrect on both sides, yet the server answered. Step 4 shows why.

06. Step 4: Read the HTTP payload and explain the checksum warning

The filter tcp[tcpflags] & tcp-push != 0 keeps only segments with the PSH flag, which here are the ones that carry data, and -A prints their bytes as ASCII. The handshake segments carry no application data, so the readable text starts with the client's GET.

About the checksum: when a card offers checksum offload, Linux leaves the TCP checksum for the card to fill in, and a capture on the sender sees the packet before that. A veth pair goes further: it hands the packet to its peer still marked "checksum not computed", the receiver trusts the mark, and the router forwards it unchanged, so every veth capture reports incorrect. The second half of the block runs ethtool -K c-eth0 tx off and captures again; the kernel now computes the checksum in software and tcpdump reports correct. This also turns off TCP segmentation offload, which helps Step 5.

Terminal · Print the payload, then capture again with tx offload off
tcpdump -r client.pcap -nn -A "tcp[tcpflags] & tcp-push != 0"
nsenter -t $C_PID -n ethtool -K c-eth0 tx off
nsenter -t $C_PID -n tcpdump -Z root --immediate-mode -U -i c-eth0 \
  -w txoff.pcap "tcp port 8080" 2> txoff.log &
TX_PID=$!
sleep 1
nsenter -t $C_PID -n curl -sS http://198.51.100.10:8080/ > /dev/null
sleep 1
kill -INT $TX_PID; wait $TX_PID
tcpdump -r txoff.pcap -nn -v -c 1
Expected output (illustrative: ports, sequence numbers, the Date header and the dotted header bytes vary; long lines wrapped)
reading from file client.pcap, link-type EN10MB (Ethernet), snapshot length 262144
10:57:15.450449 IP 192.0.2.10.56756 > 198.51.100.10.8080: Flags [P.], seq
  3030322064:3030322146, ack 804725482, win 502, options [nop,nop,TS val 2632591938 ecr
  3615539077], length 82: HTTP: GET / HTTP/1.1
E.....@.@..&...
.3d
......../."............
..*B....GET / HTTP/1.1
Host: 198.51.100.10:8080
User-Agent: curl/7.81.0
Accept: */*


10:57:15.450809 IP 198.51.100.10.8080 > 192.0.2.10.56756: Flags [P.], seq 1:120, ack
  82, win 509, options [nop,nop,TS val 3615539078 ecr 2632591938], length 119: HTTP:
  HTTP/1.0 200 OK
E...{,@.?....3d
...
..../."................
......*BHTTP/1.0 200 OK
Server: BaseHTTP/0.6 Python/3.10.12
Date: Fri, 27 Nov 2026 03:57:15 GMT
Content-Type: text/plain


10:57:15.450842 IP 198.51.100.10.8080 > 192.0.2.10.56756: Flags [P.], seq 120:138, ack
  82, win 509, options [nop,nop,TS val 3615539078 ecr 2632591938], length 18: HTTP
E..F{-@.?..<.3d
...
..../.#a...............
......*Bhello-from-server

Actual changes:
tx-checksum-ip-generic: off
tx-tcp-segmentation: off [not requested]
tx-tcp-ecn-segmentation: off [not requested]
tx-tcp-mangleid-segmentation: off [not requested]
tx-tcp6-segmentation: off [not requested]
tx-checksum-sctp: off
reading from file txoff.pcap, link-type EN10MB (Ethernet), snapshot length 262144
10:57:17.570163 IP (tos 0x0, ttl 64, id 52919, offset 0, flags [DF], proto TCP (6),
  length 60)
    192.0.2.10.56764 > 198.51.100.10.8080: Flags [S], cksum 0x364b (correct), seq
      2879435290, win 64240, options [mss 1460,sackOK,TS val 2632594057 ecr 0,nop,wscale
      7], length 0

07. Step 5: Shrink one link and watch Path MTU Discovery

Now lower the MTU of the router's server-facing interface to 1,400 bytes, as if a tunnel sat between router and server. The client and server still have 1,500-byte links, so the client still advertises and receives mss 1460 and starts by sending full-size packets.

Predict before running. The client uploads 4,000 bytes. What size are its first data packets? What should the router send back, and what size will the retransmitted packets be? Remember that every data segment also carries 12 bytes of timestamp options. (-H "Expect:" stops curl from waiting for an HTTP 100 Continue that this small server never sends.)

Terminal · Set a 1400-byte MTU on r-eth1, then upload 4,000 bytes
ip link set r-eth1 mtu 1400
head -c 4000 /dev/zero | tr '\0' 'U' > upload.txt
nsenter -t $C_PID -n tcpdump -Z root --immediate-mode -U -i c-eth0 \
  -w pmtu.pcap "tcp port 8080 or icmp" 2> pmtu.log &
TP_PID=$!
sleep 1
nsenter -t $C_PID -n curl -sS -H "Expect:" --data-binary @upload.txt \
  http://198.51.100.10:8080/
sleep 1
kill -INT $TP_PID; wait $TP_PID
tcpdump -r pmtu.pcap -nn "icmp or greater 1000"
nsenter -t $C_PID -n ip route get 198.51.100.10
Expected output (illustrative: times, ports and sequence numbers vary; long lines wrapped)
received 4000 bytes
reading from file pmtu.pcap, link-type EN10MB (Ethernet), snapshot length 262144
10:57:26.227506 IP 192.0.2.10.57620 > 198.51.100.10.8080: Flags [.], seq
  3670923702:3670925150, ack 2501788637, win 502, options [nop,nop,TS val 2632602715 ecr
  3615549855], length 1448: HTTP: POST / HTTP/1.1
10:57:26.227508 IP 192.0.2.10.57620 > 198.51.100.10.8080: Flags [.], seq 1448:2896,
  ack 1, win 502, options [nop,nop,TS val 2632602715 ecr 3615549855], length 1448: HTTP
10:57:26.227509 IP 192.0.2.10.57620 > 198.51.100.10.8080: Flags [P.], seq 2896:4154,
  ack 1, win 502, options [nop,nop,TS val 2632602715 ecr 3615549855], length 1258: HTTP
10:57:26.227524 IP 192.0.2.1 > 192.0.2.10: ICMP 198.51.100.10 unreachable - need to
  frag (mtu 1400), length 556
10:57:26.227527 IP 192.0.2.1 > 192.0.2.10: ICMP 198.51.100.10 unreachable - need to
  frag (mtu 1400), length 556
10:57:26.227561 IP 192.0.2.10.57620 > 198.51.100.10.8080: Flags [.], seq 0:1348, ack
  1, win 502, options [nop,nop,TS val 2632602715 ecr 3615549855], length 1348: HTTP:
  POST / HTTP/1.1
10:57:26.227562 IP 192.0.2.10.57620 > 198.51.100.10.8080: Flags [.], seq 1348:2696,
  ack 1, win 502, options [nop,nop,TS val 2632602715 ecr 3615549855], length 1348: HTTP
198.51.100.10 via 192.0.2.1 dev c-eth0 src 192.0.2.10 uid 1000
    cache expires 598sec mtu 1400

The first two segments carry 1,448 bytes each, so their IP packets are 1448 + 32 + 20 = 1,500 bytes, with DF set (the Linux default). The router cannot forward them onto the 1,400-byte link, so it drops each and returns need to frag (mtu 1400). The third segment, a 1,310-byte packet, fitted. The client stores the new path MTU (cache ... mtu 1400) and resends the missing data as 1,348-byte segments: 1400 − 20 − 32. Had a firewall dropped the two ICMP messages, the client would have resent 1,500-byte packets until the upload hung: the black hole from the previous lesson.

08. Step 6: Clean up

Stop the server and the placeholder processes. When the last process in a namespace exits, the kernel deletes the namespace and its veth ends, and their peers in the router go too, leaving only loopback. Then type exit to leave the lab shell.

Terminal · Remove the namespaces and the lab directory
kill $HTTP_PID $C_PID $S_PID
sleep 1
ip -br link
cd ~ && rm -rf ~/pca-lab02
Expected output
lo               UNKNOWN        00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP>

09. Check your understanding

Practice check · 2 questions

Reading the lab capture

Use the fields printed in Steps 3 and 4 to explain what happened on the wire.

Q1. In Step 4 the GET request has an IPv4 total length of 134 bytes (its frame is 148 bytes), and tcpdump prints TCP `length 82` with options `nop,nop,TS`. Which headers make up the 52 bytes between the IPv4 length and the HTTP payload?
Q2. In Step 3 the SYN shows `cksum 0xec76 (incorrect -> 0xdc27)` on `c-eth0`, and exactly the same warning on `s-eth0` after the router. The handshake still completes. What explains seeing it on both sides?
Practice only: not graded, not saved, not evidence.

10. Apply it

Add a second router namespace between router and server, predict the TTL and MAC addresses on every link, then capture to check. Or open client.pcap in Wireshark and, for the GET request, write down the frame number and the size of every header in the packet details pane, which is the layer-by-layer reading the skill practice asks for.

On shared production systems the hard parts are where to capture, how to keep files small and how to avoid storing data you should not: the subject of the next lesson.

11. Review prompt

Explain, without looking back, how two captures taken on opposite sides of a router show that Ethernet frames are local to one link while IP packets are end to end; why a capture can end up empty if tcpdump is stopped right after a short exchange; and what the router and the client each did in Step 5 when a 1,500-byte packet met a 1,400-byte link.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check