How To Check Which Program Is Using A Port Via Terminal

by
Share this Article: Facebook188Google+0Twitter16LinkedIn2Reddit0StumbleUpon0

You are sometimes trying to install or configure a program and bind it to a port and it throws an error. That means some other program is using that particular port. Let’s see how you can check what program is using your system’s ports.

First if you know the number of the port you are interested in you can:

For example let’s check port number 631:

$ sudo lsof –i:631 –n –P

That should give you something like that:

COMMAND   PID USER   FD   TYPE  DEVICE  SIZE/OFF  NODE NAME
cupsd         776 root   10u  IPv6   9353       0t0  TCP [::1]:631 (LISTEN)
cupsd         776 root   11u  IPv4   9354       0t0  TCP 127.0.0.1:631 (LISTEN)
cups-brow      953 root    8u  IPv4   9930      0t0  UDP *:631

In the above, the “-n” parameter prevents automatic conversion of host IP address to host name, and “-P” parameter prohibits conversion of port number to port name. In our example, cupsd and cups-brow processes are using TCP and UDP port number 631, respectively.

If you want a list of all open TCP ports and the programs/processes associated you can type:

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

On the table resulting from it, on the left column it has the processes and on the right the ports.

For questions please refer to our Q/A forum at : http://ask.unixmen.com/

Share this Article: Facebook188Google+0Twitter16LinkedIn2Reddit0StumbleUpon1