Linux ss Command — Inspecting Network Connections and Socket Statistics¶
The
ss(Socket Statistics) command is a modern Linux utility used to inspect network sockets, active connections, listening ports, Transmission Control Protocol (TCP) states, User Datagram Protocol (UDP) sockets, Unix sockets, and process information. It is part of the iproute2 package and is the recommended replacement for the legacy netstat command. Thesscommand is significantly faster because it reads socket information directly from the Linux kernel instead of parsing multiple files. Every Linux administrator, DevOps engineer, Cloud Architect, Platform Engineer, Site Reliability Engineer (SRE), and Network Engineer should master thesscommand.
Learning Path¶
Course Progress
What You'll Learn¶
After completing this lesson, you'll be able to:
- Understand the
sscommand - View active TCP and UDP connections
- Display listening ports
- Analyze socket states
- Identify processes using network ports
- Troubleshoot Linux networking
- Monitor production servers
Prerequisites¶
Complete:
Basic understanding of:
- TCP/IP
- Ports
- Network Connections
Why Learn the ss Command?¶
Suppose users report:
- Website Not Accessible
- Database Connection Failure
- SSH Not Working
- High Network Usage
- Unknown Open Ports
One of the first commands every Linux engineer executes is:
It immediately answers questions such as:
- Which ports are open?
- Which process owns a port?
- Which TCP connections are active?
- How many clients are connected?
- What TCP states exist?
What is ss?¶
ss stands for:
It displays:
- TCP Connections
- UDP Connections
- Unix Domain Sockets
- Listening Services
- Socket States
- Process Information
Why Replace netstat?¶
Older systems used:
Modern Linux recommends:
Advantages:
- Faster
- More Accurate
- Reads Kernel Data Directly
- Better Performance
- Actively Maintained
Basic Syntax¶
Examples:
Display All Connections¶
Displays:
- TCP
- UDP
- Unix Sockets
Display TCP Connections¶
Example:
Display UDP Connections¶
Display Listening Ports¶
Shows services waiting for incoming connections.
Example:
Display TCP Listening Ports¶
Display UDP Listening Ports¶
Display Listening Ports with Process Names¶
Example:
Display Process Information¶
Shows:
- PID
- Process Name
Associated with each socket.
Display Numeric Addresses¶
Disables Domain Name System (DNS) resolution.
Useful for:
- Faster Output
- Troubleshooting
Combine Options¶
Common example:
Meaning:
| Option | Purpose |
|---|---|
-t | TCP |
-u | UDP |
-n | Numeric Output |
-l | Listening |
-p | Process Information |
Display Established Connections¶
Shows active TCP sessions.
Display Listening State¶
Display Specific Port¶
Example:
Shows only SSH.
Display HTTP Connections¶
Display HTTPS Connections¶
Display SSH Sessions¶
Display Unix Domain Sockets¶
Useful for:
- Docker
- MySQL
- PostgreSQL
- Local Inter-Process Communication (IPC)
TCP States¶
Common TCP states:
- LISTEN
- ESTABLISHED
- SYN-SENT
- SYN-RECV
- FIN-WAIT-1
- FIN-WAIT-2
- CLOSE-WAIT
- LAST-ACK
- TIME-WAIT
- CLOSED
Example:
Displays socket states.
Connection Example¶
Displayed by:
Enterprise Example¶
Production Web Server
Troubleshooting:
Questions answered:
- Is Nginx listening?
- Is port 443 open?
- Is SSH running?
- Which process owns the port?
Cloud Perspective¶
Cloud engineers frequently use:
to verify:
- VM Services
- Load Balancer Health
- Open Ports
- Application Availability
Kubernetes Perspective¶
On Kubernetes worker nodes:
helps inspect:
- kubelet
- kube-proxy
- Container Runtime
- Ingress Controller
- NodePort Services
Useful during cluster troubleshooting.
Linux Perspective¶
Common commands:
Display all listening ports.
Display process names.
Display established TCP sessions.
Display Unix sockets.
Common ss Commands¶
| Command | Purpose |
|---|---|
ss | Display sockets |
ss -t | Display TCP connections |
ss -u | Display UDP connections |
ss -l | Display listening sockets |
ss -tuln | Display listening TCP/UDP ports |
ss -p | Display process information |
ss -x | Display Unix sockets |
ss -tan | Display TCP states |
Hands-on Lab¶
Task 1¶
Display all sockets.
Task 2¶
Display TCP connections.
Task 3¶
Display UDP connections.
Task 4¶
Display listening ports.
Task 5¶
Display process information.
Task 6¶
Display SSH connections.
Task 7¶
Display HTTPS connections.
Task 8¶
Create a troubleshooting checklist using:
ssip addrip routepingtraceroute
Production Troubleshooting¶
Problem:
Check:
↓
Port 443 Listening?
↓
Yes
↓
Check Connections
↓
Many Clients?
↓
Investigate Logs
This workflow quickly confirms whether the application is listening and accepting connections.
Common Mistakes¶
❌ Forgetting sudo when viewing process information.
✅ Use elevated privileges to view owning processes.
❌ Confusing listening sockets with established connections.
✅ Use the correct filters and TCP states.
❌ Assuming every open port is a security issue.
✅ Verify which service owns the port.
❌ Ignoring TCP state information.
✅ Analyse connection states during troubleshooting.
❌ Resolving hostnames unnecessarily.
✅ Use -n for faster output and clearer diagnostics.
Best Practices¶
- Use
ssinstead ofnetstaton modern Linux systems. - Always verify which process owns an open port.
- Use numeric output during troubleshooting.
- Monitor established connections on production systems.
- Regularly audit listening ports.
- Combine
sswithip,tcpdump, andjournalctlfor complete network analysis. - Restrict unnecessary listening services.
Interview Questions¶
Beginner¶
- What is the
sscommand? - How do you display listening ports?
- How do you display TCP connections?
- What does
ss -tulnshow?
Intermediate¶
- Why is
sspreferred overnetstat? - How do you determine which process owns a port?
- Explain common TCP connection states.
- How would you identify all active SSH sessions?
Architect Level¶
- Explain how you would troubleshoot a production web server using
ss. - Design a Linux networking troubleshooting workflow using
ssandip. - How would you identify abnormal network activity using socket statistics?
Summary¶
In this lesson, you learned:
- The
sscommand - TCP Connections
- UDP Connections
- Listening Ports
- Socket States
- Process Information
- Unix Domain Sockets
- Linux Network Troubleshooting
The ss command is one of the most powerful networking tools available on Linux. It provides fast and detailed visibility into active connections, listening services, socket states, and process ownership. Mastering ss enables engineers to troubleshoot connectivity problems, identify open ports, monitor production workloads, and analyse network behaviour efficiently.
Key Takeaways¶
ssis the modern replacement fornetstat.- Use
ss -tto view TCP connections. - Use
ss -uto view UDP connections. - Use
ss -tulnto display listening ports. - Use
sudo ss -tulnpto identify which process owns a port. - Understanding TCP states is essential for network troubleshooting.
ssis a core diagnostic tool for Linux servers, Kubernetes nodes, and cloud infrastructure.
What's Next?¶
In the next lesson, you'll learn about netstat.
You'll explore:
- What
netstatis - Active Connections
- Routing Tables
- Interface Statistics
- Listening Ports
- Process Information
- Legacy Network Diagnostics
By the end of the lesson, you'll understand how netstat works, how it compares with ss, and why it remains useful when working with legacy Linux systems and troubleshooting older environments.