Unit 3.1 · about 3 h
249 / 324Network layers, addressing, routing and DNS
Every later diagnosis in this section starts by asking which layer broke. Layers do not exist on the wire; they are a debugging vocabulary, and DNS plus routing are the two lookups every connection performs first.
- explain
You can now
- Use the OSI 7-layer and TCP/IP 4-layer models to place a failure at the right layer, and state where each model misleads.
- Trace a DNS lookup from stub resolver through root, TLD and authoritative server, and apply the TTL expiry rule.
- Read a host routing-table entry and predict the next hop with longest-prefix match.
Covers
- Network layers as an explanatory model
- IP addresses, ports, routing and DNS lookup
Study, in this order
4 steps
- The OSI 7-layer modelAlgoMaster Networks - pcap and concurrent server labs
The Seven Layers at a Glance; Encapsulation Across the Stack; Using OSI to Diagnose a Failure; Where the Model Has Limits
- The TCP/IP 4-layer modelAlgoMaster Networks - pcap and concurrent server labs
The Four Layers; Mapping TCP/IP to OSI; A Complete Request in TCP/IP Terms; Boundaries in Modern Protocols
- Layering, IP and routing in Beej's Network ConceptsBeej's Guide to Network Concepts - TCP and UDP path
Chapter 4, The Layered Network Model (Sections 4.3 and 4.4); Chapter 18, IP Routing (Sections 18.2 to 18.5)
- DNS hierarchy and debuggingAlgoMaster Networks - pcap and concurrent server labs
Domains and Zones Are Different; Following the Chain of Authority; Practical Implications for Engineers; then Debugging DNS with dig and nslookup: The Basic dig Command, Walk the Delegation with
+trace, Diagnose Cache and TTL BehaviorDepth · Use https://algomaster.io/learn/computer-networks/debugging-dns for the dig sections; skip DNSSEC detail.
Focus on
- OSI layers are an explanatory model. The wire carries frames, packets and segments; nothing is tagged with a layer number.
- DNS resolution is a chain of referrals with per-record TTLs. A cached answer is valid while now is earlier than stored time plus TTL; reading it does not refresh it.
- Routing is longest-prefix match on the destination, per packet, per hop. The default route is only the shortest prefix that matches.
- Sending adds transport, internet and link headers around application data in that order; receiving strips them in reverse.
Reproduce closed-book
dig +short example.com twice and compare the answer sets. Then closed-book, write the cold-lookup chain (stub to recursive to root to TLD to authoritative) and evaluate the TTL rule on store(api.example, 192.0.2.10, TTL 10, t=100): resolve at \(t=109\) hits, at \(t=110\) misses.Traps
- Treating OSI as seven things a packet passes through in code. Implementations merge and skip layers; TLS, for example, sits between transport use and the application.
- Reading a DNS TTL as a freshness guarantee. It bounds staleness; an authoritative change still waits out the TTL at every cache.
- Inferring network meaning from dotted quads or old class letters. Only the prefix length defines the network part.
Practice
AlgoMaster: Implement a DNS TTL Cache
store and resolve with TTL expiry (\(\text{now} < t + d\)), case-insensitive names, cached NXDOMAIN
Do not refresh expiry on resolve; the 109-hit 110-miss boundary in Reproduce is the first case to pass.
Self-test
-
A record stored at \(t=100\) with TTL 10 is resolved at \(t=110\). Hit or miss, and why?
Miss. It is valid only while \(\text{now} < 100 + 10\), and resolving does not refresh the expiry. -
Entries cover
10.0.0.0/8and10.1.2.0/24. Which carries a packet for10.1.2.9?10.1.2.0/24. Longest-prefix match wins; the /24 is more specific than the /8. -
Why can two applications on one host share one IP address without conflict?
The transport port number separates them. The IP address names the host; the port names the socket endpoint. -
A capture shows HTTP inside TLS inside TCP inside IPv4 inside Ethernet. Which layering claim does this support?
Encapsulation order only. It shows headers wrapped around data; it does not prove a seven-layer implementation.
Completion criterion
Stop when
You place a refused connection, an NXDOMAIN and a wrong route at the right layer on the first guess, and your TTL cache passes the 109-hit 110-miss boundary.
Leads to
- 3.2 TCP and UDP transport behavior Move one layer up to transport behavior on the path you can now address.
- 3.3 TLS and HTTP versions See what TLS and HTTP add above the addressed transport path.
Resources for this unit
- Beej's Guide to Network Concepts - TCP and UDP path Read the OS and sockets, protocol layering, IP, UDP and TCP chapters alongside packet captures from your own client and server. Use it to explain transport behavior rather than memorize layer names.
- AlgoMaster Networks - pcap and concurrent server labs Use Reading a Packet Capture: A Real Bug and Building a Concurrent TCP Echo Server after the Beej implementation. Reproduce one packet-level observation and one admission, deadline or shutdown behavior in your independently written service.
Also in this section
- Beej's Guide to Network Programming - sockets to multiplexing Read What is a socket?, IP addresses and data structures, Client-server background, System calls or bust, Client-server examples, Slightly advanced techniques and sendall. Build the simple TCP pair first, then replace delimiter assumptions with a bounded length-prefixed protocol.
- MIT 6.5840 - RPC, threads and fault vocabulary Read the introductory RPC and threads material plus the lab guidance. Use it to enumerate timeout ambiguity and duplicate effects. Stop before Raft and the full lab sequence.
- Replicated Log and Stream Processor - protocol slice Use only the protocol requirements, deterministic network fault matrix and delivery-contract questions. Build the single-node framed service now; keep replication and consensus for the later project.
- Designing Data-Intensive Applications, 2nd edition - Chapter 5 Read Formats for Encoding Data (printed pp. 163 to 177) for schema merits and compatibility, and Dataflow Through Services: REST and RPC (printed pp. 180 to 186) for service dataflow, version coexistence and the idempotence pointer.
- gRPC Deadlines guide Read Overview, Deadlines on the Client and Deadline Propagation for absolute deadlines, remaining-time forwarding and clock-skew shielding.
- gRPC Status Codes Read the full status list, including
DEADLINE_EXCEEDED,UNAVAILABLEand the codes never generated by the library, for the error taxonomy. - W3C Trace Context Read Section 3.2 for the
traceparentformat and Sections 3.4 to 3.5 for the legaltraceparentandtracestatemutations when forwarding.