ss command in linux (original) (raw)

Last Updated : 5 May, 2026

The ss command (Socket Statistics) is an important Linux utility used to display detailed information about network sockets. It helps analyze network connections, monitor open ports and troubleshoot connectivity issues efficiently. The command provides details about TCP, UDP and other socket types, including their states and associated processes. Due to its speed and efficiency, it is widely used as a modern replacement for netstat.

Example: List All Sockets

The ss command without any options displays a list of all sockets along with their connection details.

**Command:

ss

**Output:

ss

Syntax

ss [options]

Options Available in the `ss` command Linux

Options Description
-t Display TCP sockets
-u Display UDP sockets
-l Display listening sockets
-a Display all sockets (listening and non-listening)
-e Display detailed information (including users)
-i Display internal information
-n Show numerical addresses instead of resolving
-r Display the routing table
-s Display summary statistics
-4 Display only IPv4 sockets
-6 Display only IPv6 sockets
-o Show timers
-p Show process information
-P Show process statistics
--timewait Display TIME-WAIT sockets
--listening Display listening sockets
--all Display all sockets (listening and non-listening)
--numeric Show numerical addresses instead of resolving
--extended Display extended socket information
--resolve Resolve hostnames
--processes Display process information
--processes-raw Display process information in raw format
--summary Display summary statistics

1. -t: Display TCP Sockets

Shows only TCP (Transmission Control Protocol) sockets, which are connection-oriented and ensure reliable data transfer. This is particularly useful for monitoring web servers, SSH sessions or other services that require a stable connection.

**Command:

ss -t

**Output:

ss-t

2. -u: Display UDP Sockets

Displays only UDP (User Datagram Protocol) sockets, which are connectionless and used for applications like DNS, streaming, or VoIP. Useful for identifying open UDP ports, monitoring traffic patterns or troubleshooting packet loss in services that don’t require a connection handshake.

**Command:

ss -u

**Output:

ss-u

3. -l: Display Listening Sockets

Shows sockets that are actively listening for incoming connections. Helps you identify which services or applications are available on your system and which ports they are using.

**Command:

ss -l

**Output:

ss-lss-l-2

4. -a: Display All Sockets

Displays both listening and non-listening sockets, giving a complete view of all network connections. Useful when you need an overall picture of network activity, including established sessions and passive listening ports. It can help diagnose network congestion or unexpected connections.

**Command:

ss -a

**Output:

ss-a

5. -n: Show Numerical Output

Displays IP addresses and port numbers numerically without resolving hostnames. This speeds up the command output, avoids DNS lookup delays and is useful for quick scripting or when monitoring high-traffic servers. Also makes it easier to match sockets to firewall rules or IP-based configurations.

**Command:

ss -n

**Output:

ss-nss-n-2

6. -e: Extended Information

Displays additional details about each socket, including user ID, inode and other internal flags. Useful for auditing which users or processes own specific connections and for diagnosing security or permission issues.

**Command:

ss -e

**Output:

ss-e

7. -i: Internal Information

Shows internal TCP information, such as retransmissions, congestion window size and timer data. Helpful for debugging TCP performance issues, slow connections or packet loss.

**Command:

ss -i

**Output:

ss-i

8. -p: Show Process Information

Displays the process name and PID associated with each socket. Useful for identifying which applications are using network connections, aiding in monitoring or troubleshooting.

**Command:

ss -p

**Output:

State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
ESTAB 0 0 192.168.1.10:22 192.168.1.5:53412 sshd(pid=1023)
LISTEN 0 128 0.0.0.0:80 0.0.0.0:* nginx(pid=2045)

9. -s: Summary Statistics

Provides a concise summary of all socket types, including counts of TCP, UDP and RAW sockets along with their states. Helps quickly assess the network load or detect abnormal connection patterns.

**Command:

ss -s

**Output:

Total: 12 (kernel 0)
TCP: 5 (estab 3, closed 0, orphaned 0, timewait 1)
UDP: 4
RAW: 3

10. -r: Display Routing Table

Shows the kernel routing table, including destination, gateway and interface information. Useful for verifying network routes, diagnosing connectivity issues and checking default gateways.

**Command:

ss -r

**Output:

Destination Gateway Genmask Flags Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG eth0
192.168.1.0 0.0.0.0 255.255.255.0 U eth0

Advanced Filtering and Display Options:

The 'ss' command offers more advanced options for filtering and customizing the displayed socket information.

1. Filter by Port

To display sockets for a specific source port (e.g., port 80)

**Command:

ss sport = :80

2. Display IPv6 Sockets

To include IPv6 sockets in your view

**Command:

ss -6

3. Display Summary Statistics

For a quick overview of network connections and their states

**Command:

ss -s

Real-World Examples

Example 1: Display TCP Connections to Port 22 (SSH)

This command shows all TCP connections with a source port of 22, typically used for SSH. It helps administrators identify active SSH sessions and monitor secure access to the system.

**Command:

ss -t sport = :22

Example 2: Show UDP Listening Ports

Lists all UDP sockets in the listening state, which is useful for checking open UDP services like DNS or NTP.

**Command:

ss -ul

Example 3: Display Summary Statistics for TCP and UDP

Provides a summarized overview of TCP and UDP socket types, showing counts for established, listening or closed connections. This is useful for quickly assessing network load or spotting unusual traffic patterns.

**Command:

ss -s -t -u

Efficiency of ss Compared to netstat

The ss command is significantly faster and more efficient than the traditional netstat, making it ideal for modern Linux systems, especially those with a large number of connections.