5

I want to find some processes which are running on a specified port for example 80

I ran

fuser 80/tcp

and got nothing

and then

netstat -tulpn|grep "80\|PID"

and got

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 :::80                       :::*                        LISTEN      -  

the PID is -

so what does - mean? thanks!

6
  • 1
    Do you run these commands as root?
    – mpy
    Commented Apr 24, 2013 at 14:33
  • no, ah, I ran it now as root, it shows results, thanks
    – misteryes
    Commented Apr 24, 2013 at 14:38
  • @mpy Please post this as an answer (maybe extend it and explain why you need to be root etc.)
    – slhck
    Commented Apr 24, 2013 at 19:30
  • @slhck: You gave quite a tough nut to crack why you need to be root... ;)
    – mpy
    Commented Apr 24, 2013 at 21:14
  • 1
    @mpy Haha, well that's a great answer for sure. I just thought that "You have to be root" wouldn't pass the quality filter :)
    – slhck
    Commented Apr 24, 2013 at 21:23

1 Answer 1

3

The short answer is: You need to be root in order to see all bindings.

A little bit longer:

The manpage of netstat gives a hint that is not necessary in all cases:

PID/Program name Slash-separated pair of the process id (PID) and process name of the process that owns the socket. --program causes this column to be included. You will also need superuser privileges to see this information on sockets you don't own.

So, as a normal user you only see which process listens to a port, if you own it:

$ netcat -l -p 1234 &
$ netstat -tulpn
[...]
tcp        0      0 0.0.0.0:1234            0.0.0.0:*               LISTEN      8044/netcat     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -    
[...]

You see "your" netcat process, but not who is listening to e.g. port 22.

I have a feeling, that the reason for that is, that you can't acces /proc/[PID]/fd for not-owned processes. There you find the file descriptors process [PID] has currently opened and in Un*x (nearly) everything is a file... and so are sockets.

In my example sshd, pid 3934, listens to port 22 (surprise-surprise):

$ whoami
user
$ ls -l /proc/3934/fd
/bin/ls: cannot open directory /proc/3934/fd: Permission denied
$ sudo ls -l /proc/3934/fd
total 0
lrwx------ 1 root root 64 Apr 24 16:33 0 -> /dev/null
lrwx------ 1 root root 64 Apr 24 16:33 1 -> /dev/null
lrwx------ 1 root root 64 Apr 24 16:33 2 -> /dev/null
lrwx------ 1 root root 64 Apr 24 16:33 3 -> socket:[10481]
lrwx------ 1 root root 64 Apr 24 16:33 4 -> socket:[10483]

(The second socket is bond to the IPv6 adress which I omitted in my netstat output.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .