IP, TCP, and DNS
The three protocols under nearly everything. IPv4 addresses and prefixes, with a /22 mask worked bit by bit; private ranges and the NAT box that gives a whole house one public address, and why IANA ran out in 2011; IPv6's 128 bits; TCP's three-way handshake, byte-numbered sequence, cumulative acknowledgments, and retransmission; Van Jacobson's congestion control after the 1986 collapse that cut a link to a thousandth of its speed; UDP; and DNS from the root servers down, with a real dig +trace of snl.no, caching TTLs, and ss showing live connections.
- 11 min
- 10 steps
- 8 questions
- 7 hands-on
- Lesson 20 of 24 in How Computers Work
- Drafted by Opus 5.5
In this lesson
- Addresses and masks
- One address for the whole house
- IPv6
- The handshake
- Congestion control
- UDP
- Names, from the root down
- Try it on Linux
- Further down the wire
- Walk three names yourself
Picking up where you left off.
Addresses and masks
An IPv4 address is 32 bits, written as four bytes in decimal 1. The first part names a network and the rest a host on it. At first the split came in three fixed sizes, classes A, B, and C, giving 128, 16,384, or about two million networks; by the late 1980s demand for the middle size was growing exponentially 2. Classless addressing lets the split fall anywhere, written as a prefix length: /22 means 22 network bits and 10 host bits, 1,024 addresses 2.
To find the network, AND the address with the mask bit by bit, the operation from Boolean Logic and Gates:
The two ends of the range are reserved: host bits all zero name the network, all ones are the broadcast address 2. A /22 holds 1,024 − 2 = 1,022 machines. Each bit off the prefix doubles the block 2:
| Prefix | Mask | Addresses | Old name |
|---|---|---|---|
| /24 | 255.255.255.0 | 256 | Class C |
| /22 | 255.255.252.0 | 1,024 | |
| /16 | 255.255.0.0 | 65,536 | Class B |
| /8 | 255.0.0.0 | 16,777,216 | Class A |
| /0 | 0.0.0.0 | all 4,294,967,296 | the default route |
The /0 matches every address, which is why “default” in ip route means “anything not more specific”.
Work it out
This exercise needs JavaScript.
32 − 22 = 10 host bits, so 2¹⁰ = 1,024 addresses, less the network address and the broadcast address.
Work it out
This exercise needs JavaScript.
11 is 00001011; the mask’s third byte, 252, is 11111100. ANDed: 00001000, which is 8. The network is 10.1.8.0/22.
Work it out
This exercise needs JavaScript.
A /26 leaves 6 host bits, so networks come in blocks of 64: .0, .64, .128, .192. 77 falls in .64 to .127, and the broadcast address is the top of the block.
One address for the whole house
Your laptop’s 192.168.1.23 is private. RFC 1918 set aside 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16 for anyone to use inside their own network; registries never assign them on the public internet, so the same numbers repeat in house after house 3.
The router holds the one public address and does network address and port translation (NAT). As each connection leaves, it swaps the private address and port for its public address and a port of its own, remembers the pairing, and reverses the swap for replies 4. The RFC’s own example, a telnet session from a private machine:
| Source as sent | Source as the world sees it | |
|---|---|---|
| Address | 10.0.0.10 | 138.76.28.4 |
| Port | 3017 | 1024 |
A reply addressed to 138.76.28.4 port 1024 is rewritten to 10.0.0.10 port 3017 and passed inside. RFC 3022 describes exactly this for small offices and homes sharing a single provider-assigned address. Nothing outside can open a connection to a machine inside unless the router is set to forward a port to it 4. A firewall on the machine itself, such as the ufw rules in Firewall, Updates, and Accounts, is a second gate behind that one 5.
NAT stretched a dwindling supply. On 3 February 2011 IANA handed its last five blocks of IPv4 addresses to the five regional registries; the registries’ own statement said “The future of the Internet is in IPv6” 6.
Quick check
Inside, devices use private addresses that the internet never routes. The router rewrites each outgoing connection to its own public address and a port of its choosing, and reverses it for replies.
IPv6
IPv6 addresses are 128 bits 7, written as eight groups of hexadecimal digits separated by colons 8; Binary and Hexadecimal covers the digits. One of Norway’s name servers, in the lookup below, is 2001:700:0:52d:158:38:8:133. 2¹²⁸ is about 3.4 × 10³⁸ addresses, room for every device to have a public address of its own.
The handshake
TCP turns IP’s unreliable datagrams into a reliable, ordered stream between two programs 9. Before any data moves, the two ends shake hands 10:
The client sends SYN with its starting sequence number; the server answers SYN-ACK with its own starting number and acknowledges the client’s; the client acknowledges that. The point is to keep old duplicate requests, delayed somewhere in the network, from opening phantom connections. Starting numbers come from a clock mixed with a secret, because guessable ones are a security hole 10.
Every byte of data has a sequence number, and acknowledgments are cumulative: “ACK 1101” means everything before byte 1101 has arrived. If no acknowledgment comes within the retransmission timeout, the sender resends; the timeout is computed from measured round trips and backs off exponentially when sends keep failing. Duplicates are easy to spot from their numbers 10.
Two more header fields finish the picture. Window tells the other side how many more bytes, starting from the acknowledged one, this side is willing to accept, so a fast sender can’t swamp a slow reader. FIN says “no more data from me”; each side sends one to close its half of the connection 10.
Put in order
This exercise needs JavaScript.
Three messages, then data. Each side has announced a starting sequence number and seen the other acknowledge it.
Fill the blanks
This exercise needs JavaScript.
SYN opens a connection; FIN closes one half of it. Window keeps a fast sender from swamping a slow reader.
Congestion control
In October 1986 the internet had the first of a series of congestion collapses: between Lawrence Berkeley Laboratory and UC Berkeley, 400 yards apart, throughput fell from 32,000 bits a second to 40. Van Jacobson traced the cause mostly to TCP implementations, which answered loss by sending more into a network already full 11. His fix gives every sender a congestion window. It starts at one packet and grows with each acknowledgment (slow start); a lost packet is taken as the sign of congestion, and the window is halved; otherwise it creeps up by about one packet per round trip 11. RFC 5681 still requires slow start and congestion avoidance of every TCP sender 12.
UDP
UDP is IP plus ports and a checksum. Its whole header is four 16-bit fields, source port, destination port, length, and checksum, 8 bytes against TCP’s 20; there is no handshake, no acknowledgment, no ordering, and a lost datagram stays lost 13. That suits short questions where asking again is cheaper than a connection. DNS queries go to UDP port 53 14. HTTP/3, in HTTP and the Web, builds its own reliability on top of UDP 15.
Names, from the root down
DNS turns names into addresses; How Your Machine Is Connected showed resolvectl asking for one. No server knows every name. Your resolver walks down the tree: a server without the answer returns a referral to servers closer to it, and the resolver follows the referrals until one answers 16.
The two kinds of question differ. Your laptop asks recursively: “find this for me”, and gets back only an answer or an error. The resolver asks the servers on the way non-recursively, and each replies from what it holds: the answer, an error, or a referral 16. Servers listen on UDP port 53 and on TCP port 53 as well 14.
At the top are 13 named root servers, A to M, run by 12 organizations; on 15 November 2026, 2,046 machines answered for them around the world 17. Every record carries a time to live in seconds, how long a resolver may cache it 16. The root’s pointer to the .no servers may be kept two days; the address of snl.no, one minute, so the encyclopedia can move servers quickly.
Put in order
This exercise needs JavaScript.
Each server answers from what it knows, with a referral one level closer. The resolver does the walking and keeps every answer for its TTL.
Find the mistake
This exercise needs JavaScript.
Twelve organizations run the 13 root servers. The .no referral carried a TTL of 172,800 seconds, two days; 7,200 seconds, two hours, was for snl.no’s own name servers.
Try it on Linux
dig comes in Ubuntu’s bind9-dnsutils package 18. With +trace it skips your resolver and walks the referrals itself, printing each server’s answer 19. Here it is on 15 November 2026, trimmed; the outputs in this section are examples, and your servers, addresses, and times will differ:
me@linuxbox:~$ dig +trace snl.no
; <<>> DiG 9.18.39-0ubuntu0.24.04.9-Ubuntu <<>> +trace snl.no
;; global options: +cmd
. 518400 IN NS a.root-servers.net.
[12 more root servers, from the local resolver]
no. 172800 IN NS z.nic.no.
no. 172800 IN NS i.nic.no.
[4 more .no servers, then DS and RRSIG lines]
;; Received 717 bytes from 198.41.0.4#53(a.root-servers.net) in 47 ms
snl.no. 7200 IN NS ns-cloud-a4.googledomains.com.
[3 more, then DS and RRSIG]
;; Received 302 bytes from 158.38.8.133#53(z.nic.no) in 140 ms
snl.no. 60 IN A 34.120.43.127
[an RRSIG signature]
;; Received 217 bytes from 216.239.38.106#53(ns-cloud-a4.googledomains.com) in 21 ms
- Each record reads: name, TTL in seconds, class
IN(internet), type, value. NSlines are referrals: the servers for that zone.Ais the answer, an IPv4 address.DSandRRSIGlines are DNSSEC signatures;+traceasks for them 19.Received ... from ... in ... ms: who answered and how fast. The .no server took 140 ms; Google’s took 21.
For just the answer, dig +short snl.no prints 34.120.43.127.
Then look at live TCP connections, numbers only 20:
me@linuxbox:~$ ss -tn
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
ESTAB 0 0 192.168.1.23:41632 34.120.43.127:443
TIME-WAIT 0 0 192.168.1.23:41618 34.120.43.127:443
ESTAB is a connection past its handshake. TIME-WAIT is one just closed, held a while so stray segments from it can’t be mistaken for a new connection on the same ports 10. The local port, 41632, is the one NAT will swap on the way out.
Further down the wire
Walk three names yourself
Run dig +trace on three names under different top-level domains: a .no or .se site you read, a .edu, and a .com. For each, count the referrals and note the TTL at every level and which server was slowest. Then run plain dig on the same name twice, a few seconds apart, and watch the TTL in the answer count down: that’s your resolver’s cache. Finally, run tracepath -n to one of the servers and compare its hop count with what ping’s TTL suggested in Layers and Packets.
Lesson complete
Nice work.
Teach it back
In two sentences, explain IP, TCP, and DNS to a friend who missed it.
Related lessons
Among the starsSources for this lesson
- 1RFC 791: Internet Protocol. IETF (prepared for DARPA). 1981. verifiedSeptember 1981. Addresses are four octets (32 bits). Header fields include Total Length (16 bits, up to 65,535 octets), flags DF (Don't Fragment) and MF (More Fragments), fragment offset in units of 8 octets, Time to Live (8 bits), protocol, checksum, source and destination addresses. TTL is set by the sender and reduced wherever the datagram is processed (by at least one at each module); at zero the datagram is destroyed, to discard undeliverable datagrams. All hosts must accept datagrams of up to 576 octets, whole or in fragments; every internet module must forward a 68-octet datagram without further fragmentation; a gateway fragments a datagram too big for the next network, and the destination reassembles it.
Also cited in Layers and Packets.
- 2RFC 4632: Classless Inter-domain Routing (CIDR). IETF. 2006. verifiedAugust 2006 (obsoletes RFC 1519). The original plan split the 32-bit space into Class A (128 networks of about 16.7 million hosts), B (16,384 of 65,536) and C (about 2 million of 254); demand for Class B grew exponentially in the late 1980s; CIDR replaced classes with explicit prefix lengths. Table: a /22 holds 1024 addresses, a /16 65,536 (legacy Class B), a /8 16,777,216 (legacy Class A), 0.0.0.0/0 is the default route.
- 3RFC 1918: Address Allocation for Private Internets. IETF. 1996. verifiedFebruary 1996. IANA reserves 10.0.0.0-10.255.255.255 (10/8), 172.16.0.0-172.31.255.255 (172.16/12) and 192.168.0.0-192.168.255.255 (192.168/16) for private internets; anyone may use them without coordination; they are unique only within the enterprise; registries never assign them for external connectivity.
- 4RFC 3022: Traditional IP Network Address Translator (Traditional NAT). IETF. 2001. verifiedJanuary 2001. Network Address Port Translation (NAPT) lets the nodes of a private network share a single registered address, mapping tuples of (local IP address, local TCP/UDP port) to (registered IP address, assigned port); this fits most small office and home office (SOHO) groups using a single provider-assigned address; inbound access needs a static mapping per port.
- 5Firewall (Ubuntu Server documentation). Canonical. verifiedufw is Ubuntu's default firewall configuration tool, a front end to netfilter, initially disabled; sudo ufw enable/disable; ufw allow 22 and deny 22; allow from a host or subnet to a port (ufw allow proto tcp from 192.168.0.2 to any port 22); status and status verbose; status numbered and delete; --dry-run; application profiles in /etc/ufw/applications.d with ufw app list and app info.
Also cited in Setting Up the Server, Firewall, Updates, and Accounts.
- 6Free Pool of IPv4 Address Space Depleted. Number Resource Organization. 2011. verifiedMontevideo, 3 February 2011, read November 15, 2026. On January 31 IANA allocated two blocks to APNIC, triggering the policy to share the last five /8 blocks equally among the five Regional Internet Registries; on February 3 IANA allocated them, so no IPv4 addresses remain for IANA to allocate; each /8 is 1/256 of the IPv4 space; the NRO chairman: 'The future of the Internet is in IPv6.'
- 7RFC 8200: Internet Protocol, Version 6 (IPv6) Specification. IETF. 2017. verifiedJuly 2017. IPv6 increases the address size from 32 to 128 bits; unlike IPv4, fragmentation is performed only by source nodes, not by routers; every link must have an MTU of at least 1280 octets.
Also cited in Layers and Packets.
- 8Networking key concepts (Ubuntu Server documentation). Canonical. verifiedTCP/IP; IPv4 addresses as four numbers 0-255 (32 bits) and IPv6 as eight groups of four hex digits (128 bits); netmasks in CIDR form such as /24; network and broadcast addresses; the gateway, usually a router, for reaching other networks; nameservers resolve hostnames to addresses; on Ubuntu Server, addresses, routes, and nameservers are set in Netplan files in /etc/netplan/; TCP vs UDP.
Also cited in How Your Machine Is Connected.
- 9RFC 1122: Requirements for Internet Hosts - Communication Layers. IETF. 1989. verifiedOctober 1989. Section 1.1.3: the Internet protocol suite has four layers, application, transport, internet, and link; the application layer 'essentially combines the functions of the top two layers -- Presentation and Application -- of the OSI reference model'; transport has TCP (reliable, connection-oriented, resequencing, flow control) and UDP (connectionless datagram); IP is a connectionless datagram service with no end-to-end delivery guarantee, so datagrams may arrive damaged, duplicated, out of order, or not at all, and the layers above are responsible for reliability; ICMP is part of IP; the link layer is the protocol for the directly connected network. Section 1.3.1: strict layering is an imperfect model; implementations involve creative breaking of it. Section 3.3.2: EMTU_R must be at least 576.
Also cited in Layers and Packets.
- 10RFC 9293: Transmission Control Protocol (TCP). IETF. 2022. verifiedAugust 2022 (STD 7, obsoletes RFC 793). Figure 1: the TCP header without options is five 32-bit words (20 bytes): source port, destination port, sequence number, acknowledgment number, data offset/flags (including SYN, ACK, FIN, RST)/window, checksum/urgent pointer. 3.4.1: each new connection gets a 32-bit initial sequence number from a clock plus a secret pseudorandom function, because predictable ISNs are a security problem. 3.4: every octet sent on a TCP connection has a sequence number; acknowledgment is cumulative, so acknowledging X means all octets up to but not including X have arrived; this makes duplicates easy to detect after retransmission. 3.5, Figure 6: the three-way handshake, A sends SYN with SEQ=100, B replies SYN,ACK with SEQ=300 ACK=101, A sends ACK with SEQ=101 ACK=301, then data; its principal reason is to keep old duplicate connection requests from causing confusion. 3.8.1: the retransmission timeout must be computed dynamically (per RFC 6298), with exponential backoff. Header fields: Window, the number of data octets, beginning with the one acknowledged, that the segment's sender is willing to accept; FIN, no more data from sender. 3.4: the TIME-WAIT state limits the rate of connection reuse so that segments from an earlier incarnation of a connection are not mistaken for the new one.
Also cited in Layers and Packets.
- 11Congestion Avoidance and Control. Proceedings of SIGCOMM '88, pp. 314-329 (revised version, November 1988, on the LBL site). 1988. verifiedRead November 15, 2026 in the slightly revised November 1988 version from Lawrence Berkeley Laboratory. In October 1986 the Internet had the first of a series of congestion collapses: throughput from LBL to UC Berkeley, 400 yards and two IMP hops apart, fell from 32 Kbps to 40 bps, a factor of a thousand; the cause lay largely in TCP implementations. Seven new algorithms went into 4BSD TCP, including RTT variance estimation, exponential retransmit backoff, and slow-start. Slow-start: a congestion window, cwnd, starts at one packet and grows by one packet per acknowledgment. Congestion avoidance: a lost packet signals congestion; on a timeout set cwnd to half the current window (multiplicative decrease); on each ack increase it by 1/cwnd (additive increase); send the minimum of the receiver's window and cwnd.
- 12RFC 5681: TCP Congestion Control. IETF. 2009. verifiedSeptember 2009. Section 3.1: the slow start and congestion avoidance algorithms MUST be used by a TCP sender to control the amount of outstanding data injected into the network; the congestion window (cwnd) is the sender-side limit on data sent before an acknowledgment, the receiver's advertised window (rwnd) the receiver-side limit.
- 13RFC 768: User Datagram Protocol. IETF. 1980. verifiedAugust 1980. UDP lets programs send messages with a minimum of protocol mechanism; it is transaction oriented; delivery and duplicate protection are not guaranteed; applications needing ordered reliable delivery should use TCP. The header has source port, destination port, length, and checksum.
- 14RFC 1035: Domain Names - Implementation and Specification. IETF. 1987. verifiedNovember 1987. DNS messages over UDP are limited to 512 octets; servers listen on UDP port 53 and TCP port 53; TTL is a 32-bit count of seconds a record may be cached.
- 15RFC 9114: HTTP/3. IETF. 2022. verifiedJune 2022. HTTP/3 maps HTTP semantics onto QUIC, a UDP-based transport (RFC 9000) with stream multiplexing, per-stream flow control and reliability at the stream level, and TLS 1.3 built in; servers advertise it with the Alt-Svc response header, e.g. Alt-Svc: h3=":50781"; servers may use any UDP port; UDP blocking can make it fail.
Also cited in HTTP and the Web.
- 16RFC 1034: Domain Names - Concepts and Facilities. IETF. 1987. verifiedNovember 1987. A resource record's TTL is a 32-bit time in seconds, used by resolvers when they cache records, saying how long a record may be cached before it should be discarded. A name server in non-recursive mode answers from local information with an answer, an error, or a referral to another server 'closer' to the answer; in recursive mode the server acts as a resolver and returns only an answer or an error, never referrals.
- 17Root Server Technical Operations Association. root-servers.org. verifiedRead November 15, 2026: 'the root server system consists of 2046 operational instances operated by the 12 independent root server operators'; the 13 root name servers, A to M, are operated by 12 organisations: Verisign (A and J), USC-ISI, Cogent, UMD, NASA, ISC, DISA, Army Research Lab, Netnod (I), RIPE NCC, ICANN, and WIDE.
- 18bind9-dnsutils package, Ubuntu 24.04 (noble). Canonical (packages.ubuntu.com). verifiedRead November 15, 2026. 'Clients provided with BIND 9', version 1:9.18.39-0ubuntu0.24.04.9 in main; the file list installs /usr/bin/dig, delv, mdig, nslookup, and nsupdate.
- 19dig - DNS lookup utility (BIND 9 manual pages). Internet Systems Consortium. verifiedRead November 15, 2026. +trace traces the delegation path from the root name servers: dig makes iterative queries, follows referrals from the root servers, and shows the answer from each server used; +dnssec is set when +trace is set, to emulate a name server's default queries; +short gives a terse answer.
- 20ss(8) manual page. man7.org (Linux man-pages). verifiedRead November 15, 2026. ss investigates sockets; with no options it lists non-listening sockets that have established connections; -t TCP, -n numeric, -a all; state filters name the standard TCP states: established, syn-sent, syn-recv, fin-wait-1, fin-wait-2, time-wait, closed, close-wait, last-ack, listening, closing; example ss -t -a.