Linux ss command
ss is a Linux command for viewing socket statistics. It is similar to netstat but faster and provides more detailed information about network connection states.
ss stands for Socket Statistics and is used to display and analyze the system's network connection status.
ss can display detailed information about TCP, UDP, and UNIX sockets and supports rich filtering features for debugging networks, monitoring network connections, and more.
Syntax format
ss [options]
- options: optional parameters used to specify filter conditions or display modes.
Description of the options parameter:
-a, --all: display all sockets, including listening and non-listening ones.-t, --tcp: display only TCP sockets.-u, --udp: display only UDP sockets.-l, --listening: display only sockets in the listening state.-p, --processes: display process information associated with sockets.-n, --numeric: display addresses in numeric form instead of resolving them to hostnames.-r, --resolve: resolve hostnames to IP addresses.-s, --summary: display summary information about sockets.-4: display only IPv4 sockets.-6: display only IPv6 sockets.-i, --info: display detailed internal information.-o, --options: display TCP timer information.-K, --kill: kill a specified socket by ID.-f, --family=FAMILY: specify the protocol family (such asinet,inet6,unix,link).-m, --memory: display the memory used by each socket.-H, --no-header: do not display the header line.-v, --verbose: display verbose output.
Common usage
1. View all socket connections
ss -a
Display detailed information about all sockets in the system, including listening and non-listening connections.
** 2. View TCP connections**
ss -t
Display only the TCP connections of the current system.
** 3. View UDP connections**
ss -u
Display only the UDP connections of the current system.
** 4. View listening sockets**
ss -l
Display only sockets that are listening, excluding established connections.
** 5. Display process information associated with sockets**
ss -p
Display all process information related to network connections.
** 6. Display a summary of network connections**
ss -s
Display a summary of network connections, including the total number of sockets, TCP/UDP connection counts, and more.
** 7. Display IPv4 sockets**
ss -4
Display only IPv4 sockets.
** 8. Display IPv6 sockets**
ss -6
Display only IPv6 sockets.
** 9. View detailed TCP socket states and timer information**
ss -o
Display TCP socket timer information, useful for analyzing issues such as connection timeouts and TCP retransmissions.
Example
1. View all TCP connections and show processes
ss -t -a -p
Display all TCP connections along with the associated process information.
** 2. View listening TCP ports**
ss -t -l
This command displays only ports listening under the TCP protocol, useful for troubleshooting server port listening issues.
** 3. View all UDP connections**
ss -u -a
Display all UDP connection information in the system.
** 4. View connections on a specified port**
ss -t '( dport = :80 or sport = :80 )'
This command displays TCP connections related to port 80, useful for checking the network connections of a web service.
** 5. View memory usage of each socket**
ss -m
Display the memory used by each network connection, suitable for analyzing the memory footprint of network connections.
** 6. View IPv6 network connections**
ss -6 -t -a
Display all IPv6 TCP network connections.
** 7. Simple socket statistics summary**
ss -s
This command displays an overview of the system's network connections, including the number of TCP and UDP sockets and their states.
Linux Command Reference