SS command is used to get various network/socket connections related information from a Linux system. Previously we had used netstat command to perform the same operations but it has been long deprecated & was replaced with ss command.
SS command is much more faster than netstat & capable of showing much more information than netstat. Those familiar with netstat command need not worry as the options used with ss command are similar to netstat.
In this tutorial, we will learn usage of SS command with the help of SS command examples.
So let’s start,
(Recommended Read: Learn to use Wget command with 12 examples)
SS command examples
1- Checking all connections
To list out all the connections on a system, we can use ‘a’ option with ss command,
$ ss -a
This will produce all tcp, udp & unix connections from the system.
2- Checking all tcp or udp or unix socket connections
To list only the tcp connections our system, use ‘t’ options with ss,
$ ss -at
Similarly to list out only the udp connections on our system, we can use ‘u’ option with ss,
$ ss -au
To only list out Unix socket connections, we can use ‘x’ options,
$ ss -ax
3- List process id/Process Name with
To get list of all connections along with PID or process name, we can use ‘p’ option & it can be used in combination with any other ss option,
$ ss -ap
4- List only port number & not the name
To speed up our output, we can use ‘n’ option as it will perform any reverse lookup & produce output with only numbers. Since no lookup is performed, our output will much faster.
$ ss -an
5- Print only listening ports
To print only the listening ports , we will use ‘l’ option with ss. It will not be used with ‘a’ as it prints all ports,
$ ss -l
6- Print network stats
To print network statistics of each protocol like packet received or transmitted, we can use ‘s’ options with ss,
$ ss -s
7- Print interfaces stats
To display only the statistics on network interfaces, use ‘I’ option,
$ ss -i
8- Display the network routing information
To print the network routing information, use ‘r’ option,
$ ss -r
9- Filtering a single port
To filter a single port connections, we can combine ‘grep’ command with ss,
$ ss -anp | grep 3306
10- Count number of connections
To count the number of connections from port, we can further add ‘wc’ command with ss & grep command,
$ ss -anp | grep 3306 | wc -l
This will print the number of connections for the port mysql port i.e. 3306.
With this we end our tutorial on how to use SS command with the help of some examples. Please let know if you want us to add some more ss command examples or have any other suggestion or query using the comment box below.