August 26, 2017

FREEBSD - Show open sockets

FreeBSD text image

Most people know the netstat command to show you everything about the state of the network on your machine.

You can also use sockstat to list all the open sockets on your system. Below are the sockstat options.

sockstat -4 Show AF_INET (IPv4) sockets.

sockstat -6 Show AF_INET6 (IPv6) sockets.

sockstat -c Show connected sockets.

sockstat -j jid Show only sockets belonging to the specified jail ID.

sockstat -L Only show Internet sockets if the local and foreign addresses are not in the loopback network prefix 127.0.0.0/8, or do notcontain the IPv6 loopback address ::1.

sockstat -l Show listening sockets.

sockstat -p ports Only show Internet sockets if the local or foreign port number is on the specified list.The ports argument is a comma-separated list of port numbers and ranges specified as first and last port separated by a dash.

sockstat -P protocols Only show sockets of the specified protocols. The protocols argument is a comma-separated list of protocol names, as they are defined in protocols(5).

sockstat -s Display the protocol state, if applicable. This is currently only implemented for SCTP and TCP.

sockstat -u Show AF_LOCAL (UNIX) sockets.

© Arnold Greyling 2023