Find PID Listening on an IP Address and Port
On Linux, you can use the netstat command to discover which process (and its PID) is listening on a specific IP address and port. Follow the steps below.
1. Basic Command
sudo netstat -tunlp | grep <IP_ADDRESS>
- Replace
<IP_ADDRESS>with the actual IP you want to check. For example:grep 192.168.1.10
2. Command Options
-t: Show only TCP connections-u: Show only UDP connections-n: Display addresses and ports numerically without name resolution-l: Show only listening sockets-p: Show the PID/Program name using each socket
3. Example Output
tcp 0 0 192.168.1.10:34001 0.0.0.0:* LISTEN 2759984/nginx
| Field | Meaning |
|---|---|
tcp | Protocol (TCP) |
192.168.1.10:34001 | Local IP and port |
LISTEN | Socket state |
2759984/nginx | PID=2759984, process name=nginx |
4. Terminate the Discovered PID
sudo kill 2759984
For a forceful kill (SIGKILL):
sudo kill -9 2759984
5. Alternative: ss Command
The ss tool is faster and provides similar information:
sudo ss -tunlp | grep 192.168.1.10
In summary, these commands help you quickly identify which process is listening on a given IP address and port, and allow you to terminate it if needed.
Visited 14 times, 1 visit(s) today
