Use the ss Command in Linux to check the socket/network connection
Ss is part of the iproute2 package (a tool for controlling TCP/IP networks and traffic ). Iproute2 is designed to replace the standard Unix network tool set (usually called "net-tools") that was previously used to configure network interfaces, route tables, and manage ARP tables "). The ss tool is used to export socket statistics. It displays information similar to netstat and more TCP and status information. Because it gets information directly from the kernel space, it will be faster. Ss operations are similar to netstat, so it can easily replace netstat.
Usage and common options
Ss is similar to netstat. By default, it displays the list of open non-listener TCP sockets that have established connections. You can use the following options to filter the output:
- -N-Do not try to parse the service name.
- -R-try to parse the address/port number.
- -A-display all sockets.
- -L-display the listening socket.
- -P-the process that uses the socket is displayed.
- -S-print statistics
- -T-only display TCP sockets.
- -U-only UDP socket is displayed.
- -D-only display DCCP socket
- -W-only displays RAW sockets.
- -X-only display Unix domain sockets
- -F FAMILY-displays the type of the FAMILY socket. Currently, the following families are supported: unix, inet, inet6, link, and netlink.
- -A query-specifies the list of sockets to be listed, which are separated by commas. The following identifiers can be identified: all, inet, tcp, udp, raw, unix, packet, netlink, and unix.Dgram, unixStream, packetRaw, packetDgram.
- -O STATUS-list sockets in the specified STATUS
Ss Command example
1. display all TCP ports and processes using them:
- # Ss-tnap
2. You can use the-4 flag to display IPv4 links and the-6 flag to display IPv6 links. For example:
- # Ss-tnap6
3. As with the above behavior, you only need to replace t with u to display all open UDP ports.
- # Ss-unap
4. You can use the-s flag to print various useful statistics:
- # Ss-s
5. You can use the-o flag to check all links in different States, such as displaying all established connections.
- # Ss-tn-o state established-p
This article permanently updates the link address: