How Do I Find Open Ports on FreeBSD?

Last updated: Aug 20, 2008

Sometimes it is helpful to know which ports are currently open on your server. On my FreeBSD servers I like to use the sockstat command. It is very similar to the netstat command for Windows or Linux. You can configure it to show IPv4 ports, IPv6 or both.

One of the benefits of checking your server’s open ports with sockstat, is its ability to generate a quick list of all your services. Once you have a list of services listening on specific ports you can go through each one and see if you really need it. This is helpful because reducing unneeded services is often the first recommended step towards securing a server.

A list of active services also gives you an idea of which ports you need to allow through your firewall. This is especially useful if you use a “deny all by defaut” type configuration.

To get a quick list of open ports I use:

sockstat -4 -l

This command shows all listening IPv4 ports.

To check IPv6 ports you would use:

sockstat -6 -l

And then of course if you want to display all ports simply use:

sockstat

Another useful thing to do is print off the list for future reference by piping the output to the printer (lpr).

socstat -4 -l | lpr

Need to print shipping labels on your site?

Checkout my product RocketShipIt for simple easy-to-use developer tools for UPS™ FedEx™ USPS™ and more.

Get notified on new posts or other things I'm working on

Share: