devutils/ATFQ/book ATFQ git

Part I · How it works

6.1 Network layers: OSI and TCP/IP

alsoosiosi modelnetwork layerstcp/ip modelnetwork stacklayers

TL;DR

  • A network is built in layers, each using the one below: link (Ethernet, Wi-Fi), network (IP), transport (TCP, UDP), application (HTTP, DNS, SSH).
  • The OSI model names seven layers, the Internet uses four, and people still say "layer 2" for Ethernet and "layer 7" for HTTP.
  • When something fails, check from the bottom up:
ip -br link                     # 2: is the link up?
ip -br addr; ip route           # 3: an address, and a way out?
ping -c 3 1.1.1.1               # 3: does IP reach the Internet?
dig example.com                 # 7: do names resolve?
curl -I https://example.com     # 4 to 7: TCP, TLS, HTTP

On your machine

alice@laptopexample
$ atfq 6.1
  L2 link   wlp0s20f3 up · neighbour 192.168.1.1 is f4:92:bf:0e:21:7a on
            wlp0s20f3
  L3 IP     docker0 172.17.0.1/16, wlp0s20f3 192.168.1.23/24, wlp0s20f3
            fe80::8ec6:81ff:fe2a:107f/64 · gateway 192.168.1.1 · forwards
            packets for others
  L4 TCP    12 connections open now; 30,120 started and 410 accepted since
            boot · 1,840 of 3.1 million segments resent
  L4 UDP    95,000 datagrams in, 61,000 out, since boot
  L7 DNS    127.0.0.53

An example: Alice's laptop, one of the test machines. In your terminal, this block shows your own machine, read live.

Pitfalls

Deep dive 2 questions

Where does the OSI model come from?

From an ISO standard published in 1984, meant to define a complete set of network protocols. Those protocols lost to TCP/IP, which already ran on the ARPANET and in BSD Unix. The seven-layer vocabulary stayed, as the common way to say where a problem sits.

What does each layer add?

On the way out, each layer wraps what comes from above in its own header: TCP adds ports and sequence numbers, IP adds the source and destination addresses, Ethernet adds MAC addresses. The receiver unwraps them in reverse order. A packet carrying a few bytes is mostly headers.

Commands
ip ping dig curl
See also
19. Network
6.2 What happens when you open a website
6.5 Ethernet, MAC addresses and ARP
6.4 TCP, UDP and connections