This article shows how to find a process listening on a specific port in Linux.
Use the following command to find a process name listening on a specific port:
$ sudo lsof -i :8000
This example shows that the python3
process is listening on port 8000.
You can list the Linux processes that are listening on any TCP or UDP port:
$ sudo netstat -lntup| grep LISTEN
Here are the keys to use:
-l
– show listening ports only-n
– display IP addresses and port numbers in numerical form and do not resolve them (check the /etc/services file to find the mappings between port numbers and service names)-t
– show open TCP ports-u
– show open UDP ports-p
– show the ID of the process listening on the port
We have found the PID of the process using the port, and can now display detailed process information:
$ ps -aux | grep 72005
In this example, the process is started manually by the root user with the following command: python3 -m http.server
(is used to run a simple HTTP server to share the current directory).
To kill the process listening on the busy port you want to free, run:
$ sudo kill -9 72005
You can check that the port is free now:
$ sudo lsof -i :8000