Wednesday, December 22, 2010

How to find out which process is listening on a port when netstat fails you

Sometimes I just bang my head on the wall.  While trying to install Webmin, my favorite web-based interface for system administration for Linux, I recently ran into a conflict.


user@localhost:~$ sudo dpkg -i webmin-current.deb
(Reading database ... 43176 files and directories currently installed.)
Unpacking webmin (from webmin-current.deb) ...
Port 10000 is already in use
dpkg: error processing webmin-current.deb (--install):
 subprocess pre-installation script returned error exit status 2
Errors were encountered while processing:
 webmin-current.deb
user@localhost:~$

I naturally looked to "netstat" to help me determine what process was listening on port 10000.  Unfortunately, no matter what netstat flags I used, I could not get it show a PID.

user@localhost:~$ netstat -anel
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode
....
tcp        0      0 0.0.0.0:10000           0.0.0.0:*               LISTEN      0          12724
....
tcp6       0      0 :::10000                :::*                    LISTEN      0          12725
....
user@localhost:~$

I decided to try to see if I could gather any information from "lsof" and 'lo and behold there is an option "-i :<portnum> for displaying files which are tied to ports.

user@localhost:~$ sudo lsof -i :10000
COMMAND   PID USER   FD   TYPE DEVICE SIZE NODE NAME
beremote 5490 root    3u  IPv4  12724       TCP *:webmin (LISTEN)
beremote 5490 root    4u  IPv6  12725       TCP *:webmin (LISTEN)
user@localhost:~$

Interesting that Backup Exec was listening on port 10000 and lsof identified it as webmin.  Anyways, another problem solved and another tidbit of info save for another day.

1 comment:

  1. Thanks for this! Was scratching my head trying to figure out why webmin wouldn't install ( and how to find what was using that port)

    ReplyDelete