[Updated] A Linux system administrator needs to know some Linux Commands. ss command is a tool that is used for displaying network socket related information on a Linux system. The tool displays more detailed information than the netstat command which is used for displaying active socket connections. In this article, you will learn ss Command Examples to Monitor Network Connections. If you are preparing to purchase your own Linux VPS, the available packages of Eldernode are economical and VIP.
Tutorial ss Command Examples To Monitor Network Connections
Join us with this article to see how the ss command can be used to display varied socket connection information in Linux. In the following of this tutorial, you will learn 12 ss command examples. If you are a new starting user, have a look at our article on 10 useful Linux command Line tricks for Newbies.
Note: If you need to limit normal users to log in and log back in as the root account, you may set up the superuser or root privileges for our normal account. So a normal user should put the word sudo before the command to run commands with administrative privileges.
How to list all connections (ss Command Examples)
To list all the connections regardless of the state they are in, use the basic ss command without any options.
How to list listening and Non-listening ports
You can use use the -a option to retrieve a list of both listening and non-listening ports.
How to list listening sockets
To display listening sockets only, use the -l flag.
How to list all TCP connections
To display all TCP connections, use the -t option.
How to list all listening TCP connections
Use the -lt combination to have a view of all the listening TCP socket connection.
List all UDP connections
View all the UDP socket connections by using the -ua option.
How to list all listening UDP connections
To list listening UDP connections use the -lu option.
How to display PID (Process IDs) of sockets
To display the Process IDs related to socket connections, use the -p flag.
How to display summary statistics
To list the summary statistics, use the -s option.
How to display IPv4 and IPv6 socket connections
If you are curious about the IPv4 socket connections use the -4 option.
To display IPv6 connections, use the -6 option.
How to filter connections by port number
To filter the socket port number or address number, you can use the ss command too. For example, to display all socket connections with a destination or source port of ssh run the command.
ss -at '( dport = :22 or sport = :22 )'
Alternatively, you can run the command.
ss -at '( dport = :ssh or sport = :ssh )'
How to check man pages for ss Command
To get more insights into the ss command usage, check the man pages using the command below.
In this article, you reviewed 12 examples of ss commands. Those are some of the commonly used options that are used with the ss command. The command is considered more superior to the netstat command and provides detailed information about network connections. Find a related article to learn about Linux commands on A to Z Linux commands overview with examples.