Lesson 3 of 4 Networking Fundamentals

Ports and Protocols

Firewall rules, logs and network analysis all depend on recognising ports and protocols. This lesson explains port ranges, the commonly used ports and protocols, and which protocols are insecure and what replaces them.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe port ranges and sockets.
  • Identify commonly used ports and protocols.
  • Identify insecure protocols and their secure replacements.
  • Interpret listening ports on a host.

Ports and sockets

A port is a 16-bit number (0 to 65,535) that identifies a service or connection endpoint on a host, used by TCP and UDP. A socket is the combination of an IP address, protocol and port, such as 192.0.2.10 TCP 443; a connection is identified by the source and destination sockets. Port numbers are divided into ranges.

RangeNameUse
0 to 1023Well-known (system) portsStandard services such as HTTP and SSH; usually require administrative rights to bind
1024 to 49151Registered portsServices registered with IANA, such as SQL Server and RDP
49152 to 65535Dynamic (ephemeral) portsTemporary client-side ports for outgoing connections

Services can run on non-standard ports, so a port number suggests but does not prove what protocol is in use; next-generation firewalls identify applications by their traffic rather than only their ports.

Commonly used ports and protocols

SSCP candidates are expected to recognise common ports. The following table lists them with their security notes.

PortProtocolPurposeSecurity note
20, 21 TCPFTPFile transfer (data, control)Cleartext; replace with SFTP or FTPS
22 TCPSSH, SFTP, SCPSecure remote shell and file transferSecure; restrict and use keys
23 TCPTelnetRemote terminalCleartext; replace with SSH
25 TCPSMTPMail transfer between serversUse STARTTLS; 587 for client submission
49 TCPTACACS+Device administration AAAEncrypts full payload
53 TCP/UDPDNSName resolutionAbused for tunnelling and amplification; use DNSSEC
67, 68 UDPDHCPAddress assignmentRogue DHCP servers; use DHCP snooping
69 UDPTFTPTrivial file transferNo authentication; restrict tightly
80 TCPHTTPWebCleartext; redirect to HTTPS
88 TCP/UDPKerberosAuthenticationRequires synchronised time
110, 995 TCPPOP3, POP3SMail retrievalUse 995 (TLS)
123 UDPNTPTime synchronisationEssential for logs; abused for amplification
143, 993 TCPIMAP, IMAPSMail retrievalUse 993 (TLS)
161, 162 UDPSNMPDevice monitoring and trapsUse SNMPv3; v1 and v2c use cleartext community strings
389, 636 TCPLDAP, LDAPSDirectory accessUse LDAPS or StartTLS
443 TCPHTTPSSecure webTLS 1.2 or 1.3
445 TCPSMBWindows file sharingNever expose to the internet
514 UDPSyslogLog transferCleartext; use TLS on 6514
1433 TCPMicrosoft SQL ServerDatabaseDo not expose externally
1812, 1813 UDPRADIUSAuthentication and accountingProtect shared secrets
3389 TCPRDPRemote desktopNever expose directly; use VPN or gateway with MFA
Match the pairs

Common ports

Exam skills 6.1.6

Match each protocol with its default port.

Log in to try this activity Interactive activities are free with an account.

Insecure protocols and their replacements

Many older protocols send credentials and data in cleartext, so anyone who can capture the traffic can read them. Practitioners replace them with secure equivalents, as the following comparison summarises.

Remote access
InsecureTelnet (23), rlogin
Secure replacementSSH (22)
WhyEncrypted session and credentials
File transfer
InsecureFTP (21), TFTP (69)
Secure replacementSFTP (22), FTPS (990 or explicit TLS)
WhyEncrypted transfer and authentication
Management and web
InsecureHTTP (80), SNMPv1/v2c (161), LDAP (389)
Secure replacementHTTPS (443), SNMPv3, LDAPS (636)
WhyEncryption and, for SNMPv3, user authentication

Beyond replacing protocols, practitioners close ports that are not needed, restrict administrative protocols such as SSH and RDP to management networks or VPNs, and never expose services such as SMB, RDP and database ports directly to the internet, where they are scanned constantly.

The following diagram assesses each of three inbound firewall rules from the internet.

Reviewing three inbound internet rules. TCP 443 to the web server is expected. TCP 3389 exposes RDP to brute force and exploits and should be replaced by a VPN or remote desktop gateway with MFA. UDP 161 exposes SNMP on the core router, which can leak configuration and, in v1 and v2c, sends community strings in cleartext.
The scenario is illustrative.
Match the pairs

Secure replacements

Exam skills 6.1.6 · 5.3.1

Match each insecure protocol with its secure replacement.

Log in to try this activity Interactive activities are free with an account.

Seeing ports on a host

On Linux, the ss command lists listening sockets and the processes that own them, which helps confirm that only expected services are exposed.

ss -tulpn

Each line shows the protocol (tcp or udp), the local address and port (0.0.0.0 or [::] means all interfaces, 127.0.0.1 means local only) and the owning process. A database listening on all interfaces when it should listen only locally is a common finding. The lab for the network security appliances module uses this command.

Worked example

Reviewing a firewall

A review of an internet-facing firewall finds inbound rules allowing TCP 443 to the web server, TCP 3389 to a file server and UDP 161 to the core router. Which rules are problems?

TCP 443 to the web server is expected. TCP 3389 exposes RDP to the internet, a major target for brute force and exploits; remote administration should go through a VPN or remote desktop gateway with MFA. UDP 161 exposes SNMP on the router, which can leak configuration and, with v1/v2c, uses cleartext community strings; management should be restricted to an internal management network. Both rules should be removed.

Worked example

Identifying cleartext traffic

A packet capture on the server network shows administrators logging in to switches over TCP 23 and a backup job sending files over TCP 21. What should be recommended?

Port 23 is Telnet and 21 is FTP, both cleartext, so the capture reveals switch passwords and backup contents. Replace Telnet with SSH on the switches (and disable Telnet), and move the backup to SFTP or another encrypted transfer. Rotate the exposed switch credentials.

Check yourself

Which port and protocol should replace SNMPv2c on port 161 for secure monitoring?

Show answer

SNMPv3 on the same port, which adds user authentication and encryption.

Exam Tips

Remember for the exam

  • Well-known ports are 0 to 1023; dynamic ports are 49152 to 65535.
  • Replace Telnet with SSH, FTP with SFTP or FTPS, SNMPv1/v2c with SNMPv3.
  • Never expose RDP, SMB or database ports directly to the internet.