Ports, TCP and UDP
Unit 2 of 5 in Networking fundamentals.
You will be able to explain what a port is and what TCP and UDP each promise.
Lesson
An address finds the host; a port finds the service
One computer can run many network services at once. TCP uses port numbers to identify application services and to multiplex distinct flows between hosts. The address gets the datagram to the right machine, and the port gets the data to the right program on it.
A TCP connection is defined by a pair of sockets, one for each end. That is why you can have many separate connections to the same web server at the same time.
TCP: a reliable, ordered stream
TCP gives applications a reliable, in-order byte stream. It does this by detecting lost packets with sequence numbers, detecting errors with checksums, and fixing problems by retransmitting. A connection starts with a short exchange between the two sides, the three-way handshake, before data flows.
RFC 1122 describes TCP as connection-oriented, with end-to-end reliability, resequencing and flow control.
UDP: just send the message
UDP is the minimal option. Its specification says it lets programs send messages with a minimum of protocol mechanism, that it is transaction oriented, and that delivery and duplicate protection are not guaranteed. It says applications that need ordered, reliable delivery of streams should use TCP.
So the choice is a trade: TCP does the bookkeeping for you, UDP leaves it to the application. Neither one hides data; encryption is a separate layer.
What a defender takes from this
Each service listening on a port is a way in, so the fewer you expose the less there is to defend. NIST's firewall guidance recommends blocking traffic that the organization does not need, a practice it calls deny by default, because it decreases the risk of attack. The labs show you how to see which ports your own machine is listening on.
Key points
- Addresses find hosts; ports find services on a host.
- A TCP connection is defined by a pair of sockets.
- TCP is a reliable, ordered stream using sequence numbers, checksums and retransmission.
- UDP sends messages with minimal mechanism and no delivery guarantee.
- Expose only the ports you need.
Sources
- RFC 9293: Transmission Control Protocol (TCP)
- RFC 768: User Datagram Protocol
- RFC 1122: Requirements for Internet Hosts, Communication Layers
- NIST SP 800-41 Rev. 1: Guidelines on Firewalls and Firewall Policy
Practice in the labs
Talk to services by hand, then diagnose a transport problem.
- Talk to network services by hand with netcat and socat: You type a web request by hand over a plain TCP connection and see that a port is just a way to reach a program.
- Diagnose a path MTU black hole with ping and tracepath — then fix it without opening ICMP wide: You chase a connection that starts but stalls, a classic transport-layer puzzle that teaches you to measure instead of guess.
Knowledge check
- What does a port number identify? Answer: An application service on a host. RFC 9293 says TCP uses port numbers to identify application services and to multiplex distinct flows between hosts.
- Which statement about UDP is correct? Answer: Delivery and duplicate protection are not guaranteed. RFC 768 says UDP is transaction oriented and that delivery and duplicate protection are not guaranteed; applications needing ordered reliable streams should use TCP.
- How does TCP notice that a packet was lost? Answer: It uses sequence numbers to detect losses and retransmits. TCP reliability consists of detecting losses with sequence numbers and errors with checksums, and correcting by retransmission (RFC 9293).
Back to the syllabus or see all classes.