Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

How data travels in layers (TCP/IP)

After this lesson: I can place a protocol in its layer.

45 min lesson4 commandsStatic routing lab: build routes on a small network in your browser

One photo, many small jobs

You send a photo to a group chat. Your phone finds the Wi-Fi, picks a route to the server and splits the photo into pieces.

At the far end the pieces are checked and put back in order. Nobody wrote one huge program for all of that.

Instead, the work is shared out in layers. Each layer does one job.

By the end of this lesson

Note

I can place a protocol in its layer.

Key words

WordWhat it meansExample
Protocolan agreed set of rules for talking over a network
Layerone level of the network that does one job
Headerextra information a layer adds to the front of the data
Packetone small piece of data with its headers
Encapsulationwrapping data inside the header of each layer in turn
Porta number that says which program on a device gets the data80

The cells students fill in are left blank in this preview.

Four layers, each with one job

The internet uses a model called TCP/IP. It has four layers.

The application layer is the program you use, such as a browser. The transport layer splits the data and checks it arrives. The internet layer puts an address on each packet and finds a route. The link layer moves bits across one cable or one Wi-Fi hop.

Worked example: the layers and their protocols

LayerIts jobProtocols you will meet
ApplicationThe program's own messagesHTTP, HTTPS, DNS, SMTP
TransportWhich program, in order, checkedTCP, UDP
InternetAddresses and routes across networksIP, ICMP
LinkOne hop on one cable or Wi-FiEthernet, Wi-Fi

The cells students fill in are left blank in this preview.

Each layer wraps the one above

When you load a web page, the browser writes an HTTP message. The transport layer puts a TCP header in front. It holds the port numbers.

The internet layer adds an IP header with the two addresses. The link layer adds an Ethernet header for the next hop. This wrapping is encapsulation.

At the other end, each layer takes off its own header and passes the rest up.

Worked example: one web request, wrapped

Order on the wireHeaderWhat it holds
FirstEthernetThe hardware address of the next hop
SecondIPFrom 192.168.1.20 to 198.51.100.7
ThirdTCPFrom port 51000 to port 443
LastHTTPS dataThe request for the page

The cells students fill in are left blank in this preview.

Meet the machines in the lab

Command
netlab status

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Ping the router next to h1

Command
sudo ip netns exec h1 ping -c 2 -W 1 10.0.1.1

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

See the router's hardware address

Command
sudo ip netns exec h1 ip neigh

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

What the three Runs show

The first Run lists five machines. The host h1 has one cable, to-r1, with the address 10.0.1.2/24.

The ping uses ICMP, an internet layer protocol. Two replies come back from 10.0.1.1.

The third Run shows the link layer. It prints one line: the router's IP address, then lladdr and its hardware address, then REACHABLE.

See which ports a router listens on

Command
sudo ip netns exec r1 ss -ltn

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Ports belong to the transport layer

This Run lists TCP ports that are waiting for a connection. There are three LISTEN lines, on ports 2601, 2616 and 2623.

Each port leads to one small program inside the router. All three only listen on 127.0.0.1, the router talking to itself.

A common mistake

Warning

Many people think the Ethernet header travels all the way to the far end. It only lasts one hop. Each router takes it off and puts on a new one for the next cable. The IP header is the one that crosses the whole trip.

Going further: a packet with no transport header

A ping packet is Ethernet IP ICMP. It has no TCP or UDP header at all.

Add a function has_transport(packet) to your assignment. It returns True when one header is TCP or UDP. Try it on a web request and on a ping. Then say why a ping needs no port number.

About this lab and its source: Static routing lab: build routes on a small network in your browser

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.