≡ Menu

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

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

Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 11 comments… add one }

  • vinod June 22, 2007, 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

    • doru001 January 4, 2011, 1:29 pm

      sudo?

    • nixCraft January 5, 2011, 7:06 am

      Yes, you must be root and use sockstat command.

  • ramakrishna June 5, 2008, 11:27 am

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

  • Rudi August 4, 2008, 1:27 pm

    on FreeBSD you can also use sockstat to list open sockets

  • Ruwinda Fernando June 29, 2009, 8:58 am

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

    BR.
    ruwinda.

  • Jon November 17, 2010, 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
    $

  • Jacob April 1, 2012, 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.

  • sovan December 9, 2012, 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?????

    • NublaII August 1, 2014, 2:35 pm

      Try this:
      open tcp, udp, listening, program, numeric, ipv4
      netstat -tulpn4

  • sovan December 9, 2012, 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.

Leave a Comment