Ports and protocols: TCP, UDP, common services, and what a listening port tells you
How TCP and UDP ports identify services, the ports worth recognizing on sight, and how to list what your own machine is listening on and why each listener exists.
Diagram
From a listening socket to a decision
Step 1 of 4
List
See which programs are listening and on which addresses.
$ sudo ss -tulpn
tcp LISTEN 0 128 0.0.0.0:22 users:(("sshd",pid=812))
tcp LISTEN 0 511 127.0.0.1:5432 users:(("postgres",pid=990))
udp UNCONN 0 0 0.0.0.0:5353 users:(("avahi-daemon",pid=640))The example on the open step is one illustration, or the fix you can paste into an application you own.
What this page is made of
3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.
Listening on all interfaces
- What fails
- A service bound to 0.0.0.0 answers on every network the host is attached to.
- Who is affected
- Anyone who can reach any of those networks.
- What you would notice
- A development database showing 0.0.0.0:5432 in ss output.
- What you change
- Bind to localhost or a specific interface, and firewall the rest.
Cleartext protocols
- What fails
- Telnet, FTP, plain HTTP, and old SNMP send credentials readable on the wire.
- Who is affected
- Users whose passwords cross a network you do not control.
- What you would notice
- Ports 21, 23, or 80 serving logins.
- What you change
- Replace with SSH, SFTP, HTTPS, and SNMPv3.
Management ports
- What fails
- RDP, SSH, WinRM, and database ports are the most attacked services on the internet.
- Who is affected
- The whole host and its credentials.
- What you would notice
- 3389 or 22 open to 0.0.0.0/0 in a cloud security group.
- What you change
- Put management behind a VPN, bastion, or identity-aware proxy.
TCP and UDP
TCP sets up a connection with a three-way handshake and retransmits lost data, which suits web, mail, and SSH. UDP sends datagrams with no handshake, which suits DNS, NTP, streaming, and QUIC. Port numbers from 0 to 1023 are well known; 1024 to 49151 are registered; higher numbers are usually ephemeral client ports.
Ports worth recognizing
You will read these numbers in firewall rules, scans, and captures every day.
- 22 SSH, 3389 RDP, 5985/5986 WinRM
- 53 DNS, 123 NTP, 161 SNMP
- 25/587 SMTP, 993 IMAPS
- 80 HTTP, 443 HTTPS and QUIC over UDP
- 445 SMB, 389/636 LDAP, 88 Kerberos
- 1433 SQL Server, 3306 MySQL, 5432 PostgreSQL, 6379 Redis, 9200 Elasticsearch
The same check on Windows
Get-NetTCPConnection shows listeners with the owning process, which you can join to the process name.
Get-NetTCPConnection -State Listen |
Select LocalAddress, LocalPort, @{n="Process";e={(Get-Process -Id $_.OwningProcess).ProcessName}} |
Sort LocalPortCheck yourself
Recognition and the fix. Nothing here is a procedure.
ss shows 127.0.0.1:6379 for Redis. Who can connect?
Sibling techniques
Pages at the same depth, plus a lab and a glossary card for this one.