Difference between revisions of "Port to PID"

From Noah.org
Jump to navigationJump to search
Line 3: Line 3:
 
Use the `lsof` command to find which process is listening on a given port.
 
Use the `lsof` command to find which process is listening on a given port.
  
For example, I saw that some process was already using port 69 (normally TFTP). I did not expect this port to be in use, so I ran the following command to find out which process what listening on port 69:
+
The -n option for `lsof` turns of reverse name resolution which speeds up the output. Otherwise it will try to reverse each IP address to a name.
 +
 
 +
For example, say I saw that some process was already using port 69 (normally TFTP). I did not expect this port to be in use, so I ran the following command to find out which process what listening on port 69:
 +
 
 +
<pre>
 +
lsof -n -i :69
 +
</pre>
 +
 
 +
To find which process is listening on port 80 (you would expect some http server):
  
 
<pre>
 
<pre>
lsof -i :69
+
lsof -n -i :80
 
</pre>
 
</pre>
  
So to find which process is listening on port 80 (expect some http server):
+
To see who is connected via SSH or SCP look for port 22:
  
 
<pre>
 
<pre>
lsof -i :80
+
lsof -n -i :22
 
</pre>
 
</pre>
  
Line 18: Line 26:
  
 
<pre>
 
<pre>
lsof -u USER
+
lsof -n -u USER
 
</pre>
 
</pre>
  
 
<pre>
 
<pre>
lsof -c COMMAND
+
lsof -n -c COMMAND
 
</pre>
 
</pre>

Revision as of 14:50, 25 September 2008

Use the `lsof` command to find which process is listening on a given port.

The -n option for `lsof` turns of reverse name resolution which speeds up the output. Otherwise it will try to reverse each IP address to a name.

For example, say I saw that some process was already using port 69 (normally TFTP). I did not expect this port to be in use, so I ran the following command to find out which process what listening on port 69:

lsof -n -i :69

To find which process is listening on port 80 (you would expect some http server):

lsof -n -i :80

To see who is connected via SSH or SCP look for port 22:

lsof -n -i :22

You can also look for files opened by a given user or command:

lsof -n -u USER
lsof -n -c COMMAND