Beginner · Networking for security · topic 8 of 43 · 30 min
Ports and protocols
Explanation
Why ports matter
One computer runs many network programs at once: a web server, an SSH server, a database. The IP address gets data to the right computer; the port number gets it to the right program. An open port is a door into the machine. Every open door that is not needed is extra risk, which is called attack surface.
Port ranges
- 0–1023: well-known ports, for common services. On Linux only admin (root) programs can listen on them by default.
- 1024–49151: registered ports, used by many applications and databases.
- 49152–65535: dynamic or ephemeral ports. Your computer picks one of these as the source port each time it opens a connection.
Ports every analyst should know
| Port | Protocol | Service | Security note |
|---|---|---|---|
| 20, 21 | TCP | FTP (file transfer) | Sends passwords in clear text; use SFTP instead |
| 22 | TCP | SSH (secure remote shell), SFTP | Often brute-forced; use keys and limit who can reach it |
| 23 | TCP | Telnet | Clear text; should almost never be open |
| 25 | TCP | SMTP (mail between servers) | 587 is used for sending mail from apps and clients |
| 53 | UDP and TCP | DNS | Watch for strange volumes (tunnelling) |
| 67, 68 | UDP | DHCP (hands out IP addresses) | A fake DHCP server can redirect traffic |
| 80 | TCP | HTTP | Not encrypted; redirect to 443 |
| 123 | UDP | NTP (time sync) | Correct time is vital for logs |
| 143, 993 | TCP | IMAP, IMAP over TLS | Use 993 |
| 389, 636 | TCP | LDAP, LDAP over TLS | Directory lookups (Active Directory) |
| 443 | TCP (and UDP for HTTP/3) | HTTPS | Most normal web traffic |
| 445 | TCP | SMB (Windows file sharing) | Never expose to the internet; used by WannaCry in 2017 |
| 3306 | TCP | MySQL | Databases should not face the internet |
| 3389 | TCP | RDP (Windows Remote Desktop) | A top target for ransomware gangs; put it behind a VPN |
| 5432 | TCP | PostgreSQL | Databases should not face the internet |
Seeing which ports are open on your own machine
$ sudo ss -tulpn
Netid State Local Address:Port Process
udp UNCONN 127.0.0.53%lo:53 users:(("systemd-resolve",pid=612))
tcp LISTEN 0.0.0.0:22 users:(("sshd",pid=901))
tcp LISTEN 127.0.0.1:3306 users:(("mysqld",pid=1144))
tcp LISTEN 0.0.0.0:80 users:(("apache2",pid=1210))PS> Get-NetTCPConnection -State Listen | Select-Object LocalAddress, LocalPort, OwningProcess | Sort-Object LocalPort
LocalAddress LocalPort OwningProcess
------------ --------- -------------
0.0.0.0 135 1032
0.0.0.0 445 4
0.0.0.0 3389 1180Scanning your own lab
Nmap is a free tool that checks which ports are open on a machine. Defenders use it to find forgotten services before attackers do. Use it only on your own lab machines or with written permission.
$ nmap -sV 192.168.56.101
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 9.6p1 Ubuntu
80/tcp open http Apache httpd 2.4.58
3306/tcp open mysql MySQL 8.0.39Common mistakes
- Believing a port number proves the service. Anything can run on any port; malware often uses 443 or 80 to blend in.
- Leaving RDP (3389) or SMB (445) open to the internet. Put remote access behind a VPN with MFA.
- Forgetting UDP. Some scans and firewalls only look at TCP.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Ports and protocols · 1/7
The IP address finds the computer. The port number finds the program on it.
Prefer a video by a teacher? Find free videos on “common network ports every security analyst should know” on YouTube ↗
In real life: The forgotten RDP port
A small logistics company in Gujarat opened Remote Desktop (port 3389) to the internet so the owner could work from home. Within days, the firewall logged thousands of password guesses from many countries. A weak admin password was eventually guessed and ransomware was installed. The fix after recovery: close 3389 to the internet, use a VPN with MFA, and set account lockout. This pattern is one of the most common ransomware entry points worldwide.
Practice (0/3 done)
Complete the PORTS dict so that service(port) returns the service name for these ports: 22 "SSH", 53 "DNS", 80 "HTTP", 443 "HTTPS", 445 "SMB", 3389 "RDP". For any other port return "unknown".
An internet-facing server should not expose risky services. Write risky_exposed(open_ports) that returns a sorted list of the ports in open_ports that are in RISKY. Also return an empty list when nothing risky is open.
ss -tulpn shows mysqld listening on 127.0.0.1:3306. What does that mean?
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- DNS: the internet's phone bookNetworking for security · same module
- Ports, services and what scanning doesEthical Hacking and Penetration Testing (legal labs) · Scanning with nmap
- Clients, servers, IP addresses and URLsBackend Development · How the web and backends work
- nmap scan typesEthical Hacking and Penetration Testing (legal labs) · Scanning with nmap
- TCP, UDP and port numbersComputer Networking (CCNA level) · How networks work
- firewalld: zones, services and portsLinux and Red Hat (RHCSA to RHCE) · Software and networking
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
Which port does HTTPS use by default?
Answer: 443
HTTPS uses TCP 443 (and UDP 443 for HTTP/3).
Port 3389 is…
Answer: RDP (Remote Desktop)
3389 is Windows Remote Desktop, a common ransomware entry point when exposed.
Why is Telnet (port 23) dangerous?
Answer: It sends everything, including passwords, in clear text
Telnet has no encryption. SSH replaced it.
Which port range does your computer usually pick its source port from?
Answer: 49152–65535
Clients use dynamic (ephemeral) ports, 49152–65535 in the IANA range.
Traffic to a server on port 443 is…
Answer: Usually HTTPS, but any program can use that port
Port numbers are conventions. Malware often uses 443 to blend in with normal traffic.
An "open" port means…Related
Answer: A service is listening there
Open means a service is listening and accepting connections.
Which port does HTTPS use by default?Related
Answer: 443
HTTP uses port 80 and HTTPS uses port 443 when no port is written in the URL.
-Pn tells nmap to…Related
Answer: Skip host discovery and treat the host as up
-Pn is useful when a host ignores pings but is actually up.
From nmap scan types
Which port does SSH use?Related
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 2 more topics in “Networking for security” before its exam: DNS: the internet's phone book, HTTP, HTTPS and TLS.
- Module 2 exam: Networking for security · 12 questions · 20 min, without help. 5 topics of this module still to finish first.
- Then the next module, Systems and cryptography. 43 topics left in the course before the final exam.