Sub topic 4
Ports and Well-Known Port Numbers
This chapter assumes you know the difference between TCP and UDP from the previous chapter. You should also be able to open a Windows command prompt and read an IPv4 address. The chapter explains what a port is, how port numbers are grouped, which well-known ports the exam expects you to know, and how to see ports in use on a Windows computer.
What a port is
An IP address gets a packet to the right computer. A port is a 16-bit number that gets the data to the right program on that computer. One computer can browse the web, send mail, and accept remote desktop connections at the same time, and the port number tells the operating system which program receives each piece of incoming data.
Because a port is 16 bits, valid values run from 0 to 65535. Ports exist separately for TCP and UDP. TCP port 53 and UDP port 53 are different endpoints, even though DNS uses both.
A socket is the combination of an IP address, a port number, and a transport protocol. A written socket looks like 192.168.1.20:443. A single connection is identified by four values: source IP, source port, destination IP, and destination port, plus the protocol. This is why a thousand browsers can all connect to the same web server on port 443. Each client has a different source port, so each connection is unique.
The three port ranges
The Internet Assigned Numbers Authority (IANA) divides the port space into three ranges.
| Range | Name | Typical use |
|---|---|---|
| 0 to 1023 | Well-known (system) ports | Standard services such as HTTP, SSH, DNS |
| 1024 to 49151 | Registered ports | Vendor applications, such as database servers and games |
| 49152 to 65535 | Dynamic (ephemeral, private) ports | Temporary source ports chosen by clients |
Most of the exam's port questions come from the first range.
How a client and server use ports
A server listens on a fixed, well-known port so clients know where to connect. A client does not need a fixed port. The operating system picks a free ephemeral port for each outgoing connection and releases it when the connection ends.
Windows chooses ephemeral ports from 49152 to 65535 by default. Some other systems use a different range, so treat the IANA range as the exam answer and the actual range as something that can be configured.
Well-known ports to memorize
The table below lists the ports most often tested on A+ Core 1. The next chapter covers what each protocol does, so here you only need to match number to name.
Port Protocol Service
20/21 TCP FTP (data/control)
22 TCP SSH, SFTP
23 TCP Telnet
25 TCP SMTP
53 TCP/UDP DNS
67/68 UDP DHCP (server/client)
69 UDP TFTP
80 TCP HTTP
110 TCP POP3
137-139 TCP/UDP NetBIOS/NetBT
143 TCP IMAP
161/162 UDP SNMP (queries/traps)
389 TCP/UDP LDAP
443 TCP HTTPS
445 TCP SMB over TCP
3389 TCP/UDP RDPSome memory aids help. The mail protocols are 25 for sending (SMTP), 110 for POP3, and 143 for IMAP. The two DHCP ports are 67 for the server and 68 for the client. SNMP uses 161 for queries and 162 for traps, which are alerts sent by a device without being asked.
Secure and insecure pairs
Many exam questions ask you to replace an unencrypted service with an encrypted one.
| Insecure | Port | Secure replacement | Port |
|---|---|---|---|
| Telnet | 23 | SSH | 22 |
| HTTP | 80 | HTTPS | 443 |
| FTP | 20/21 | SFTP | 22 |
SFTP runs inside an SSH session, so it shares port 22 with SSH. It is not FTP with encryption added, and it is a different protocol.
Seeing ports on your own computer
The netstat command lists connections and listening ports on Windows. The -a option shows all connections and listening ports, and -n prints numbers instead of resolving names.
netstat -anTypical output looks like this:
Proto Local Address Foreign Address State
TCP 0.0.0.0:135 0.0.0.0:0 LISTENING
TCP 0.0.0.0:445 0.0.0.0:0 LISTENING
TCP 192.168.1.20:50712 203.0.113.10:443 ESTABLISHED
UDP 0.0.0.0:68 *:*Read each line from left to right.
0.0.0.0:445with stateLISTENINGmeans a service accepts connections on port 445 on every local address.- The
ESTABLISHEDline is the browser connection from the diagram. The local port 50712 is ephemeral, and the foreign port 443 identifies HTTPS. - UDP lines have no state, because UDP has no connection to track.
To learn which program owns a port, add -o to show the process ID, then look the ID up. Adding -b shows the program name directly, but it needs an elevated command prompt.
netstat -ano
tasklist /fi "PID eq 4321"Replace 4321 with a process ID from the netstat output.
Testing whether a port is reachable
ping cannot test a port, because it uses ICMP, which has no ports. To check whether a specific TCP port accepts connections, use PowerShell:
Test-NetConnection example.com -Port 443The result field TcpTestSucceeded : True means the three-way handshake completed. False means something blocked the connection or no service was listening.
Common errors and edge cases
- Port conflict. Two programs cannot listen on the same TCP port at the same address. The second program fails to start with an "address already in use" error. Use
netstat -anoto find the first program. - Service listening, but unreachable. A listening service can still be blocked by the Windows Defender Firewall on the host or by a firewall on the network. The
LISTENINGstate innetstatproves only that the program is waiting. - Wrong protocol. Opening TCP 53 does not open UDP 53. Firewall rules and port forwarding entries name the protocol, and a mismatch is a frequent cause of "the rule exists but nothing works."
- Ports that need both. DNS uses UDP for most queries and TCP for large responses. LDAP and RDP also appear with both protocols in the table.
- Several ports for one protocol. FTP uses port 21 for control and port 20 for data in active mode. NetBIOS uses three ports (137 to 139).
- Legacy and modern file sharing. NetBIOS over TCP/IP (137 to 139) is the older way to share files on Windows. Modern Windows uses SMB directly over TCP port 445.
Why ports matter for later chapters
Ports are the basis of firewall rules, which allow or block traffic by port number and protocol. They are also the basis of port forwarding, which sends outside traffic arriving on one port to a chosen device inside a home or office network. The SOHO router chapter builds on both. The command-line troubleshooting chapter uses netstat again to confirm that a service is listening.
Exercise
A technician runs netstat -an on a workstation and sees the line "TCP 192.168.1.20:51844 203.0.113.10:443 ESTABLISHED". Which port is the destination service, which port is the ephemeral client port, and which protocol is the workstation most likely using?
Show answer
The destination service port is 443, which is HTTPS, so the workstation is most likely browsing a secure website. The ephemeral client port is 51844, a temporary port chosen by the operating system that falls in the dynamic range of 49152 to 65535.
Exercise
A company wants to replace Telnet and unencrypted file transfer with encrypted tools. Which single port number covers both the remote shell replacement and SFTP, and why?
Show answer
Port 22. SSH replaces Telnet (port 23), and SFTP runs inside an SSH session, so both use TCP port 22.