How to find the running network services and the port and user

I want to find a list of all network services running on my system, including details of the port and services and the users. I know that I need to use netstat, ps and fuser. but I don't know how to write the command. Do I need to write a shell script to find all of them? or I can use in a line of commands? Thanks for your help.


Use the command : sudo lsof -i -n -P

This command lists the Application Name, PID, User, IP version, Device ID and the Node with Port Name. It shows both TCP and UDP.

Variations :

  • To format it in a nice, readable way; use :

    sudo lsof -i -n -P | more

  • To view view only TCP connections :

    sudo lsof -i -n -P | grep TCP | more

  • To view view only UDP connections :

    sudo lsof -i -n -P | grep UDP | more