netstat is obsolete, use 'ss'
netstat has been a valuable tool for Linux sysadmins for a long time. Now there is a better option.
If you are still using
netstat this is news for you. There is a better alternative;
ss. According to the documentation of
ss, it can display more socket information than other tools.
The following commands were executed on Ubuntu 18.04 with
ss180129. Depending on your version, output parameters may slightly vary.
Given no arguments,
ss comaand will list all TCP, UDP, and Unix sockets, that are in
a is used to print all sockets, in all states.
List only TCP sockets, in
List all TCP sockets, in all states.
Display additional information on TCP sockets.
The output of
ss -ti include almost all the paraemters related to TCP stack, so wil be invaluable in troubleshooting network issues.
Filtering can be applied based on socket status. The command takes the form
ss [options] state <tcp-state>.
List all TCP listening ports.
List all TCP ports in SYN-SENT status.
Filtering can also be done based IP address.
Or, based on source, dstination ports.
These filters can be combined to get a more fine grained output. Below command will list the TCP sockets in established state to port 22 with peer IP 172.16.10.10.
As you may appreciate
ss has advanced filtering capabilities and provides more information than
netstat. So, next time when you are investigating any network related things, rememeber to use
ss instead of