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

Sources

Practice in the labs

Talk to services by hand, then diagnose a transport problem.

Knowledge check

  1. 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.
  2. 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.
  3. 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.

Related