Linux is celebrated for its versatility and robust command-line utilities. One such utility is the 'ss' command, which stands for "Socket Statistics." It is a potent tool for inspecting and displaying detailed information about network sockets on a Linux system. The 'ss' command is an indispensable resource for network administrators, system administrators, and developers, offering insights into network connections, routing tables, and more.
In this comprehensive guide, we'll explore the 'ss' command, its various options, and use cases, and provide real-world examples to help you harness its full potential.
Basic Syntax of `ss` command in Linux
Before diving into the intricacies of 'ss,' let's start with its basic syntax:
ss [options]
Where [options] can be any combination of command-line options that modify the behavior of 'ss.' Below, we'll delve into some common options and their use cases.
Options Available in the `ss` command Linux
We will go through the most common options available.
|
Display TCP sockets
|
Display UDP sockets
|
Display listening sockets
|
Display all sockets (listening and non-listening)
|
Display detailed information (including users)
|
Display internal information
|
Show numerical addresses instead of resolving
|
Display the routing table
|
Display summary statistics
|
Display only IPv4 sockets
|
Display only IPv6 sockets
|
Show timers
|
Show process information
|
Show process statistics
|
Display TIME-WAIT sockets
|
Display listening sockets
|
Display all sockets (listening and non-listening)
|
Show numerical addresses instead of resolving
|
Display extended socket information
|
Resolve hostnames
|
Display process information
|
Display process information in raw format
|
Display summary statistics
|
Note : This is not an exhaustive list, and the 'ss' command offers additional options and flexibility. You can explore further options and combinations by referring to the 'ss' manual page using the command man ss in your terminal.
Displaying Socket Information:
List All Sockets:
To obtain a comprehensive list of all active sockets on your system, use the following command:
ss
ss
When you execute this command, it provides a detailed list of established connections. This information includes the protocol type (e.g., TCP, UDP, RAW), local and foreign addresses, the state of each connection, and more.
Filtering by Protocol:
You can narrow down the socket list by specifying a particular protocol. For instance, if you want to view only TCP sockets, use the -t option like this:
ss -t
This command displays only TCP sockets, making it easier to focus on a specific type of connection.
Display Listening Sockets:
To see all sockets currently in the listening state (sockets waiting for incoming connections), employ the -l option:
ss -l
ss -lThis command helps you identify which services or applications are actively listening for incoming network connections.
Display Established Connections:
If you're interested in viewing exclusively established connections (sockets that are actively communicating), use the -e option:
ss -e
ss -eThis command provides a concise list of connections that are currently established, omitting listening or other states.
Advanced Filtering and Display Options:
The 'ss' command offers more advanced options for filtering and customizing the displayed socket information.
Filter by Port:
To filter sockets based on a specific port number, you can use commands like this:
ss sport = :80
This command, for example, displays sockets with a source port of 80. It's useful for pinpointing connections related to a particular service or port.
Display IPv6 Sockets:
If you need to view IPv6 sockets in addition to IPv4, use the `-6` option:
ss -6
This command allows you to see both IPv4 and IPv6 socket information.
Display Summary Statistics:
To obtain summary statistics about various socket types, utilize the -s option:
ss -s
Running this command provides a summarized overview of socket types, including their counts and various states.
Real-World Examples:
Example 1: Display TCP Connections to Port 22 (SSH):
ss -t sport = :22
This command specifically displays TCP connections with a source port of 22, which is typically associated with SSH connections. It helps you identify active SSH sessions.
Example 2: Show UDP Listening Ports:
ss -ul
This command lists all UDP sockets in the listening state, which is valuable for identifying open UDP ports on your system.
Example 3: Display Summary Statistics for TCP and UDP:
ss -s -t -u
Here, the command combines `-s` with `-t`and `-u` to provide summary statistics separately for TCP and UDP socket types, offering insights into the overall network usage on your system.
Conclusion:
The 'ss' command is a valuable tool for examining network sockets and connections on a Linux system. Its flexibility and numerous options make it suitable for a wide range of tasks, from troubleshooting network issues to monitoring network activity.
In this guide, we've covered the basic syntax of 'ss' and explored various options and real-world examples to illustrate its practical use. By mastering the 'ss' command, you gain insight into the network activity on your Linux system and can effectively manage and troubleshoot network-related tasks.
Similar Reads
ls Command in Linux
The ls command is one of the most used commands in the Linux terminal to display the files and directories or path in the terminal. So, using the ls command is a basic skill for navigating the Linux file system, handling files, and managing directories. What is the ls Command in LinuxThe ls command
10 min read
pssh linux comman
The "pssh" command in Linux stands for "parallel SSH," and it is a powerful command designed for executing commands simultaneously on multiple remote servers. This tool simplifies and expedites the process of managing and administering a cluster of machines by allowing administrators to perform task
6 min read
elinks Linux Command
In the field of utility tools, "elinks" is a fast and efficient tool for web content right through the terminal. It is a text-based web browser without any graphical interface. In this article, we are going to discuss in more detail, the features of the elinks tool and how to customize the tool base
5 min read
Fun Commands in Linux
Linux isn't just for coding and administrationâit can also be a lot of fun. With a variety of terminal commands, you can add some entertainment to your Linux experience. Below is a list of some cool and fun commands you can use in Linux to enhance your terminal experience. Weâll also cover how to in
4 min read
Linux Commands
Linux commands are essential for controlling and managing the system through the terminal. This terminal is similar to the command prompt in Windows. Itâs important to note that Linux/Unix commands are case-sensitive. These commands are used for tasks like file handling, process management, user adm
15+ min read
Linux command in DevOps
DevOps engineers use Linux every day because itâs free, fast, and easy to customize. More importantly, most DevOps tools like Docker, Kubernetes, Ansible, Terraform, and Jenkins are built to run best on Linux. In DevOps, you often work on cloud servers (like AWS, Azure, or Google Cloud), and most of
9 min read
Linux vs Windows Commands
Most of us think that Linux has terminal and we can use a command-line interface only in Linux but it is just a myth. There is a PowerShell and a command prompt in windows as well where we may execute the commands easily. But Windows and Linux have commands with the same name as well. .linux-vs-wind
2 min read
How to Use Linux lscpu Command
In the Linux environment, the lscpu command is an important utility for getting detailed information about the CPU (Central Processing Unit) configuration of our system. When this command is been executed, it provides the overview of the CPU architecture such as the CPU family, model, number of core
5 min read
Linux Commands Cheat Sheet
Linux, often associated with being a complex operating system primarily used by developers, may not necessarily fit that description entirely. While it can initially appear challenging for beginners, once you immerse yourself in the Linux world, you may find it difficult to return to your previous W
13 min read
w command in Linux with Examples
The 'w' command in Linux gives us important information about who is currently using the computer, how much the computer is being used, and what programs are running. It's a handy tool for people who take care of computer systems, as it helps them keep an eye on what users are doing, how much of the
3 min read