The ss command is a tool used to dump socket statistics and displays information in similar fashion (although simpler and faster) to netstat. The ss command can also display even more TCP and state information than most other tools. Because ss is the new netstat, we’re going to take a look at how to make use of this tool so that you can more easily gain information about your Linux machine and what’s going on with network connections.
The ss command-line utility can display stats for the likes of PACKET, TCP, UDP, DCCP, RAW, and Unix domain sockets. The replacement for netstat is easier to use (compare the man pages to get an immediate idea of how much easier ss is).
In this tutorial, we will illustrate How to use ss Command in Linux.
- ss command without any options simply lists all the connections
- List of both listening and non-listening ports using the -a option
- Display listening sockets using the -l option
- Usel -t option to list all TCP connection
- List all Listening TCP Connections
- Also you can List all UDP Connections
- List all Listening UDP Connections
- Also list Summary Statistics using -s flag
- Display Process IDs of Sockets using -p flag
- Also Display IPv4 and Socket Connections
- Display IPv6 Socket Connections
- Filter Connections by Port Number to display all socket connections with a destination or source port of http
ss -at '( dport = :80 or sport = :80 )'
- Also, you can do the previous steps with its name (http) as follows
ss -at '( dport = :http or sport = :http )'
- You can use more one flag to filtering your output according to your needs
- Also you can make deep filtering as the same as the previous steps with grep command to get the specific value you searched on as shown below
ss -ntlpua | grep 80
We showed you how to use ss command, with ss, you can get very detailed information about how your Linux machine is communicating with other machines, networks, and services; details about network connections, networking protocol statistics, and Linux socket connections.