When it comes to accessing socket-related information via the command line in Linux, the first tool that comes to mind is netstat. However, there is another tool that can do this work for you.
It's called ss . In this tutorial, we discuss the basics of this tool with the help of some easy-to-understand examples. But before we do, it is worth mentioning that all cases here have been tested on a Ubuntu 18.04 LTS machine.
Linux ss command
The ss command in linux lets you examine sockets. The following is its syntax:
ss [options] [ FILTER ]
And here's what the tool's man page says about it:
ss used to dump socket statistics. It lets you view information similar to netstat.
It can show more TCP and state information than other tools.
The following are some Q&A styled examples that should give you a better idea of how the ss command works.
. How to use the ss command?
In its very basic form, you can use the ss command by performing ss sans any choice.
The following is the result that the command gave in my case:  How to use ss command "src =" https://www.howtoforge.com/images/command-tutorial/ss-basic- usage.png "/>
You notice that ss shows sockets with established connections in the default output.
The following screenshot shows this command line option in action:
<img height =" 256 "width = "500" alt = "How to make ss suppressed headline?
Suppression of headings can be done using the -H command line option.
makes ss suppress headline "src =" https://www.howtoforge.com/images/command-tutorial/ss-h-option.png "/>
So you can see
Q3. How to do ss shows both listening and non-listening output?
This can be done with the -a command line option.
Note that listening output is omitted by default, so that you use -a makes ss include them in the output.If you want ss to only show listening output, use the -l command line option.
Q4 How to do ss processes using socket?
If you want the ss command to display process information along with the other information it already produces in the output, then use the -p command line option.
] The following screenshot shows the result in my case:
So d u can see that the process information is displayed in the output.
Q5. How to do ss provides summary information?
If you do not want to see the production, the ss command produces by default. Then there is an alternative by which you can ask ss to give a small summary of the information it analyzes.
This summary can be produced with the command-line option -s:
For example The following is the summary in my case:
Total: 1334 (kernel 0)
TCP: 41 (estab 35 , closed 3, orphan 0, sync 0, timeline 3/0), ports 0
Transport Total IP IPv6
* 0 - -
RAW 1 0 1
UDP 7 5 2
TCP 38 37 1
INET 46 42 4
FRAG 0 0 0
Q6. How to do ss shows only IPv4 or IPv6 jacks?
This can be done using options -4 and -6.
If you want ss to show only IPv4 socket, run the following command:
Similarly for IPv6, run the following command:
Q7. How does ss only show TCP or UDP socket?
There are various command line options that you can use here: -t for TCP and -u for UDP.
The following is a useful excerpt from the ss command page.
View TCP socket.
View UDP socket.
View DCCP socket.
View RAW socket.
View Unix domain outlet (alias for -f unix).
-S, - sctp
View SCTP socket.
Display vsock sockets (alias for -f vsock).
The command ss is a handy tool if your Linux work involves networks. Here we have in this guide discussed some command-line options ss-offers. When you are finished training these, go to the tool's man's page to learn more.