Sub topic 4
Ports and Well-Known Port Numbers
This chapter assumes you know the difference between TCP and UDP, can read an IPv4 address, and have used the Windows command prompt. It covers what a port is, how port numbers are grouped, which ones the A+ Core 1 exam expects you to know, and the errors that cause most mistakes.
What a Port Is
An IP address identifies a device. A port number identifies a specific service or conversation on that device. It is a 16-bit number, so the range is 0 to 65535. A socket is the combination of an IP address, a port and a protocol, such as 192.168.1.20:443 over TCP.
A web server, a mail server and a file server can all run on one computer with one IP address. The port number tells the operating system which program should receive each incoming packet.
Port Ranges
| Range | Name | Use |
|---|---|---|
| 0-1023 | Well-known ports | Standard services, assigned by IANA |
| 1024-49151 | Registered ports | Vendor applications |
| 49152-65535 | Dynamic (ephemeral) ports | Temporary client-side ports |
When your browser connects to a web server, it sends traffic to destination port 443. Your computer picks a random ephemeral port as the source port, so replies return to the right program.
Ports to Memorize
| 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 | RDP |
Group them to remember them. Mail uses 25, 110 and 143. Insecure remote access is 23 and the secure replacement is 22. Web traffic is 80 and 443.
Viewing Ports on Your Computer
The netstat command lists active connections and listening ports.
netstat -anA line showing 0.0.0.0:3389 in the LISTENING state means the computer is accepting Remote Desktop connections on every interface. Lines with high port numbers on the local side are usually outgoing connections using ephemeral ports.
Common Errors
- Mixing up the secure and insecure pairs. HTTP is 80 and HTTPS is 443. Telnet is 23 and SSH is 22.
- Forgetting that DNS uses both protocols. Ordinary lookups use UDP 53. TCP 53 is used for larger responses and zone transfers.
- Swapping the DHCP ports. The server listens on 67 and the client uses 68.
- Treating a port as a security control. Changing a service to a nonstandard port does not make it secure. A firewall rule that allows or blocks the port does the real work.
- Blocking a port on one side only. A firewall must allow the destination port on the server and the returning traffic on the client's ephemeral port. Most stateful firewalls handle the return traffic automatically.
Exercise
A technician must allow remote desktop access to a Windows computer through a firewall, and must also block the unencrypted remote shell protocol. Which port should be allowed and which should be blocked?
Show answer
Allow TCP 3389 for RDP. Block TCP 23, which is Telnet. Telnet sends data, including passwords, in clear text. SSH on port 22 is the encrypted alternative.
Exercise
A browser connects to https://example.com. What is the destination port, and what kind of port does the browser use as its source port?
Show answer
The destination port is TCP 443. The source port is a dynamic (ephemeral) port in the range 49152-65535, chosen by the operating system for that connection.