How to use ss command in Linux?

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]

OR

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.

ss --help

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.

ss

ss

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 –

ss -a

ss -a

Display listening sockets only

The given command will display the list of all listening sockets only.

ss -l

ss -l

Display all the TCP connections 

You can display the list of all TCP connections by using –

ss -at

ss -au

OR use the given command if you want to display all the listening TCP connections –

ss -lt

listening tcp connections

Display the list of UDP connections 

To display the list of all the UDP connections use –

ss -au

ss -au

OR if you want to display the list of all listening UDP connections then use –

ss -lu

ss -ul

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.

ss -w

OR

ss --raw

ss -w

Display summary statistics

To display the summary statistics use –

ss -s

summary statistics

Filter connections

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-

state based filtering

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.

man ss

Conclusion

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.

Leave a Comment