In Unix-like systems, ss (Socket Statistics) is a command used to display the network statistics. It is simpler and faster than the now deprecated netstat command.
The ss command is used with some other commands such as the IP command to get useful network information and troubleshoot the network issues.
In this article, I will discuss the usage of the ss command in Linux along with some examples.
Syntax of ss command
The basic syntax of the Linux ss command is given below.
ss [option] [filter]
Where you can find a detailed list of options that can be used with the ss command on its man page or you can display it by using the given command in your terminal.
Using the ss command in Linux
The examples of using the ss command in Linux are given below.
Display the list of all connections
If you run the ss command without any parameters, it will display the list of all connections.
Where different columns in the output show the given information.
- Netid – It represents the type of sockets some of these are TCP, UDP, u_seq(Unix sequence), and u_str(Unix stream)
- State – It shows the state of the socket i.e. ESTAB (established), UNCONN (Unconnected), LISTEN (listening)
- Recv-Q – Number of received packets in the queue
- Send-Q – Represents the number of sent packets in the queue
- Local address:port -Address of local machine and port
- Peer address:port – Address of remote machine and port
Display all the listening and non-listening ports
The following command will display all the listening and non-listening ports on a system –
Display listening sockets only
The given command will display the list of all listening sockets only.
Display all the TCP connections
You can display the list of all TCP connections by using –
OR use the given command if you want to display all the listening TCP connections –
Display the list of UDP connections
To display the list of all the UDP connections use –
OR if you want to display the list of all listening UDP connections then use –
Display list of raw sockets
A raw socket is used to receive raw packets. You can use the following command to display all raw sockets on a system.
Display summary statistics
To display the summary statistics use –
The ss command allows advanced filtering of results examples of which are given below.
Given example shows the filtering based on the connection’s state –
ss -t state listening
This will display all the listening TCP connections-
Another way is to filter by port number for example –
ss dst :50
The above command will filter results by port number 50.
To get more information on how to use the ss command you can refer to its manual page.
So here you have learned how to use the ss command in Linux. Now if you have a query then write us in the comments below.