Linux ss Command
ss is a command in Linux used to view socket statistics. Its functionality is similar to netstat, but it is faster and provides more detailed network connection status information.
ss is the abbreviation for Socket Statistics, 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 functions for debugging networks, monitoring network connections, and so on.
Syntax Format
ss [options]
- options: Optional parameter, used to specify filter conditions or display mode.
options parameter description:
-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 of 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 the specified socket by ID.-f, --family=FAMILY: Specify the protocol family (e.g.inet,inet6,unix,link)。-m, --memory: Display the memory used by each socket.-H, --no-header: Do not display the header line.-v, --verbose: Display detailed output.
Common Usage
1. View all socket connections
ss -a
Display detailed information of all sockets in the system, including listening and non-listening connections.
2. View TCP connections
ss -t
Display only the current system's TCP connections.
3. View UDP connections
ss -u
Display only the current system's UDP connections.
4. View sockets that are listening
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 summary information of network connections
ss -s
Display summary information of network connections, including the total number of sockets, TCP/UDP connection counts, etc.
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 status and timer information
ss -o
Display the timer information of TCP sockets, suitable for analyzing issues such as connection timeouts and TCP retransmissions.
Examples
1. View all TCP connections and display processes
ss -t -a -p
Display all TCP connections and show the process information associated with the connections.
2. View listening TCP ports
ss -t -l
This command displays only the ports being listened on under the TCP protocol, suitable 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 for a specified port
ss -t '( dport = :80 or sport = :80 )'
This command displays TCP connections related to port 80, suitable 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 usage 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.
Other Extensions
Linux Command Reference