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

by Vivek Gite on March 27, 2006 · 7 comments

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

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 7 comments… read them below or add one }

1 vinod June 22, 2007

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

sudo?

Reply

3 Vivek Gite January 5, 2011

Yes, you must be root and use sockstat command.

Reply

4 ramakrishna June 5, 2008

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

on FreeBSD you can also use sockstat to list open sockets

Reply

6 Ruwinda Fernando June 29, 2009

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

BR.
ruwinda.

Reply

7 Jon November 17, 2010

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

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 14 + 13 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: