---
title: "Quiz: Transport Layer: TCP, UDP and Ports"
domain: networking
level: beginner
questions: 10
---

# Quiz: Transport Layer: TCP, UDP and Ports

## Questions

### 1. A web server listens on TCP port 443. When your browser on a Linux laptop connects to it, which source port does the connection use?
*Objective: 1 — the transport layer's job; well-known, registered and ephemeral ports*

- A) Port 443 as well, because both ends of a connection must use the same port
- B) Port 80, because browsers always send from the HTTP port
- C) An ephemeral port that the operating system picks for this connection, by default from 32768–60999 on Linux
- D) A port from 0–1023, because those ports are reserved for clients

### 2. A web server sits behind a *stateless* firewall rule set that allows inbound TCP to destination port 443 and outbound TCP from source port 443 to destination port 443 only. Clients' SYNs reach the server, but no client ever completes a connection. Why?
*Objective: 1 — the transport layer's job; well-known, registered and ephemeral ports*

- A) The server's replies go to each client's ephemeral port, not to port 443, so the outbound rule drops them; it must allow destination ports in the clients' ephemeral range
- B) Port 443 is a well-known port, so firewalls can't filter it
- C) The server needs a different port for each client, so a single rule for 443 can't work
- D) The clients must also listen on port 443 to receive the replies

### 3. Which statement about UDP is correct?
*Objective: 2 — comparing TCP and UDP and choosing one for an application*

- A) UDP delivers datagrams in order but doesn't guarantee that they arrive
- B) UDP is slower than TCP because it checks every datagram twice
- C) UDP can't be used for applications that need reliable delivery
- D) Each datagram arrives whole or not at all; UDP doesn't detect loss, duplication or reordering, so the application must deal with them if it cares

### 4. A developer wants to replace TCP with plain UDP in a file-synchronization tool "to make it faster". Files must arrive complete and uncorrupted. What will the developer have to build into the application?
*Objective: 2 — comparing TCP and UDP and choosing one for an application*

- A) Nothing: UDP's checksum already guarantees that every file arrives complete
- B) Sequence numbers, acknowledgements, retransmission, reordering and congestion control: in effect, much of what TCP (or QUIC) already provides
- C) Only encryption, because UDP sends data in clear text while TCP encrypts it
- D) A three-way handshake, because UDP refuses to send data without one

### 5. A capture shows the start of a TCP connection with absolute sequence numbers. Which acknowledgement number does the third segment carry?
*Objective: 3 — handshake, teardown, sequence and acknowledgement numbers, retransmission, flow control*

```text
IP 192.0.2.10.51200 > 203.0.113.80.443: Flags [S], seq 4000, length 0
IP 203.0.113.80.443 > 192.0.2.10.51200: Flags [S.], seq 9000, ack 4001, length 0
IP 192.0.2.10.51200 > 203.0.113.80.443: Flags [.], ack ?, length 0
```

- A) `ack 9001`
- B) `ack 4001`
- C) `ack 9000`
- D) `ack 13001`

### 6. A sender transmits three segments of 500 bytes each, starting at sequence numbers 1001, 1501 and 2001. The receiver gets the first and the third; the second is lost. Which acknowledgement number does the receiver send when the third segment arrives?
*Objective: 3 — handshake, teardown, sequence and acknowledgement numbers, retransmission, flow control*

- A) `ack 2501`, because that is the next byte after the last segment received
- B) `ack 2001`, because the third segment starts there
- C) `ack 1501`, a duplicate acknowledgement: it can only acknowledge up to the first missing byte
- D) No acknowledgement at all until the missing segment arrives

### 7. A Linux application server has been running for a week. You see the output below, and the number of these lines grows every day until the service stops accepting work. What is the most likely cause?
*Objective: 4 — listening sockets and connection states with `ss` or `netstat`*

```text
$ ss -tan state close-wait | head -4
Recv-Q Send-Q   Local Address:Port    Peer Address:Port
1      0         198.51.100.15:8080      192.0.2.44:52018
1      0         198.51.100.15:8080      192.0.2.44:52044
1      0         198.51.100.15:8080      192.0.2.61:40112
```

