lsof to view running services and ports

Moderators: ashishsinha, alok, Linux Moderators

lsof to view running services and ports

Postby alok on Tue May 08, 2012 10:22 am

Now you want to know what services are running on the Linux server and on which ports. You have netstat coming as the first choice of command for this job. Good !!

But you can also use "lsof" command for the purpose.

Code: Select all
lsof -Pnl +M -i4


for checking IPv4 ports, and

Code: Select all
lsof -Pnl +M -i6


for checking IPv6 ports

Here:
-P - will stop the conversion of port numbers to port names for network files. This will make lsof run a little faster.

-n - will stop conversion of network numbers to host names for network files. Useful where host name lookup is not working properly.

-l - will stop conversion of user ID numbers to login names.

+M - reports portmapper registrations for local TCP and UDP ports.

-i4 - IPv4 listing only
-i6 - IPv6 listing only

You can use the lsof command without -Pnl and +M option to see the difference in the output.

Here is a sample output from my system. You can also view this post on Network NUTS Facebook Page at http://www.facebook.com/networknuts

networknuts-lsof.png
lsof showing running services and ports
User avatar
alok
 
Posts: 231
Joined: Tue Dec 23, 2008 11:11 am

Return to Linux Room

Who is online

Users browsing this forum: No registered users and 2 guests