Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

The Seven Layers at a Glance

The OSI (Open Systems Interconnection) model divides the work of a network into seven layers. Each layer does one job and relies on the layer below it.

LayerJobExamples
7 ApplicationWhat programs exchangeHTTP, DNS, SSH
6 PresentationFormat, encryptionTLS, encodings
5 SessionKeeping a dialog openSessions, RPC
4 TransportProgram to programTCP, UDP
3 NetworkAddressing, routingIP, ICMP
2 Data linkFrames on one linkEthernet, Wi-Fi
1 PhysicalBits on the mediumCopper, fiber, radio

A common memory aid from the bottom up: "Please Do Not Throw Sausage Pizza Away".

How Data Moves Through the Layers

On the sending side, each layer wraps the data from the layer above in its own header. An HTTP request becomes the payload of a TCP segment with source and destination ports, which becomes the payload of an IP packet with source and destination addresses, which becomes the payload of an Ethernet frame with MAC addresses, which is sent as bits. The receiving side unwraps the layers in reverse order. That is why people say "frame" at layer 2, "packet" at layer 3, and "segment" or "datagram" at layer 4.

Where Real Protocols Sit

The OSI model was designed as the framework for a family of protocols that never took over. The internet runs on TCP/IP, which draws its layers differently, so some protocols fit the model only loosely:

  • Ethernet: layers 1 and 2. Switches work here with MAC addresses; see what is a MAC address.
  • ARP: usually described as sitting between layers 2 and 3, because it maps IP addresses to MAC addresses.
  • IP: layer 3, where routers work. ICMP, used by ping, is usually placed here too.
  • TCP and UDP: layer 4; see TCP vs UDP.
  • TLS: often placed at layer 6 by convention, though some put it at layer 5 and it does not fit any one layer cleanly.
  • HTTP, DNS, SSH, SMTP: layer 7. In practice, layers 5, 6, and 7 are handled together by the application and its libraries.

OSI and the TCP/IP Model

OSI layersTCP/IP layer
7, 6, 5Application
4Transport
3Internet
2, 1Link

The TCP/IP model describes the protocols that are actually in use; the OSI model is the vocabulary people use to talk about them. See what is TCP/IP.

What "Layer 4" and "Layer 7" Mean in Practice

  • Layer 4 load balancer: forwards TCP or UDP connections by address and port without reading their content. It is fast and works for any protocol, but cannot route by URL.
  • Layer 7 load balancer: reads the HTTP request and can route by host name, path, or header, terminate TLS, and add headers. See what is a load balancer.
  • Network firewall: rules on layers 3 and 4: addresses, protocols, and ports.
  • Web application firewall: inspects HTTP requests at layer 7.
  • Switch and router: a switch forwards frames at layer 2, a router forwards packets at layer 3.

Troubleshooting from the Bottom Up

When a service does not answer, check one layer at a time, starting at the bottom. The first layer that fails is where the problem is. The commands below run on the server or on a Linux machine that tries to reach it:

# Layers 1 and 2: is the interface up?
ip link show eth0
# Layer 2: is the gateway's MAC address known?
ip neigh
# Layer 3: does the gateway answer, and which route is used?
ping -c 4 203.0.113.1
ip route get 198.51.100.20
# Layer 4: is the port open?
nc -zv 198.51.100.20 443
# Layers 5 and 6: does the TLS handshake complete?
openssl s_client -connect example.com:443 -servername example.com
# Layer 7: what does the application answer?
curl -I https://example.com

Reading the Results

A link that is DOWN, a gateway that never answers ARP, or a missing route explains why nothing above it works. If ping and the port test succeed but TLS fails, look at the certificate and protocol settings; openssl s_client shows the details. If curl gets an error status, the network is fine and the application is the place to look.

Was this answer helpful?
Loading...