Find Out What Ports Are Listening / Open On My Linux & FreeBSD Server

by on March 27, 2006 · 10 comments· LAST UPDATED July 22, 2010

in

How do I find open ports on Linux / FreeBSD server?

There are different commands on both Linux and UNIX server to find out what tcp/udp ports are listening or open on your own server. You can use netstat command, which print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships etc. Another (and suggested) option is to use lsof command, which list open files, and ports on Linux, FreeBSD, Solaris and other Unixish systems.

netstat command to find open ports

# netstat --listen
To display open ports and established TCP connections, enter:
$ netstat -vatn
To display only open UDP ports try the following command:
$ netstat -vaun
If you want to see FQDN (full dns hostname), try removing the -n flag:
$ netstat -vat

lsof Command Examples

To display the list of open ports, enter:
# lsof -i
To display all open files, use:
# lsof
To display all open IPv4 network files in use by the process whose PID is 9255, use:
# lsof -i 4 -a -p 9255

A Note About FreeBSD Users

You can use the sockstat command lists open Internet or UNIX domain sockets, enter:
$ sockstat
$ sockstat -l
$ sockstat -4 -l
$ sockstat -6 -l

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 10 comments… read them below or add one }

1 vinod June 22, 2007 at 9:43 am

I used lsof command in freebsd 5 i am not getting any output for checking tcp/udp ports which are listening or open on my server

Reply

2 doru001 January 4, 2011 at 1:29 pm

sudo?

Reply

3 nixCraft January 5, 2011 at 7:06 am

Yes, you must be root and use sockstat command.

Reply

4 ramakrishna June 5, 2008 at 11:27 am

What is the equivalent port for com9 on linux?How do i find out com port equivalents in linux?Thanks

Reply

5 Rudi August 4, 2008 at 1:27 pm

on FreeBSD you can also use sockstat to list open sockets

Reply

6 Ruwinda Fernando June 29, 2009 at 8:58 am

correction :- should be
netstat -l, –listening :- to get list the listening sockets.

BR.
ruwinda.

Reply

7 Jon November 17, 2010 at 10:58 pm

lsof -i (to get an idea of ports out there)

netstat -a | grep
example: netstat -a | grep 4449

If nothing is returned like below the port is free
$ netstat -a | grep 4449
$

Reply

8 Jacob April 1, 2012 at 3:11 pm

Hello There.

My name is Jacob and I’m running a hosting business. I have 2 dedicated servers at the moment and they’re both Linux Debian 6.0. I have some troubles with my dedicated IP’s. Some server on my dedicated server is having the port 0000 or 0. It takes all the dedicated IP’s and I don’t know how to find where its located or how to close it. I know the pid and I can see it’s running some where but the location I cant see. Please help me. It’s a big problem I’ve been trying to figure out.

Reply

9 sovan December 9, 2012 at 9:51 am

there are some command to find out the all open port…bt there have any command to find out all the port,which are listing or not?that means have any command to show list of all ports?????

Reply

10 sovan December 9, 2012 at 10:00 am

how do i find out what ports are listeningopen/off on my linuxfreebsd server?how do i find the port,which are not listening.i just want to see list of all port.

Reply

Leave a Comment

Tagged as: , , , , , , , , , ,

Previous Faq:

Next Faq: