ss Command in Linux: Display Socket Statistics and Listening Ports
Learn ss command in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.
10 min read
Learn ss command in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.
- What ss Does and When to Use It
- Availability and Installation Across Linux Distributions
- Command Syntax, Arguments, and Exit Status Codes
The ss command in linux is the modern, authoritative utility for inspecting network socket statistics, active TCP/UDP connections, and listening server ports. Distributed as a core component of the iproute2 suite, ss was designed specifically to supersede legacy netstat by eliminating the severe performance bottlenecks associated with reading and parsing raw text files in /proc/net.
The ss command in Linux (socket statistics) inspects active network connections, listening service ports, TCP buffer memory allocations, and Unix domain sockets directly from the Linux kernel. Part of the modern iproute2 package, ss replaced the obsolete netstat utility by using kernel netlink sock_diag interfaces to retrieve connection states in constant time, even on servers handling tens of thousands of concurrent sockets.
On modern Linux systems running high-throughput web proxies, database clusters, or container orchestration platforms, socket counts frequently reach tens or hundreds of thousands. While older tools degraded server responsiveness by acquiring global kernel locks while parsing /proc/net/tcp line by line, ss queries the kernel's dedicated netlink sock_diag subsystem, dumping structured binary socket state tables in sub-millisecond timeframes.
Whether you are investigating connection leaks, verifying that a newly deployed web server is bound to the correct network interface, diagnosing TCP buffer backlogs, or filtering network traffic by IP and port in shell pipelines, ss provides comprehensive diagnostic flags and an expressive filtering grammar.
What ss Does and When to Use It
Under the hood, ss interacts with the Linux kernel through Netlink sockets using the AF_NETLINK address family and the NETLINK_INET_DIAG protocol. When ss executes, it crafts an inet_diag_req_v2 request specifying the desired protocol family (IPv4, IPv6, UNIX), socket states (such as TCP_ESTABLISHED or TCP_LISTEN), and extensions (memory allocation, internal TCP timer info). The kernel's sock_diag module responds with binary inet_diag_msg payloads containing socket telemetry.
This architecture exposes deep kernel transport parameters that legacy tools could never access. By querying socket structures directly (struct sock and struct tcp_sock), ss can surface metrics such as round-trip time (RTT), congestion window size (cwnd), unacknowledged packet counts, retransmission timeouts (rto), and receive/send memory queue limits (Recv-Q / Send-Q) without introducing CPU overhead.
At the operating system level, ss interacts with the Linux kernel networking stack through netlink sockets (AF_NETLINK), raw packet sockets, or standard POSIX resolver APIs. When running ss in cloud instances or Kubernetes worker nodes, combining flags such as -t, -u, -l, -a lets you bypass slow reverse DNS lookups and inspect numeric IPv4/IPv6 addresses and socket states directly.
Availability and Installation Across Linux Distributions
The ss utility is packaged in iproute2 across mainstream Linux distributions. It is pre-installed on standard Ubuntu, Debian, RHEL, Rocky Linux, AlmaLinux, Fedora, and Arch Linux systems, while minimal container images may require manual installation:
Before running administrative tasks or automation scripts, verify whether ss is installed and inspect which binary path and version your shell resolves:
type -a ss
ss --version 2>/dev/null || man -f ss
# Illustrative output (reviewed against documentation)
ss is /usr/bin/ss
ss (iproute2)
# Debian / Ubuntu
sudo apt-get update && sudo apt-get install -y iproute2
# RHEL / Rocky / AlmaLinux / Fedora
sudo dnf install -y iproute
# Arch Linux
sudo pacman -S --noconfirm iproute2
# Alpine Linux
sudo apk add --no-cache iproute2
Command Syntax, Arguments, and Exit Status Codes
ss [OPTIONS] [FILTER]
The ss invocation grammar follows the pattern: ss [OPTIONS] [FILTER]. Options determine the protocol families to inspect (-t for TCP, -u for UDP, -x for UNIX domain sockets, -4 for IPv4, -6 for IPv6), the socket operational state (-l for listening sockets, -a for both listening and non-listening sockets), and display formatting (-n for numeric IP/ports, -p for process names and PIDs).
Following the command options, administrators can supply advanced filter expressions using relational operators. Filters can match IP addresses, CIDR blocks, port names or numbers, and TCP state machine phases: for example, ss -tan '( sport = :443 or dport = :443 )' or ss -t state time-wait. This eliminates the need to pipe output through multiple grep, awk, or sed commands.
0— Successful execution; socket tables were retrieved and formatted without error.1— Operational error, invalid command-line option, or malformed state/port filter expression.2— Unprivileged execution error when attempting to inspect socket memory or process owners without appropriate capabilities.
Important Options and Flags Reference
| Option / Flag | Long Form / Argument | Technical Behavior and Purpose |
|---|---|---|
-t | --tcp | Filters the display to show only TCP (Transmission Control Protocol) sockets. |
-u | --udp | Filters the display to show only UDP (User Datagram Protocol) sockets. |
-l | --listening | Displays only listening sockets (services waiting for incoming connections; omitted by default). |
-a | --all | Displays all sockets, combining both listening servers and established active connections. |
-n | --numeric | Prevents resolving numeric IP addresses and port numbers to hostnames and service names (drastically improves speed). |
-p | --processes | Displays the process name, Process ID (PID), and file descriptor (FD) owning each socket (requires root/sudo). |
-e | --extended | Displays extended socket metadata, including UID, inode number, and socket cookie. |
-i | --info | Shows internal kernel TCP metrics such as RTT, congestion window (cwnd), MSS, and pacing rate. |
-s | --summary | Prints a summary breakdown of total socket counts categorized by protocol family (TCP, UDP, RAW, UNIX). |
In daily Linux administration, the most common and powerful flag combination is -tulpn (TCP, UDP, Listening, Processes, Numeric). Running sudo ss -tulpn immediately lists every daemon actively accepting connections on the system, showing the exact bound IP address, port, and owning daemon PID without waiting on slow reverse DNS lookups.
For performance profiling and incident response, pairing -ti with connection filters allows engineers to diagnose network latency and packet loss at the socket layer. Examining rtt and cwnd metrics reveals whether application slowness is caused by server CPU constraints or network congestion along the WAN path.
When combining short flags on the command line, POSIX and GNU utilities allow clustering boolean flags behind a single hyphen, provided any option taking an argument appears last. In automated shell scripts, using long-form GNU options where portable makes self-documenting code that is easier to audit during peer review.
Practical Basic and Advanced Usage Examples
1. List All Listening TCP and UDP Ports with Process Names
Inspect all listening network services on the server, showing numeric ports and owning process information.
sudo ss -tulpn
# Illustrative output (reviewed against documentation)
Netid State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
udp UNCONN 0 0 0.0.0.0:53 0.0.0.0:* users:(("named",pid=1024,fd=512))
tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=842,fd=3))
tcp LISTEN 0 511 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=1250,fd=6))
tcp LISTEN 0 511 0.0.0.0:443 0.0.0.0:* users:(("nginx",pid=1250,fd=7))
tcp LISTEN 0 70 127.0.0.1:3306 0.0.0.0:* users:(("mariadbd",pid=1100,fd=22))
The output displays all listening services: BIND DNS on port 53, OpenSSH on port 22, Nginx on ports 80 and 443, and MariaDB bound strictly to localhost (127.0.0.1:3306).
2. Display All Active Established TCP Connections
List currently established network connections without showing idle listening daemons.
ss -t -a state established
# Illustrative output (reviewed against documentation)
Recv-Q Send-Q Local Address:Port Peer Address:Port
0 0 192.0.2.10:22 198.51.100.45:52341
0 64 192.0.2.10:443 203.0.113.88:41200
The state filter restricts output to sockets in the TCP ESTABLISHED phase, identifying active SSH administrative sessions and HTTPS web clients.
3. Filter Network Connections by Destination Port
Target specific services—such as HTTPS port 443—using ss's native expression syntax.
ss -tan '( dport = :443 or sport = :443 )'
# Illustrative output (reviewed against documentation)
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 511 0.0.0.0:443 0.0.0.0:*
ESTAB 0 0 192.0.2.10:443 203.0.113.12:49822
TIME-WAIT 0 0 192.0.2.10:443 198.51.100.8:54210
The expression filters traffic where either the local source port or remote destination port is 443, displaying listening, established, and closing sockets.
4. Display Detailed TCP Performance and RTT Metrics
Inspect socket-level round-trip time, window sizing, and congestion algorithms for active connections.
ss -ti dst 198.51.100.45
# Illustrative output (reviewed against documentation)
State Recv-Q Send-Q Local Address:Port Peer Address:Port
ESTAB 0 0 192.0.2.10:22 198.51.100.45:52341
cubic wscale:7,7 rto:240 rtt:22.4/4.1 ato:40 mss:1460 rcvspace:64240 ssthresh:10 cwnd:10
The -i flag outputs kernel TCP internals: cubic congestion algorithm, 22.4ms RTT with 4.1ms variance, 1460-byte MSS, and a congestion window (cwnd) of 10.
5. Display High-Level Socket Summary Statistics
Quickly review aggregate socket resource utilization across all protocols without listing individual connections.
ss -s
# Illustrative output (reviewed against documentation)
Total: 342
TCP: 48 (estab 12, closed 18, orphaned 0, timewait 14)
Transport Total IP IPv6
RAW 0 0 0
UDP 8 5 3
TCP 30 20 10
INET 38 25 13
FRAG 0 0 0
ss -s aggregates system-wide socket counts, showing total open sockets, active established TCP streams, sockets in TIME_WAIT, and UDP endpoints.
6. Inspect Unix Domain Sockets and Process Bindings
List active local inter-process communication (IPC) Unix domain sockets used by services like Docker, systemd, and PHP-FPM.
sudo ss -x -a -p | head -n 8
# Illustrative output (reviewed against documentation)
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
u_str LISTEN 0 4096 /run/systemd/private 12450 * 0 users:(("systemd",pid=1,fd=28))
u_str LISTEN 0 4096 /var/run/docker.sock 18920 * 0 users:(("dockerd",pid=912,fd=4))
u_str LISTEN 0 128 /run/php/php8.2-fpm.sock 22100 * 0 users:(("php-fpm8.2",pid=1450,fd=7))
The -x flag targets AF_UNIX sockets, identifying active local socket filesystem paths, queue sizes, and owning daemon PIDs.
Real-World Workflows, Pipelines, and Shell Automation
High-Concurrency Web Server Socket Exhaustion Diagnosis
During traffic spikes, web servers can become unresponsive due to socket buffer exhaustion or connection buildup in TIME_WAIT or SYN_RECV states. This script diagnoses socket health and flags connection leaks.
#!/usr/bin/env bash
set -euo pipefail
echo "=== 1. Summary of System-Wide Socket Usage ==="
ss -s
echo "=== 2. Connections in TIME_WAIT State (Top 5 Remote IPs) ==="
ss -tan state time-wait | awk '{print $4}' | cut -d: -f1 | sort | uniq -c | sort -rn | head -n 5 || true
echo "=== 3. Sockets with Non-Zero Receive/Send Backlogs ==="
ss -tan '( Recv-Q > 0 or Send-Q > 0 )' state established
echo "=== 4. Checking for SYN Flood / Backlog Saturation ==="
SYN_COUNT=$(ss -tan state syn-recv | wc -l)
echo "Active sockets in SYN_RECV state: ${SYN_COUNT}"
if [ "${SYN_COUNT}" -gt 100 ]; then
echo "WARNING: Possible SYN flood attack or backend queue saturation detected!"
fi
# Illustrative output (reviewed against documentation)
=== 1. Summary of System-Wide Socket Usage ===
Total: 1250
TCP: 1120 (estab 450, closed 50, orphaned 2, timewait 618)
=== 2. Connections in TIME_WAIT State (Top 5 Remote IPs) ===
142 198.51.100.12
98 203.0.113.44
76 198.51.100.89
54 203.0.113.101
32 192.0.2.200
=== 3. Sockets with Non-Zero Receive/Send Backlogs ===
State Recv-Q Send-Q Local Address:Port Peer Address:Port
ESTAB 32000 0 192.0.2.10:80 203.0.113.12:51240
=== 4. Checking for SYN Flood / Backlog Saturation ===
Active sockets in SYN_RECV state: 4
This production diagnostics workflow checks total socket counts, identifies client IPs generating high churn in TIME_WAIT, detects processes unable to drain their Recv-Q buffers, and monitors SYN backlog health.
Automated Listening Port Security Baseline Audit
Audit all listening ports on a production server and compare them against an approved security baseline to immediately detect unauthorized backdoors or newly exposed services.
#!/usr/bin/env bash
set -euo pipefail
BASELINE_FILE="/etc/security/approved_listening_ports.txt"
CURRENT_FILE="/tmp/current_listening_ports.txt"
# Extract listening protocol, local address, and port in sorted format
sudo ss -tuln | awk 'NR>1 {print $1, $5}' | sort -u > "${CURRENT_FILE}"
if [ ! -f "${BASELINE_FILE}" ]; then
echo "Baseline file not found. Creating baseline from current state..."
cp "${CURRENT_FILE}" "${BASELINE_FILE}"
echo "Baseline created at ${BASELINE_FILE}:"
cat "${BASELINE_FILE}"
exit 0
fi
echo "=== Auditing Listening Ports Against Baseline ==="
if diff -u "${BASELINE_FILE}" "${CURRENT_FILE}"; then
echo "SUCCESS: All listening ports conform to approved baseline."
else
echo "SECURITY ALERT: Unauthorized or altered listening ports detected!"
exit 1
fi
# Illustrative output (reviewed against documentation)
=== Auditing Listening Ports Against Baseline ===
--- /etc/security/approved_listening_ports.txt 2026-10-01 10:00:00
+++ /tmp/current_listening_ports.txt 2026-10-22 20:15:00
@@ -2,3 +2,4 @@
tcp 0.0.0.0:22
tcp 0.0.0.0:443
tcp 0.0.0.0:80
+tcp 0.0.0.0:8080
SECURITY ALERT: Unauthorized or altered listening ports detected!
The script dumps listening TCP/UDP endpoints, compares them against an approved baseline with diff, and generates a security alert if an unauthorized port (such as 8080) opens.
Pipelines, Redirection, Quoting, and Shell Expansion
When embedding ss inside shell pipelines (|), conditional chains (&& and ||), or command substitutions ($(...)), the calling shell performs tilde expansion, variable interpolation, and globbing before invoking the binary. Always wrap paths, patterns, and variables in quotes so whitespace and wildcard characters (*, ?) are not expanded prematurely, and use set -euo pipefail in unattended scripts.
Permissions, Security Implications, and Safe Execution
While ss is predominantly a read-only query tool, passing the -K (--kill) option instructs the Linux kernel to forcibly abort and tear down active TCP sockets matching the filter expression. Killing sockets prematurely terminates production user connections and can abort in-flight database transactions.
Running ss as an unprivileged user allows you to view network socket endpoints and connection states, but hides the process name, Process ID (PID), and file descriptor columns (displaying empty users:() blocks). Viewing process ownership requires root privileges or the CAP_NET_ADMIN capability, ensuring unprivileged users cannot infer the execution details of processes owned by other accounts.
In containerized architectures, ss operates within the network namespace of the calling process. When executed inside a Docker or Kubernetes container, ss displays only the sockets isolated within that container's network namespace unless the container is launched with --net=host or executed from the host root namespace via nsenter.
GNU/Linux, BSD, and BusyBox Implementation Differences
The ss utility is an exclusive Linux feature tightly coupled with the Linux kernel's Netlink sock_diag interface. It is not available on BSD systems (FreeBSD, OpenBSD) or macOS. On BSD and macOS systems, administrators rely on netstat, sockstat, or lsof to achieve comparable socket visibility.
Across Linux distributions, ss is pre-installed in the iproute2 package on Debian, Ubuntu, RHEL, Rocky Linux, AlmaLinux, Fedora, Arch Linux, and Alpine Linux. However, minimal BusyBox environments include a simplified netstat applet rather than ss.
Troubleshooting Common Errors and Diagnostics
Process names and PIDs missing from ss output
Root Cause: The ss command was invoked without root/sudo privileges, preventing the tool from inspecting /proc/[pid]/fd socket links owned by other users.
Resolution: Rerun the command with sudo to grant the required permissions to inspect process tables.
sudo ss -tulpn
Filter expression syntax error
Root Cause: Special characters such as parentheses, brackets, or colons in the filter expression were expanded or split by the shell.
Resolution: Always wrap filter expressions in single quotes to prevent premature shell expansion.
ss -tan '( sport = :http or sport = :https )'
Cannot open netlink socket: Protocol not supported
Root Cause: The host kernel lacks the inet_diag or sock_diag kernel module (common in heavily stripped custom microVM kernels).
Resolution: Load the required kernel modules or enable CONFIG_INET_DIAG in the kernel build configuration.
sudo modprobe inet_diag
sudo modprobe tcp_diag
Alternatives, Related Commands, and Related Tutorials
- nslookup Command in Linux: Query DNS Records and Name Servers — Practical syntax, flags, and examples for
nslookup. - How to Check Open Ports in Linux: nmap, netcat, and Bash — Practical syntax, flags, and examples for
nc. - netstat Command in Linux: Network Connections, Routing, and Statistics — Practical syntax, flags, and examples for
netstat. - Netcat (nc) Command in Linux: Port Scanning, Transfers, and Debugging — Practical syntax, flags, and examples for
nc. - 25 Best Linux Commands Every Sysadmin Should Know — Core command-line utilities for daily Linux server administration.
- How to Find a File in Linux from the Command Line — Practical file search patterns across Linux directories.
- Linux Commands Knowledge Hub (#linux-commands) — Browse all Linux command-line tutorials and system administration references.
Authoritative References and Official Documentation

The Linux Command Line, 2nd Edition: A Complete Introduction
Frequently Asked Questions
Quick answers to common questions and configurations
/proc/net, which imposes significant CPU locking overhead on busy servers with tens of thousands of connections.Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
Rajesh Ray
I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides



Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!