Memra

What the other machine is, and how you name it

◈ 10 cards

Distinguish TCP from UDP, place a port number in the right range, derive an IPv4 address class from its leading bits, and say what DNS actually resolves.

One request, end to end

Before any remote command makes sense, follow a single ordinary web request across the network and name what does each part.

A name. You type a host name. A name is for people; the network cannot route on it.

DNS. Your machine asks a name server to translate the name into an address. DNS is a distributed database of name-to-address mappings, run by many organisations rather than one, and it is queried through resolver functions the application calls without thinking about it. The historical alternative is the static /etc/hosts file, one line per host — workable on a LAN of twenty machines, hopeless at Internet scale and only ever as correct as whoever last edited it.

An address. DNS answers with an IPv4 address — 32 bits, written as four decimal numbers — or an IPv6 address, which is 128 bits written in colon-separated hex.

A connection. Your browser opens a TCP connection to that address, at port 80. The address selects the machine; the port selects which program on it. TCP shakes hands first, then guarantees that what you send arrives, in order and uncorrupted, retransmitting as needed.

Segments and routing. TCP hands its segments to IP, which wraps them in datagrams and routes them hop by hop. IP itself is connectionless and best-effort — it will happily lose or reorder a datagram. Every reliability guarantee you have comes from TCP layered on top, never from IP.

The reply comes back the same way and TCP reassembles it in order.

The same exchange over UDP, and what is lost

Swap TCP for UDP and most of the machinery goes away. There is no handshake, so the first byte can leave immediately; there are no acknowledgements, no retransmission, no sequencing, and no flow control. A UDP packet is a datagram, and it is genuinely best-effort: it may vanish, arrive twice, or overtake the one sent before it. What you gain is the absence of overhead and of head-of-line blocking, which is why live video and voice prefer it — a late frame is worth less than no frame, and there is no point retransmitting a moment that has passed. What you lose is every guarantee, so if the application needs one it has to build it.

Ports: three ranges, three owners

A port number is 16 bits, so 0 through 65535, and the range is split three ways. 0 to 1023 are the well-known ports, assigned by IANA — 22 for ssh, 23 for telnet, 80 for http. On a UNIX system only a privileged process may bind one, which is a real security property: if you connect to port 22 you know the program listening was started by someone with root. 1024 to 49151 are registered with IANA by whoever wants a stable number for their service, and any user may bind them. 49152 to 65535 are dynamic or private, which is where the kernel takes the ephemeral port it gives your outgoing connection. /etc/services is the local copy of the names.

Worked example: reading an address class off the leading bits

Classful addressing is history in the routers and current on the exam, and the exam wants the derivation, not the table. Take the first byte and write it in binary; the leading bits name the class, and the class fixes how the remaining 32 bits split between a network part and a host part.

ClassLeading bitsNetwork bitsFirst byte
A070 to 127
B1014128 to 191
C11021192 to 223
D1110multicast224 to 239

So 200 is 11001000, which begins 110, so 200.1.2.3 is class C: 21 network bits, hence 2 to the 21st networks, and 8 host bits, hence 2 to the 8th minus 2 usable hosts — the all-zeros and all-ones host patterns are the network address and the broadcast address, and neither names a machine. Do the same arithmetic for class A and class B and you have reproduced the whole table from four bit-counts.

Two addresses are worth knowing by themselves. 127.0.0.0/8 is loopback: a datagram sent to 127.0.0.1 is handed straight back up the stack by your own kernel and never reaches the wire, so a packet capture on your interface shows nothing at all. And a host part of all ones is the directed broadcast address for its network.

UDPTCPconnectionconnectionlessconnection-orientedguaranteebest effortreliable, in sequenceunit is called adatagramsegmentcostnone - just sendhandshake, state, ackssuitslive video and voicefile transfer, ssh, httpIP under both is connectionless and best-effort.
Everything in the TCP column is paid for with the first row. If you do not need the guarantee, you should not be paying for the handshake.
RangeNameAssigned byWho may bind0-1023well knownIANAprivilegedprocesses only1024-49151registeredIANA, on requestany user49152-65535dynamic / privatenobodyany user, usuallythe kernel/etc/services is the local list of the assigned names.
A 16-bit field split three ways. The privilege rule on the first range is what lets you infer something about who started the program answering on port 22.

source iproute2 ss(8); POSIX.1-2024 /etc/services

source iproute2 ip(8); traceroute(8)

NORMAL ~/memra/learn/comp-325/networks-tcp-udp-ports-and-dns utf-8 LF