Find listen ports on your linux

For example, if you only want to see TCP connections, use netstat –tcp.
This shows a list of TCP connections to and from your machine. The following example shows connections to our machine on ports 993 (imaps), 143 (imap), 110 (pop3), 25 (smtp), and 22 (ssh).It also shows a connection from our machine to a remote machine on port 389 (ldap).

Note: To speed things up you can use the –numeric option to avoid having to do name resolution on addresses and display the IP only.

Code Listing 1: netstat –tcp

% netstat --tcp --numeric  
Active Internet connections (w/o servers)  
Proto Recv-Q Send-Q Local Address           Foreign Address         State       
tcp        0      0   ESTABLISHED
tcp        0      0   ESTABLISHED
tcp        0      0      TIME_WAIT
tcp        0      0     TIME_WAIT
tcp        0      0    TIME_WAIT
tcp        0    256   ESTABLISHED


If you want to see what (TCP) ports your machine is listening on, use netstat –tcp –listening.
Another useful flag to add to this is –programs which indicates which process is listening on the specified port.
The following example shows a machine listening on ports 80 (www), 443 (https), 22 (ssh), and 25 (smtp);

Code Listing 2: netstat –tcp –listening –programs

# sudo netstat --tcp --listening --programs
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address   Foreign Address   State     PID/Program name
tcp        0      0 *:www           *:*               LISTEN    28826/apache2
tcp        0      0 *:ssh           *:*               LISTEN    26604/sshd
tcp        0      0 *:smtp          *:*               LISTEN    6836/
tcp        0      0 *:https         *:*               LISTEN    28826/apache2


Note: Using –all displays both connections and listening ports.

The next example uses netstat –route to display the routing table. For most people, this will show one IP and and the gateway address but if you have more than one interface or have multiple IPs assigned to an interface, this command can help troubleshoot network routing problems.

Code Listing 3: netstat –route

% netstat --route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface   U     0      0        0 eth0         UG    1      0        0 eth0


The last example of netstat uses the –statistics flag to display networking statistics. Using this flag by itself displays all IP, TCP, UDP, and ICMP connection statistics.
To just show some basic information. For example purposes, only the output from –raw is displayed here.
Combined with the uptime command, this can be used to get an overview of how much traffic your machine is handling on a daily basis.


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

So far I like this one the best. You need sudo to see the programs that are listening

sudo netstat -tple


sudo netstat -lnptu

Published by

John C. Zastrow

Grew up in Youngstown, NY with a deep respect and fascination for the Laurentian Great Lakes and all things water. After a dabbling with interests in sports medicine, and being a professional potter, undergraduate work at CU - Boulder led me back to my passion for water and science. Undergrad degree in tow, I worked as an aquatic toxicologist and GIS/RS analyst in the Front Range. Graduate work at Wisconsin – Milwaukee fed my curiosity about the Great Lakes extended my interests in data analysis and management. My projects involved climate change modeling, phytoplankton physiology, riding research vessels in the frigid Lake Michigan, managing an environmental database development effort, and of course GIS/RS. My next job found me in Fairfax, Virginia where I was able to continue with most of my professional interests. The chaos of Greater D.C and a need to be closer to family brought us to Portland, Maine. I am still passionate about all things water, environmental, and spatial and am a strong advocate for Open Source software (for a variety of reasons). I lead software development and data management projects for Tetra Tech and focus on things geospatial.