Skip to content

ElementaryLesson 1 of 9

Layers ​

Sending a message across a network is split into layers, and each layer has one job. On the way out, each layer wraps the message in a small label of its own. On the way in, each layer reads its label and hands what is inside to the next layer up.

Five layers, five jobs ​

LayerIts jobWhat it usesWhere you met it
1 PhysicalCarry bits as signalsCables, light, radio wavesWhat is a network?
2 LinkReach the next device on the same local networkFrames, hardware addresses, switches, Ethernet, ARPSwitches
3 NetworkReach a device on any network, one hop at a timePackets, IP addresses, routers, ICMPRouters and the gateway
4 TransportReach the right program, and with TCP, check every piece arrivedPorts, TCP, and UDPPorts and protocols
5 ApplicationSay what the program wantsWeb pages, DNS questionsDNS

Each layer uses only the layer under it, and does not care how that layer works. A web browser does not know if the page came over a cable or over Wi-Fi. A switch does not know if a frame holds a web page or a DNS question. So you can change one layer without touching the others, and you can look for a problem one layer at a time.

Wrapping on the way down ​

Each layer adds a A few bytes at the front of a message that say where it goes and how to handle it. Each layer adds its own. in front of whatever the layer over it hands down. The finished bundle, one header inside another, is like a letter in an envelope inside another envelope. This wrapping is called Wrapping a message in one header per layer on the way down, so each layer can read its own header on the way up..

Try itWrap a DNS question for the cable
5 ApplicationDNS questionWhat is the address of circuit.tako.id?

Add the headers in the order the laptop adds them, starting with the one closest to the question.

The headers are not free. On this small question they add 46 bytes: 8 for UDP, 20 for IP, and 18 for the frame. That is why a network always carries a little less than its cable's speed.

CheckA frame leaves the laptop. Which header does the next device on the cable read first?

Who opens which layer ​

The devices in the middle of the trip open only as many layers as their job needs:

  • A switch works at layer 2. It reads the hardware address in the frame header, sends the frame out of the right port, and changes nothing.
  • A router works at layer 3. It takes off the frame header, reads the IP address, lowers the TTL, and wraps the packet in a new frame for the next hop.
  • The device at the end opens every layer, up to the program the message is for.
Try itFollow the question through a switch and a router
Laptop192.168.20.10SwitchRouterDNS server192.168.30.53
LayerAt the laptop
5 ApplicationAdded Writes the question: what is the address of circuit.tako.id?
4 TransportAdded Adds a UDP header: from port 51000 to port 53
3 NetworkAdded Adds an IP header: from 192.168.20.10 to 192.168.30.53, TTL 64
2 LinkAdded Adds a frame header: from 3c:22:fb:0a:91:7e to 00:00:5e:00:53:01, the router
1 PhysicalAdded Sends every bit as signals on the cable

Step 1 of 4

The laptop wraps the question

The frame is addressed to the router, because the server is on another network.

The IP addresses stay the same from the laptop to the server, and only the frame changes at each hop. This is the envelope inside an envelope from Addresses.

CheckA packet crosses three routers on its way to a server. What is still the same when it arrives?

Layer 2, layer 3, and the OSI model ​

People often say "layer 2" or "layer 3". The numbers come from an older model called Open Systems Interconnection: a model from the 1980s that splits networking into seven layers. People still use its layer numbers., which has seven layers instead of five. Its bottom four are the same as in this lesson. Its top three are all part of the application layer here:

This lessonOSIWhat people say
Application5 Session, 6 Presentation, 7 Application"layer 7"
Transport4 Transport"layer 4"
Network3 Network"layer 3"
Link2 Data link"layer 2"
Physical1 Physical"layer 1"

So a "layer 2 problem" is about frames, hardware addresses, and switches. A "layer 3 problem" is about IP addresses and routes. A "layer 3 switch" is a switch that can also route, as many bigger switches can.

CheckA router can be told to block some traffic. If such a rule works at layer 4, what does it look at?

Layers in a Circuit file ​

The fields of a Circuit device file follow the layers too:

LayerIn a Circuit device fileLesson
1 Physicalinterfaces.ethernet, a port's speed, and link: where the cable goesTrunks
2 Linkswitching.vlans, and a port's access_vlan or trunk_vlansVLANs
3 Networkaddresses on a port or interface, and routingDHCP
4 Transportprotocol and dst_port in a firewall ruleFirewalls
7 Applicationsystem.dns, and management.ssh: programs the device itself runsWriting a network down

Here is part of a router's file, with the layer of each line in its comment.

ts
system: { dns: { servers: ["203.0.113.53"] } }, // 7: the DNS server this router asks
interfaces: {
    ethernet: {
        "1g-1": { description: "Internet provider", addresses: ["203.0.113.2/30"] }, // 1: a port, and 3: its IP address
    },
},
routing: { static_routes: [{ prefix: "0.0.0.0/0", next_hop: "203.0.113.1" }] }, // 3: everything else goes to the provider

Circuit Studio draws your network one layer at a time too: the cables, the VLANs on each cable, and which devices share an address range.

Discussion

Stuck, or found a mistake? Ask here. You sign in with GitHub.

Released under the Business Source License 1.1.