DevOps.Academy
CoursesCurriculumInterview prepPricing
◔My learningSign in
DevOps.Academy

Free, hands-on DevOps lessons. Made with care in India.

System status

Learn

All coursesLinux roadmapCurriculumInterview questionsCheat sheetsMy learning

Academy

PricingCertificates

Legal

PrivacyTermsContact

devops.rajeev.pro

NetworkingLesson 1 of 12
Your progress · 0%
On this page
  1. Four layers
  2. What a packet contains
  3. The next hop
  4. Read your own network
↖ Course roadmap
Lesson 1 · How networks work

How networks work: layers, packets and the next hop

The four layers every request passes through, what a packet really contains, and the two decisions every machine makes to send it on. Read your own machine with ip and watch a packet with tcpdump.

25 min read · beginner · hands-on

By the end of this lesson you'll be able to

0 of 4 complete
Lab status

Verified lab: ip on a Linux host (WSL 2) and a tcpdump capture of a real HTTP request from an Alpine container. The output shown is real.
Cloud lab: none needed.

"The network is down" is the start of most incident calls, and it's almost never the whole network. Something broke at one layer. This lesson gives you the map, so you can say which.

Four layers

The internet runs on the four-layer TCP/IP model. People still say "layer 4" or "layer 7" from the older seven-layer OSI model, so you need both numbers: an "L4 load balancer" works with TCP ports, an "L7" one reads HTTP. Each layer only talks to the layers next to it, and each one has its own tools and its own ways of breaking. This whole course follows the stack upward.

What a packet contains

Every request is wrapped in headers, one per layer. This is a real HTTP request, captured with tcpdump -e in an Alpine container:

$ tcpdump -i eth0 -e -n -c 6 tcp port 80 & curl -s -o /dev/null http://example.com
0e:89:79:78:14:35 > 8e:25:82:58:7f:16, ethertype IPv4, length 74: 172.17.0.2.34410 > 104.20.23.154.80: Flags [S] ...
8e:25:82:58:7f:16 > 0e:89:79:78:14:35, ethertype IPv4, length 74: 104.20.23.154.80 > 172.17.0.2.34410: Flags [S.] ...
0e:89:79:78:14:35 > 8e:25:82:58:7f:16, ethertype IPv4, length 66: 172.17.0.2.34410 > 104.20.23.154.80: Flags [.] ...
0e:89:79:78:14:35 > 8e:25:82:58:7f:16, ethertype IPv4, length 141: 172.17.0.2.34410 > 104.20.23.154.80: Flags [P.] ...

(Trimmed.) One line per packet, read left to right: link (MACs), internet (IPs), transport (ports and TCP flags). The first three lines are TCP's handshake (lesson 3); the fourth, 75 bytes longer, carries the HTTP request.

The next hop

Look at the destination MAC: 8e:25:82:58:7f:16. That isn't example.com. It's the container's gateway:

Every machine makes the same two decisions for every packet:

  1. Where next? The route table says: not on my subnet, so send it to the default gateway.
  2. Which MAC is that? ARP asks the local network "who has 172.17.0.1?" once and caches the answer.
$ ip neigh        # inside the container
172.17.0.1 dev eth0 lladdr 8e:25:82:58:7f:16 ref 1 used 0/0/0 probes 4 REACHABLE

Same MAC as in the capture. Routers along the way repeat both decisions, rewrapping the frame with new MACs each time. The IP addresses stay the same end to end, until NAT changes them (lesson 7).

Read your own network

Three commands show everything above on your own machine. From a Linux host (WSL 2 here):

$ ip -br addr
lo               UNKNOWN        127.0.0.1/8 ::1/128
eth0             UP             172.29.94.205/20 fe80::215:5dff:fedd:4d64/64
docker0          DOWN           172.17.0.1/16
$ ip route
default via 172.29.80.1 dev eth0 proto kernel onlink
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown
172.29.80.0/20 dev eth0 proto kernel scope link src 172.29.94.205
$ ip neigh
172.29.80.1 dev eth0 lladdr 00:15:5d:6c:9c:81 REACHABLE

(Trimmed.) eth0 has address 172.29.94.205 on a /20 network (lesson 2 decodes that). Anything not on a listed network goes to the default route, 172.29.80.1, and ip neigh holds that gateway's MAC. docker0 is the bridge that containers use, which is why the container's gateway was 172.17.0.1. Lesson 11 takes it apart.

Old commands

ifconfig, route and arp still appear in older guides. They come from the deprecated net-tools package; ip addr, ip route and ip neigh replace them and are installed everywhere.

⌘
Mini mission

Map your own machine

Record your main interface and address, your default gateway and its MAC. Then capture one HTTP request in a container and show that the packet's destination MAC is the container's gateway.

Input: A Linux shell (or WSL 2) and DockerOutput: ~/my-network.txt
Reveal one safe solution
$ { ip -br addr; ip route; ip neigh; } > ~/my-network.txt
$ docker run --rm --cap-add NET_ADMIN --cap-add NET_RAW alpine:3.22 sh -c '
    apk add -q tcpdump curl
    tcpdump -i eth0 -e -n -c 4 tcp port 80 & sleep 1
    curl -s -o /dev/null http://example.com; sleep 2; ip neigh' >> ~/my-network.txt
{ ip -br addr; ip route; ip neigh; } > ~/my-network.txt
  • >write output to a file, replacing it
docker run --rm --cap-add NET_ADMIN --cap-add NET_RAW alpine:3.22 sh -c '
  • dockerbuild and run containers
  • runstart a new container
  • --rmdelete the container when it exits
  • --cap-add NET_ADMINadd a Linux capability back
  • --cap-add NET_RAWadd a Linux capability back
  • alpine:3.22the image to start
  • sh -c 'the command run inside, instead of the image’s default

The destination MAC in the outgoing packets should match the ip neigh line at the end.

Try it yourself

0 of 5 steps done

Run each task in your own account or terminal, then tick it off.

Knowledge check

Quick check

Question 1 of 3

A website returns 503. Which layer is that?

Go deeper

Official reading for this lesson

  • DocsThe TCP/IP model (RFC 1122, section 1.1.3)IETF ↗
  • Docsip(8) manualman7.org ↗
  • Articletcpdump tutorial and primerDaniel Miessler ↗

Or get every quiz answer right and it completes itself.

Something unclear, wrong or out of date in this lesson? Tell me, and I'll fix it.

Next lesson →IP addressing and subnets: reading CIDR