Sub topic 13
Seeing the layers in a packet capture
This chapter assumes you know what encapsulation is, can read hexadecimal bytes, and can run commands in a terminal. It shows how a capture tool displays each layer of a frame, so you can check the model against real traffic.
What a capture shows
A packet capture tool asks the network card for a copy of the frames it sees. It then decodes each frame by peeling headers in the same order a receiver does: Ethernet, then IP, then TCP or UDP, then the application data. The output is a readable view of decapsulation.
To capture, you normally need administrator rights. Capture only on networks you own or are authorized to monitor.
Running a capture
The following command captures five TCP packets on port 80. The -e option prints the Ethernet header, -v adds IP header details, and -nn keeps addresses and ports numeric. Replace eth0 with your interface name.
sudo tcpdump -i eth0 -e -nn -v -c 5 tcp port 80To generate traffic, run curl http://example.com/ in a second terminal while the capture waits.
Matching output to layers
A line of output has the same order as the frame on the wire. Read it from the left. The sample below is shortened and uses made-up addresses.
12:00:01.000 11:22:33:44:55:66 > aa:bb:cc:dd:ee:ff, ethertype IPv4 (0x0800), length 74:
(tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 60)
192.168.1.10.50000 > 203.0.113.5.80: Flags [S], seq 1, win 65535, length 0| Part of the output | Layer | What it tells you |
|---|---|---|
| `11:22:33:44:55:66 > aa:bb:cc:dd:ee:ff` | Link | Source and destination MAC addresses for this hop |
| `ethertype IPv4 (0x0800)` | Link | The payload is an IPv4 packet |
| `length 74` | Link | Total frame length captured, here 14 bytes of Ethernet header plus 60 bytes of IP packet |
| `ttl 64`, `proto TCP (6)` | Network | Remaining hop count and the protocol of the payload |
| `192.168.1.10 > 203.0.113.5` | Network | End-to-end source and destination IP addresses |
| `.50000 > .80` | Transport | Source and destination ports |
| `Flags [S]`, `seq 1` | Transport | A TCP SYN segment with its sequence number |
Notice that the Ethernet ethertype field names the protocol of the IP layer, and the IP proto field names the protocol of the transport layer. Each header says what the next layer is. That is how a receiver knows which decoder to apply.
Following hops
Capture on two machines on either side of a router, and compare the same packet. The IP addresses and ports match on both. The MAC addresses differ, and the TTL is one lower after the router. This confirms that the IP header is end to end, while the Ethernet header is rewritten at each hop.
Common errors
- You see no packets. The interface name is wrong, or the traffic does not cross that interface. Check names with
ip link show. - Checksums look wrong. Many network cards compute checksums after the capture point, so outgoing packets can show bad checksums. This is usually harmless.
- Packets look larger than the MTU. Offload features can merge packets before capture, so a captured length can exceed 1500 bytes. The wire frames are still within the MTU.
- HTTPS shows no readable data. The payload is encrypted, so you see only headers and encrypted bytes. The Ethernet, IP and TCP layers are still visible.
- The filter matches nothing.
tcp port 80only matches plain HTTP. Useport 443for HTTPS.
Exercise
In a capture line, you see ethertype IPv4 (0x0800), proto TCP (6), and .80 as the destination port. Which layer does each of these three fields describe, and what does each one tell the receiver?
Show answer
The EtherType belongs to the Ethernet (link) header and says the payload is an IPv4 packet. The proto field belongs to the IP (network) header and says the payload is a TCP segment. The destination port belongs to the TCP (transport) header and says which application should receive the data, here a web server on port 80.
Exercise
You capture the same packet before and after a router. Which of these change: source IP, destination IP, source MAC, destination MAC, TTL, destination port?
Show answer
The source MAC, destination MAC and TTL change. The source IP, destination IP and destination port stay the same, assuming no network address translation on that router.