Sockstat command

On FreeBSD, we can employ sockstat command to list both open Internet and UNIXdomain sockets:

  1. # sockstat
  2. USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS
  3. root sshd 45768 3 tcp4 192.168.80.129:22 192.168.80.1:60803
  4. root sshd 22144 3 tcp4 192.168.80.129:22 192.168.80.1:54834
  5. root sshd 19097 3 tcp4 192.168.80.129:22 192.168.80.1:58174
  6. smmsp sendmail 662 3 dgram -> /var/run/log
  7. root sendmail 659 3 tcp4 127.0.0.1:25 *:*
  8. root sendmail 659 4 dgram -> /var/run/logpriv
  9. root sshd 656 3 tcp6 *:22 *:*
  10. root sshd 656 4 tcp4 *:22 *:*
  11. ......

We can see the output of sockstat lists which process owns the socket, the file descriptor number of the socket, etc. So it is a really awesome tool to diagnose network related issues.

Reference:
SOCKSTAT(1).