How do I find out what ports are listening/open on my Linux / FreeBSD server?

This entry is part 3 of 2 in the series Linux Service Management

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

A. 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 --listenDisplay open ports and established TCP connections:$ netstat -vatnFor UDP port try following command:$ netstat -vaunIf you want to see FQDN, remove -n flag:$ netstat -vat

lsof Command Examples

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

Series Navigation
Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 4 comments… read them below or add one }

1 vinod 06.22.07 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

2 ramakrishna 06.05.08 at 11:27 am

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

3 Rudi 08.04.08 at 1:27 pm

on FreeBSD you can also use sockstat to list open sockets

4 Ruwinda Fernando 06.29.09 at 8:58 am

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

BR.
ruwinda.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

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

Previous post: How do I find out syntax errors in my Apache web server configuration file?

Next post: How can I change the message of the day on my Linux server?