FreeBSD Administration

Using sockstat to look at open ports in FreeBSD

If you need to know what ports are open and listening on your FreeBSD servers, you can use a few commands.  Netstat -An used to me my goto command for pulling up a list of ports that are listening but it was always difficult to figure out what process or service had opened those ports.  Recently I discovered sockstat.  Sockstat is not a new utility, it has been around for a long time, I’m not sure why I never used it before.

Sockstat is a versatile utility that can be used to display network and system open sockets in FreeBSD (and other unix variants). This command line utility is installed by default and is used mainly to show what sockets are open and list the process that opened it (or is listening on that socket). It can display both network sockets (TCP/UDP) as well as inter-process sockets (or IPC).

Here is a list of some of the common uses.

List all Open Ports:

# sockstat


List Listening or Open Ports:

# sockstat -l

List all IPv4 Opened Ports:

# sockstat -4

List All IPv6 Opened Ports:

# sockstat -6

List TCP or UDP Opened Ports:

Show only the TCP ports

# sockstat -P tcp

Show only the UDP ports

# sockstat -P udp

List TCP or UDP specific ports but port number

# sockstat -P tcp -p 26

List TCP or UDP specific ports but only those that are connected.

# sockstat -P tcp -p 26 -c

List only Network Ports that are Listening:

# sockstat -46 -l -s

List Unix sockets or Named Pipes:

# sockstat -u

List all the ports opened by an application:

# sockstat -46 | grep ntp

Leave a Comment

Your email address will not be published. Required fields are marked *