Auditing active network connections, identifying rogue daemon listeners, and diagnosing port conflicts are fundamental responsibilities for Linux system administrators. For decades, engineers relied on the legacy netstat command from the net-tools suite. However, on modern high-throughput servers managing thousands of concurrent socket descriptors, netstat is slow and inefficient because it parses raw entries sequentially from the /proc/net/ virtual filesystem.
The ss (Socket Statistics) command, part of the standard Linux iproute2 package, is the modern, high-performance successor to netstat. By interfacing directly with the Linux kernel’s sock_diag netlink subsystem, ss dumps socket state information in a fraction of the time, providing real-time visibility into TCP, UDP, raw, and Unix domain sockets.
Basic ss Command Execution
Running ss without arguments outputs a list of all established, non-listening network sockets across the system:
ss
To view basic summary statistics describing current socket allocation across your operating system:
ss -s
The summary displays total allocated sockets, broken down by TCP, UDP, RAW, and IP version (IPv4 vs IPv6), providing an instant health check on connection saturation.
Displaying All Listening Ports with Process Information
The most common diagnostic requirement is discovering which network services are listening on local ports and which processes own them. You can achieve this using the classic parameter combination -tulpn:
sudo ss -tulpn
Understanding each flag in this command:
-t: Restricts display to TCP sockets.-u: Restricts display to UDP sockets.-l: Displays only listening sockets (suppressing ephemeral client connections).-p: Shows the process name and Process ID (PID) owning each socket (requires root/sudo).-n: Displays numeric port numbers (e.g.,80,443,22) rather than attempting reverse DNS service resolution, speeding up command execution.
Output example:
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=842,fd=3))
tcp LISTEN 0 511 127.0.0.1:8080 0.0.0.0:* users:(("node",pid=1420,fd=18))
tcp LISTEN 0 511 0.0.0.0:443 0.0.0.0:* users:(("nginx",pid=1102,fd=6))
Filtering Sockets by Port or Protocol
Rather than piping output through grep, ss features built-in state and port filtering logic:
# Filter for listening sockets on port 443
ss -tl '( sport = :443 )'
# Filter for active connections to a remote destination port 80 or 443
ss -t '( dport = :http or dport = :https )'
# Filter by specific IP subnet
ss -t dst 192.168.1.0/24
Filtering by TCP Socket State
You can isolate sockets residing in specific phases of the TCP lifecycle:
# Display established TCP connections
ss -t state established
# Display connections lingering in TIME-WAIT state
ss -t state time-wait
# Display connections in SYN-SENT or SYN-RECV (useful for diagnosing SYN flood attacks)
ss -t state syn-recv
Common ss Command Flags Reference
| Flag | Description | Typical Use Case |
|---|---|---|
-t |
TCP sockets | Filter for web, database, and SSH traffic. |
-u |
UDP sockets | Inspect DNS, DHCP, and streaming services. |
-x |
Unix domain sockets | Audit local inter-process communication (IPC). |
-l |
Listening sockets only | Discover active server daemons. |
-a |
All sockets (listening and established) | Complete connection inventory. |
-p |
Show process and PID | Identify which binary bound the port. |
-e |
Show extended socket memory info | Inspect socket buffer allocations. |
Replacing deprecated netstat with ss gives Linux administrators a faster, more flexible tool for modern network diagnostics and socket auditing.