How to check which program is using a port on Linux

Last updated on November 24, 2020 by Dan Nanni

Question: My program cannot bind to a particular port number because it is used by another program/process which I don't know. Is there any way to check which program/process is currently using a particular port number on Linux?

You can detect which process is bound to what port number by using lsof command. Simply specify the port number you are interested in with -i:<port-number> option.

For example, to find out which processes are opening a port number 631, run the following command.

$ sudo lsof -i:631 -n -P
cupsd     776 root   10u  IPv6   9353      0t0  TCP [::1]:631 (LISTEN)
cupsd     776 root   11u  IPv4   9354      0t0  TCP (LISTEN)
cups-brow 953 root    8u  IPv4   9930      0t0  UDP *:631

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

To see a list of all open TCP ports, along with their associated programs/processes, you can run the command below.

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

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean