Lesson 81: ss Command
In this lesson, you'll learn how to use the ss command to display network socket-related information on a Linux system.
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 that is used for displaying active socket connections.
Let's explore how the ss command is used to display varied socket connection information in Linux.
ss Command Syntax
$ ss [OPTIONS] [FILTER]
ss Command Options
| Option | Description |
|---|---|
-a |
List all listening and non-listening sockets |
-l |
Display listening sockets only |
-t |
Display TCP connections |
-u |
Display UDP connections |
-lt |
Display all listening TCP connections |
-lu |
Display all listening UDP connections |
-p |
Display the process IDs (PIDs) using the sockets |
-s |
Display summary statistics |
-4 |
Display IPv4 socket connections |
-6 |
Display IPv6 socket connections |
1. List All Connections
The basic ss command without any options simply lists all the connections regardless of the state they are in.
$ ss
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp ESTAB 0 0 192.168.1.10:ssh 192.168.1.1:52341
tcp ESTAB 0 0 192.168.1.10:ssh 192.168.1.2:49812
u_str ESTAB 0 0 /run/systemd/journal/stdout 22001 * 22000
2. List Listening and Non-listening Ports
You can retrieve a list of both listening and non-listening ports using the -a option as shown below.
$ ss -a
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp LISTEN 0 128 0.0.0.0:ssh 0.0.0.0:*
tcp LISTEN 0 128 0.0.0.0:http 0.0.0.0:*
tcp ESTAB 0 0 192.168.1.10:ssh 192.168.1.1:52341
udp UNCONN 0 0 0.0.0.0:bootpc 0.0.0.0:*