The OSI Model Explained With One Real Packet (Captured in a Lab)
The OSI model is usually taught as seven boxes in a diagram. Here it's one real packet. We'll see what's inside it, follow it across a router, and watch the server unwrap it.
A PC fetches a web page from a server on another network, through one router. Every interface has a readable MAC address (02:00:00:00:<network>:<host>). Capture the request on the PC with tcpdump and read its layers with tshark; the web server has been capturing since it started (/arrived.pcap), so compare the same packet on both sides of the router: the Ethernet header and TTL change, the IP addresses and ports don't.
The lab
A PC fetches a web page from a server called web, on another network. Between them is one router, r1. Every interface has a MAC address that ends in its network and its host, so they're easy to read: the PC ends in ten twenty, the router in ten oh one and twenty oh one, and the web server in twenty eighty.
Capture one request
timeout 5 tcpdump -c 10 -i eth1 -w pc.pcap tcp port 80 & sleep 1; curl -s http://10.0.20.80/; wait
[1] 213 tcpdump: listening on eth1, link-type EN10MB (Ethernet), snapshot length 262144 bytes <!doctype html> <title>web.homelab.test</title> <h1>Hello from web</h1> 10 packets captured 11 packets received by filter 0 packets dropped by kernel [1]+ Done timeout 5 tcpdump -c 10 -i eth1 -w pc.pcap tcp port 80
What this shows
On the PC, start tcpdump in the background, saving web traffic to a file, then fetch the page with curl. The page comes back, and tcpdump caught ten packets.
tshark -r pc.pcap -Y http.request -O http
Frame 4: Packet, 128 bytes on wire (1024 bits), 128 bytes captured (1024 bits)
Ethernet II, Src: 02:00:00:00:10:20 (02:00:00:00:10:20), Dst: 02:00:00:00:10:01 (02:00:00:00:10:01)
Internet Protocol Version 4, Src: 10.0.10.20, Dst: 10.0.20.80
Transmission Control Protocol, Src Port: 55912, Dst Port: 80, Seq: 1, Ack: 1, Len: 74
Hypertext Transfer Protocol
GET / HTTP/1.1\r\n
Request Method: GET
Request URI: /
Request Version: HTTP/1.1
Host: 10.0.20.80\r\n
User-Agent: curl/8.21.0\r\n
Accept: */*\r\n
\r\n
[Full request URI: http://10.0.20.80/]What this shows
tshark reads the file, and the filter picks the one packet that is the web request. It shows it as four headers, one after the other: Ethernet, IP, TCP, and HTTP. Let's draw that packet out, and see what each part is for.
What's in the packet
This is the same packet, with the values from the capture. Each layer is wrapped around the one inside it. The outside two are about getting it there. Ethernet, layer two, only gets it to the next box on the same cable: it's addressed to MAC ten oh one, which is the router, not the web server. IP, layer three, carries the real destination: from the PC, at ten dot zero dot ten dot twenty, to the web server, at ten dot zero dot twenty dot eighty. Its TTL starts at sixty four.
The request packet
The inside two are for the server itself. TCP, layer four, says which program on the server should get this: port eighty, the web server. The other port is the PC's own, for the reply to come back to. And HTTP, layer seven, is the request itself: get the page at slash. Now, follow it.
Where are layers 1, 5 and 6?
So where are layers one, five and six? Layer one, physical, doesn't add a header. It's the signal itself: the electrical pulses, light or radio that carry these bits. tshark told us how many: ten twenty four bits on the wire. Layers five and six, session and presentation, have no header of their own. The OSI model has seven layers, but the internet runs on a simpler model, TCP/IP, which leaves those jobs to the application. If this page were HTTPS, the encryption, TLS, would sit between TCP and HTTP. That's the closest a real packet gets to them.
| Layer 1 | 1024 bits | Physical: not a header. It's the signal itself, on the cable |
| Layers 5 and 6 | no header | Session, presentation: TCP/IP leaves them to the application |
| With HTTPS | TLS | encryption between TCP and HTTP: the closest thing to them |
Sending it: pc
ip route
default via 10.0.10.1 dev eth1 10.0.10.0/24 dev eth1 proto kernel scope link src 10.0.10.20
What this shows
First, the PC has to decide where to send it. Its own network is ten dot zero dot ten. The web server, on ten dot zero dot twenty, isn't on it. So the packet goes to the default gateway: the router, at ten dot zero dot ten dot one.
ip neigh
10.0.10.1 dev eth1 lladdr 02:00:00:00:10:01 REACHABLE
What this shows
To put the router's address in the Ethernet header, the PC needs its MAC. The neighbour table has it: ten oh one. That's exactly what we saw in Ethernet's to field. The IP header still says the web server. Ethernet just says: next stop, the router.
Across the router: r1
ip route
10.0.10.0/24 dev eth1 proto kernel scope link src 10.0.10.1 10.0.20.0/24 dev eth2 proto kernel scope link src 10.0.20.1
What this shows
The router receives it. The Ethernet header was addressed to the router, so it has done its job, and the router takes it off. Now it reads the IP header: to ten dot zero dot twenty dot eighty. Its routing table says that network is out eth2.
ip neigh
10.0.20.80 dev eth2 lladdr 02:00:00:00:20:80 REACHABLE 10.0.10.20 dev eth1 lladdr 02:00:00:00:10:20 REACHABLE
What this shows
And its neighbour table has the web server's MAC, twenty eighty. So the router wraps the packet in a brand new Ethernet header, from its own MAC on that side to the web server's. And because it passed the packet on, it takes one off the TTL.
The same packet, after r1
So here's the packet as it leaves the router. A new Ethernet header: to twenty eighty, from twenty oh one. TTL is now sixty three. And everything inside, the IP addresses, the TCP ports and the HTTP request, is exactly as the PC sent it.
Proof: both captures
tshark -r pc.pcap -Y http.request -T fields -e eth.src -e eth.dst -e ip.src -e ip.dst -e ip.ttl
02:00:00:00:10:20 02:00:00:00:10:01 10.0.10.20 10.0.20.80 64
What this shows
That's not just a drawing. Here are those fields from the PC's capture, as it left: the two MACs, the two IP addresses, and TTL sixty four.
tshark -r /arrived.pcap -Y http.request -T fields -e eth.src -e eth.dst -e ip.src -e ip.dst -e ip.ttl
02:00:00:00:20:01 02:00:00:00:20:80 10.0.10.20 10.0.20.80 63
What this shows
And the web server has been capturing too. The same request, as it arrived: new MACs, twenty oh one to twenty eighty. TTL sixty three. The IP addresses haven't changed at all.
Unwrapping it: web
ip -br link show eth1
eth1@if1794 UP 02:00:00:00:20:80 <BROADCAST,MULTICAST,UP,LOWER_UP>
What this shows
Now the web server unwraps it, from the outside in. The Ethernet header is addressed to twenty eighty. That's this server's own MAC, so it accepts it and takes Ethernet off.
ip -br addr show eth1
eth1@if1794 UP 10.0.20.80/24 fe80::a8c1:abff:fe35:e97/64
What this shows
The IP header is addressed to ten dot zero dot twenty dot eighty. That's this server's own address, so the packet has arrived. IP comes off too.
What web has left
What's left is TCP and the request inside it. TCP says port eighty. So which program is on port eighty?
ss -ltnp
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 4096 127.0.0.11:35063 0.0.0.0:*
LISTEN 0 5 0.0.0.0:80 0.0.0.0:* users:(("python3",pid=82,fd=3))What this shows
ss lists what's listening on this server. Port eighty belongs to python three: the web server program. So TCP takes its header off, and hands the rest to it.
What the web server reads
And all the web server program reads is the request: get the page at slash. It answers, and the reply makes the same trip in reverse: wrapped in TCP, IP and Ethernet by the web server, given a new Ethernet header by the router, and unwrapped by the PC.
On Windows and Mac
On a Mac, tcpdump is built in. On Windows, Wireshark is free, and tshark comes with it. Open the capture in Wireshark on either, and you'll see the same layers. Only capture on networks you own, or are allowed to test.
| Mac | sudo tcpdump -i en0 -w web.pcap | in Terminal: tcpdump is built in |
| Windows | Wireshark | free; tshark comes with it |
| Both | open the file in Wireshark | the same layers, as a tree you can click |
Every packet is wrapped in layers at the sender and unwrapped at the end. Ethernet only gets it one hop, and changes at every router. IP gets it to the right host. TCP gets it to the right program. And the lab is on networkincidents.ca, so you can capture this packet yourself.
Try it yourself
The whole lab runs on your own computer with Docker and containerlab: get it on GitHub, then ./lab.sh up and ./lab.sh break. Setup steps are on Run the labs.