Check if a service is listening

Summary

Many administrator are using ss | grep to check if a service is listening to a particular port ex:

     ss -antp | grep 22
LISTEN 0      128           0.0.0.0:22          0.0.0.0:*     users:(("sshd",pid=1423,fd=6))

ss -l

ss has an internal option to find sockets that are listening on a dediacted port

ss -l '( sport = :ssh )' #replace ssh by the service
# or
ss -l '( sport = :22 )' #replace 22 by the port you are looking for

Ex:

      ss -l '( sport = :ssh )'
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                                         [::]:ssh                                      [::]:*                  
      ss -l '( sport = :22 )'
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                                         [::]:ssh                                      [::]:*   

The result is cleaner as ss displays only listening state.