ss (Socket Statistics) — Viewing Network Connections in Linux¶
The ss (Socket Statistics) command is the modern Linux utility for displaying network sockets, active connections, listening ports, and protocol statistics. It is significantly faster and more powerful than the legacy
netstatcommand and is the preferred tool for network diagnostics on modern Linux systems. Every Linux administrator, DevOps engineer, Cloud Architect, Network Engineer, and Site Reliability Engineer (SRE) should be proficient withss.
Learning Path¶
Course Progress
What You'll Learn¶
After completing this lesson, you'll be able to:
- Understand network sockets
- View active network connections
- Display listening ports
- Filter TCP and UDP connections
- Identify services using ports
- Monitor network activity
- Troubleshoot production networking issues
Prerequisites¶
Complete:
- Module 1 – Linux Fundamentals
- Module 2 – Linux Command Line Essentials
- Module 3 – Text Processing
- Module 4 – File Management
- Module 5 – Users and Groups
- Module 6 – Process Management
- Module 7 – Package Management
- Module 8 Lessons 1–6
Why Learn ss?¶
Imagine:
- A web server isn't accepting connections.
- SSH suddenly stops working.
- A database port appears closed.
- An application is listening on the wrong port.
One of the first commands an administrator uses is:
It quickly shows:
- Active connections
- Listening ports
- Socket states
- Associated processes
What is a Socket?¶
A socket is a communication endpoint identified by:
Example:
Applications communicate through sockets.
What is ss?¶
ss stands for:
It displays:
- TCP connections
- UDP sockets
- UNIX domain sockets
- Listening services
- Connection states
- Network statistics
Basic ss Command¶
Display all sockets.
Example:
Display Listening Ports¶
Shows services waiting for incoming connections.
Display TCP Connections¶
Display UDP Connections¶
Display Listening TCP Ports¶
Display Listening UDP Ports¶
Display All Listening Ports¶
Options:
| Option | Meaning |
|---|---|
-t | TCP |
-u | UDP |
-l | Listening sockets |
-n | Show numeric addresses (don't resolve hostnames or service names) |
Example:
Show Processes Using Ports¶
Example:
Displays:
- Process name
- Process ID (PID)
- Listening port
Filter by Port¶
View connections on port 22.
View Established Connections¶
Displays active TCP sessions.
View Connection Statistics¶
Example:
Useful for obtaining a quick summary of socket usage.
Display UNIX Domain Sockets¶
UNIX sockets are commonly used for communication between processes on the same machine.
Common Socket States¶
| State | Description |
|---|---|
| LISTEN | Waiting for incoming connections |
| ESTAB | Connection established |
| TIME-WAIT | Waiting before closing completely |
| CLOSE-WAIT | Waiting for application to close |
| SYN-SENT | Connection request sent |
| SYN-RECV | Connection request received |
Understanding these states helps diagnose connection issues.
Common Commands¶
Display all sockets.
Display listening ports.
Display listening TCP and UDP ports.
Show processes.
Connection summary.
Real Production Examples¶
Check SSH.
Verify NGINX.
Verify HTTPS.
Check PostgreSQL.
Verify MySQL.
Production Perspective¶
ss is widely used for:
- Linux servers
- Cloud virtual machines
- Kubernetes nodes
- Containers
- Database servers
- Load balancers
- API servers
- Security investigations
It is one of the first commands used to verify whether a service is actually listening on the expected port.
Hands-on Lab¶
Task 1¶
Display all sockets.
Task 2¶
Display listening ports.
Task 3¶
Display all listening TCP and UDP ports.
Task 4¶
Show listening services and associated processes.
Task 5¶
Check whether SSH is listening.
Task 6¶
Display established TCP connections.
Task 7¶
Display socket statistics.
Task 8¶
Display UNIX domain sockets.
Command Deep Dive¶
| Command | Purpose | Production Example |
|---|---|---|
ss | Display sockets | Network diagnostics |
ss -l | Show listening sockets | Service verification |
ss -t | Show TCP sockets | TCP analysis |
ss -u | Show UDP sockets | UDP analysis |
ss -tuln | Show listening TCP/UDP ports | Port verification |
ss -tulpn | Show ports with processes | Service identification |
ss -s | Display socket summary | Performance monitoring |
ss -x | Show UNIX sockets | Local IPC troubleshooting |
ss vs netstat¶
| Feature | ss | netstat |
|---|---|---|
| Performance | Faster | Slower |
| Default on Modern Linux | ✅ | ❌ |
| Displays Socket Statistics | ✅ | Limited |
| Shows Listening Ports | ✅ | ✅ |
| Shows Active Connections | ✅ | ✅ |
| Shows Processes | ✅ | ✅ (with options) |
ss is the recommended replacement for netstat on modern Linux systems.
Production Troubleshooting Scenario¶
Scenario
Users report they cannot access a web application.
Investigation:
Check whether NGINX is listening.
No output.
Check the service.
NGINX is stopped.
Start the service.
Verify again.
Output:
The application is now reachable.
Best Practices¶
- Use
ssinstead of the deprecatednetstat. - Verify that services are listening before troubleshooting firewalls.
- Use
-nfor faster output by avoiding DNS resolution. - Use
-pto identify the process associated with a socket. - Monitor connection states during performance troubleshooting.
Common Mistakes¶
❌ Forgetting to use sudo when viewing process information.
✅ Remember to to use sudo when viewing process information.
❌ Assuming a running service is listening on the expected port.
✅ Verify a running service is listening on the expected port instead of assuming it.
❌ Ignoring connection states such as TIME-WAIT and CLOSE-WAIT.
✅ Always review connection states such as TIME-WAIT and CLOSE-WAIT.
❌ Using netstat on systems where ss is available.
✅ Avoid using netstat on systems where ss is available when a safer approach exists.
Interview Questions¶
Beginner¶
- What does
ssstand for? - Which command displays listening TCP and UDP ports?
- What is a socket?
- What does the
-loption do?
Intermediate¶
- What is the purpose of the
-poption? - What is the difference between TCP and UDP sockets?
- How do you display established TCP connections?
- What does the
LISTENstate indicate?
Architect Level¶
- How would you troubleshoot a production service that is not accepting connections?
- Why is
sspreferred overnetstat? - How would you identify which process is using a specific network port?
Summary¶
In this lesson, you learned:
- Network sockets
- The
sscommand - Listening ports
- TCP and UDP sockets
- Connection states
- Process identification
- Socket statistics
- Production troubleshooting
The ss command is the modern standard for inspecting network sockets on Linux. It provides fast, detailed information about active connections, listening services, and socket states, making it an essential tool for diagnosing networking and application issues.
Key Takeaways¶
ssis the preferred replacement fornetstat.- Use
ss -tulnto view listening TCP and UDP ports. - Use
ss -tulpnto identify which process owns a listening port. - Socket states provide valuable troubleshooting information.
- Always verify that a service is listening before investigating network connectivity issues.
ssis an essential tool for production Linux administration.
What's Next?¶
netstat — Viewing Network Statistics and Connections in Linux
You'll explore:
- Legacy network statistics
- Viewing network connections
- Routing tables
- Interface statistics
- Differences between
netstatandss - When
netstatis still useful - Production troubleshooting techniques
Although ss is the preferred tool today, understanding netstat remains valuable because it is still encountered in legacy Linux systems and documentation.