- A) Normal behaviour: these sockets are in TIME-WAIT and expire after 60 seconds
- B) The clients have closed their side, but the application on port 8080 never calls `close()` on those connections
- C) A SYN flood is filling the server's half-open connection queue
- D) The server's ephemeral port range is too small

### 8. Which line of `ss -tan` output on a Linux server shows a service that other hosts on the network can open new connections to?
*Objective: 4 — listening sockets and connection states with `ss` or `netstat`*

- A) `LISTEN    0  4096  127.0.0.1:5432      0.0.0.0:*`
- B) `ESTAB     0  0     198.51.100.15:22   192.0.2.7:51022`
- C) `TIME-WAIT 0  0     198.51.100.15:443  192.0.2.10:50388`
- D) `LISTEN    0  511   0.0.0.0:443        0.0.0.0:*`

### 9. You run `nc -vz 203.0.113.80 5432` and immediately get "Connection refused". What does that tell you?
*Objective: 5 — troubleshooting "connection refused" versus "connection timed out"*

- A) A firewall on the path is silently dropping your SYN
- B) The host `203.0.113.80` is switched off
- C) Your SYN reached the host (or a firewall that actively rejects), and the answer was RST: nothing accepts connections on port 5432 at that address, so check whether the service runs and which address it listens on
- D) The name of the host couldn't be resolved by DNS

### 10. An internal API answers `nc -vz` from a host in the same data-centre network, but from a laptop on the Internet the same test ends with "Connection timed out". `ss -tln` on the API server shows `LISTEN 0 511 0.0.0.0:8443 0.0.0.0:*`. Where is the problem most likely?
*Objective: 5 — troubleshooting "connection refused" versus "connection timed out"*

- A) In the API application, which has crashed
- B) In a firewall, security group or routing between the Internet and the server, which drops the SYN from outside
- C) In the API server's listening address, which only accepts local connections
- D) In TIME-WAIT on the server, which blocks new connections from the Internet

---

## Answer key

<details>
<summary>Show answers</summary>

| # | Answer | Explanation |
|---|---|---|
| 1 | C | The server port is fixed (443); the client's operating system picks a free ephemeral port for each connection. RFC 6335 reserves 49152–65535 for that, but Linux defaults to 32768–60999. The two ends of a connection don't need the same port. |
| 2 | A | Replies travel from server port 443 to the client's ephemeral port. A stateless filter checks each packet on its own, so it needs a rule for that return traffic; a stateful firewall would allow it automatically. Port 443 can be filtered like any other port. |
| 3 | D | UDP (RFC 768) is connectionless and best effort: no acknowledgements, no ordering, no retransmission. That doesn't rule out reliable applications: QUIC builds reliability on top of UDP. UDP isn't slower; its header is only 8 bytes. |
| 4 | B | Over plain UDP, the application must number data, acknowledge it, resend losses, put it back in order and avoid overloading the network. The UDP checksum only detects corruption of one datagram; neither TCP nor UDP encrypts, and UDP has no handshake. |
| 5 | A | The client acknowledges the server's SYN: its ISN 9000 plus one, because a SYN uses one sequence number. `ack 4001` is what the server sent to acknowledge the client's SYN. |
| 6 | C | TCP acknowledgements are cumulative and name the next byte expected. Bytes 1501–2000 are missing, so the receiver repeats `ack 1501`. Duplicate ACKs like this trigger fast retransmit. With SACK it can also report that it already holds 2001–2500. |
| 7 | B | CLOSE-WAIT means the peer sent FIN and the local application hasn't closed its socket yet. Sockets that pile up and never leave CLOSE-WAIT point to an application bug, not to TIME-WAIT, a SYN flood (those would be SYN-RECV) or the port range. |
| 8 | D | `LISTEN` on `0.0.0.0` accepts connections on every IPv4 address of the host. Line A listens on loopback only, so only local programs can connect. Lines B and C are existing or finished connections, not listening sockets. |
| 9 | C | "Refused" is an answer: the host's TCP stack (or a rejecting firewall) replied with RST. A silent drop or a switched-off host gives a timeout instead, and a DNS failure gives a name-resolution error before any connection attempt. |
| 10 | B | The service listens on all addresses and works from inside, so the application and its bind address are fine (a loopback-only bind would fail from inside too). A timeout from outside means nothing answers the SYN there: look at the edge firewall, security groups and routing. |

</details>
