0

I used netstat -anlptu to check for open ports.
This command is now somewhat deprecated so I start using ss -anptu but each entry takes 2 lines. The result is not practical.
I use Debian.

 

netstat -anlptu:

tcp        0      0 0.0.0.0:6001            0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      -               
tcp        0      0 192.168.0.106:xxxxx     192.0.x.y:443          ESTABLISHED 5081/firefox    

Easy to read and clear.

 

ss -anptu:

tcp    LISTEN     0      20                                                       127.0.0.1:25                                                                           *:*
 users:(("exim4",pid=823,fd=3))
tcp    LISTEN     0      128                                                              *:22                                                                        *:*                  
 users:(("sshd",pid=807,fd=3))
tcp    ESTAB      0      272                                                  192.168.1.200:22                                                            78.224.x.y:36028              
 users:(("sshd",pid=849,fd=3),("sshd",pid=840,fd=3))
tcp    LISTEN     0      20                                                             ::1:25                                                                          :::*                  
 users:(("exim4",pid=823,fd=4))
tcp    LISTEN     0      128                                                             :::22                                                                       :::*                  
 users:(("sshd",pid=807,fd=4))

This is clearly not easy to read.
Some columns are not aligned.

 

If I redirect to less or more:

tcp    LISTEN     0      20     127.0.0.1:25                    *:*                   users:(("exim4",pid=823,fd=3))
tcp    LISTEN     0      128       *:22                 *:*                   users:(("sshd",pid=807,fd=3))
tcp    ESTAB      0      40     192.168.1.200:22              78.224.x.y:36028               users:(("sshd",pid=849,fd=3),("sshd",pid=840,fd=3))
tcp    LISTEN     0      20      ::1:25                   :::*                   users:(("exim4",pid=823,fd=4))
tcp    LISTEN     0      128      :::22                :::*                   users:(("sshd",pid=807,fd=4))

Each entry takes one line, but columns are not aligned. Once again not easy to read

 

--> how can I have a readable output with ss?

1

Use column. For example:

ss -anpt | column -t -x | less

I get output like:

State       Recv-Q  Send-Q  Local                       Address:Port                  Peer                                         Address:Port
LISTEN      0       100     127.0.0.1:143               0.0.0.0:*
LISTEN      0       100     0.0.0.0:465                 0.0.0.0:*
LISTEN      0       128     0.0.0.0:42449               0.0.0.0:*
LISTEN      0       10      0.0.0.0:5298                0.0.0.0:*                     users:(("pidgin",pid=30003,fd=19))

Note: i run a terminal that is 282 columns wide (a maximum width terminal on my 1440p screen with Liberation Mono Regular 11). YMMV on narrower terminals.

column performs a similar, but not identical, job as the columns program from the autogen. It does a good job of auto-formatting text into tabulated columns.

I'm not sure where the original source for column came from, but on debian systems, it's in the bsdmainutil package. It may be in a similarly named package on other Linux distributions.

Package: bsdmainutils
Version: 11.1.2
Description-en: collection of more utilities from FreeBSD
 This package contains lots of small programs many people expect to find when
 they use a BSD-style Unix system.
 .
 It provides banner (as printerbanner), calendar, col, colcrt, colrm, column,
 from (as bsd-from), hexdump (or hd), look, lorder, ncal (or cal), ul, and
 write (as bsd-write).
 .
 This package used to contain whois and vacation, which are now distributed in
 their own packages. Also here was tsort, which is now in the "coreutils"
 package.

The /usr/share/doc/bsdmainutils/copyright file in the package says:

This is a collection of programs from 4.4BSD-Lite that have not (yet) been re-written by FSF as GNU. It was constructed for inclusion in Debian Linux. As programs found here become available from GNU sources, they will be replaced.

and

This package may be redistributed under the terms of the UCB BSD license:

Copyright (C) 1980 -1998 The Regents of the University of California. All rights reserved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.