Why
Ports are how applications, services, and processes communicate - either locally within your server or with other devices on the network. When applications like SSH or Apache run on your server, they listen for requests on specific ports. You want to know exactly which ports are open and what services are using them. Unknown open ports could indicate rogue or potentially dangerous services that need to be investigated.Goals
- Identify all non-localhost ports that are open and listening for connections
- Verify that only expected services are listening on the network
References
Using ss to List Listening Ports
To see all ports listening for traffic:Switch Explanations
| Switch | Description |
|---|---|
-l | Display listening sockets |
-n | Do not try to resolve service names |
-t | Display TCP sockets |
-u | Display UDP sockets |
-p | Show process information |
Understanding the Output
Each line in the output shows:- Netid - Protocol (tcp/udp)
- State - Connection state (LISTEN, UNCONN)
- Local Address:Port - Address and port the service is listening on
*:22- Listening on all IPv4 interfaces on port 22:::22- Listening on all IPv6 interfaces on port 22127.0.0.1:25- Only listening on localhost (loopback)
- Peer Address - Remote connection details
- users - Process name and PID using the port
Services listening only on
127.0.0.1 (localhost) are not accessible from the network and are generally less of a security concern.What to Look For
When reviewing the output:Identify all listening ports
Make a list of all ports that are listening on network interfaces (not just localhost).
Verify expected services
For each listening port, verify:
- You know what service is using it
- You expect that service to be running
- You need that service to be accessible on the network
Common Ports and Services
| Port | Service | Description |
|---|---|---|
| 22 | SSH | Secure Shell remote access |
| 25 | SMTP | Mail server |
| 80 | HTTP | Web server |
| 443 | HTTPS | Secure web server |
| 3306 | MySQL | Database server |
| 5432 | PostgreSQL | Database server |
| 53 | DNS | Domain name service |
Additional ss Commands
Regular Auditing
Taking Action
If you find unexpected services:- Identify the service: Note the process name and PID
- Research: Determine what the service does and why it’s running
- Stop if unneeded:
- Remove if malicious:
- Configure firewall: Ensure your firewall blocks unexpected ports