Table of Contents

Linux Commands#network

ss - How to use ss command in Linux with examples

ss - another utility to investigate sockets



man ss

NAME
       ss - another utility to investigate sockets

SYNOPSIS
       ss [options] [ FILTER ]

DESCRIPTION
       ss is used to dump socket statistics. It allows showing information similar to netstat.
       It can display more TCP and state informations than other tools.

OPTIONS
       When no option is used ss displays a list of open non-listening TCP sockets that have established connection.

       -h, --help
              Show summary of options.

       -a, --all
              Display both listening and non-listening (for TCP this means established connections) sockets.

       -l, --listening
              Display only listening sockets (these are omitted by default).

       -p, --processes
              Show process using socket.

       -t, --tcp
              Display TCP sockets.

       -u, --udp
              Display UDP sockets.


ssh -h

$ ss -h
Usage: ss [ OPTIONS ]
       ss [ OPTIONS ] [ FILTER ]
   -h, --help          this message

   -a, --all           display all sockets
   -l, --listening     display listening sockets

   -t, --tcp           display only TCP sockets
   -u, --udp           display only UDP sockets


ss command Example

ss List all connections
ss -a List listening and non-listening ports
ss -l List listening ports
ss -lt List listening TCP connections
ss -ua List UDP socket connections
ss -lu List listening UDP socket connections
ss -at '( dport = :22 or sport = :22 )' List of ports 22

-t(TCP)

$ ss -t
State      Recv-Q Send-Q             Local Address:Port                              Peer Address:Port
ESTAB      0      96                 13.xx.xx.xx:22                                  14.xx.xx.xx:8901
$

-t(TCP) -l(listening)

$ ss -tl
State      Recv-Q Send-Q             Local Address:Port                              Peer Address:Port
LISTEN     0      128                    127.0.0.1:cslistener                                   *:*
LISTEN     0      128                    127.0.0.1:etlservicemgr                                *:*
LISTEN     0      128                            *:http                                         *:*
LISTEN     0      128                            *:22                                           *:*
LISTEN     0      128                            *:ddi-tcp-1                                    *:*
LISTEN     0      100                    127.0.0.1:smtp                                         *:*
LISTEN     0      128                            *:https                                        *:*
LISTEN     0      128                           :::22                                          :::*
LISTEN     0      100                          ::1:smtp                                        :::*
$