Ubuntu: How to know what program is listening on a given port?


I suspect a program is listening on port 8000 on my machine.

When I run the following command, I get that error:

> python -m SimpleHTTPServer  # Lots of python error  socket.error: [Errno 98] Address already in use  

If I use another port (8000 is the default), this simple web server runs fine.

If I wget localhost:8000, it returns 404 Not Found.

My question is: What can I do, what tools are available to find which program is listening on port 8000? Where is it configured?


To expound on the answer by @33833 you can get some very detailed info, for example:

$ lsof -i :8000  COMMAND  PID  USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME  squid3  1289 proxy   15u  IPv6 14810490      0t0  TCP *:8000 (LISTEN)    $ ps -fp 1289  UID        PID  PPID  C STIME TTY          TIME CMD  proxy     1289     1  0 09:48 ?        00:00:00 /usr/sbin/squid3 -N -f /etc/squid-deb-proxy/squid-deb-proxy.conf  

I can see right there that squid is the process, but it is actualy my squid-deb-proxy that is taking up the port.

Another good example of a java app:

$ lsof -i :4242  COMMAND  PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME  java    3075 root   86u  IPv4    12019      0t0  TCP *:4242 (LISTEN)    $ ps -fp 3075  UID        PID  PPID  C STIME TTY          TIME CMD  root      3075     1 15 May24 ?        3-16:07:25 /usr/local/crashplan/jre/bin/java -Dfile.encoding=UTF-8 -Dapp=CrashPlanService -DappBaseName=CrashPl  

You can see in lsof (LiSt Open Files) that it is java, which is less than helpful. Running the ps command with the PID we can see right away that it is CrashPlan.


you can use netstat to see which process is listening on which port.

I use this command to have a full detail :

sudo netstat -peanut  

if you need to know exactly which one is listening on port 8000 you can use this :

sudo netstat -peant | grep ":8000 "  

There is no process that can hide from netstat.


Open your terminal and type as

lsof -i :8000  

that command will list you the application used by that port with PID.

For example, with port 8881:

enter image description here

Hope that helps.


Try ss from iproute2 package:

ss -nlp | grep 8000  


Another way using socklist from procinfo package:

man socklist

socklist is a Perl script that gives you a list of all open sockets, enumerating types, port, inode, uid, pid, fd and the program to which it belongs.

sudo socklist

type  port      inode     uid    pid   fd  name  tcp     53      28749       0   1721    5  dnsmasq  tcp    631      29190       0   2433   11  cupsd  tcp  42376      82230    1000   1345   84  firefox  tcp  49048      71686    1000   1345   67  firefox  tcp  41248      81672    1000   1345  119  firefox  tcp  54676      84558    1000   1345   73  firefox  udp  56107      66258       0   3268   20  dhclient  udp  40804      17857     107    679   14  avahi-daemon  udp     53      28748       0   1721    4  dnsmasq  udp     68      67427       0   3268    6  dhclient  udp    631      19692       0    765    8  cups-browsed  udp   5353      17855     107    679   12  avahi-daemon  


You can use nmap.

It is really important to know which ports are open in your PC, this is not only useful for Linux, but also for other operating systems, Linux has a lot of tools to check which ports are open, the most common is nmap which is a command line tool, but also exist a Graphical frontEnd for it if you prefer that way.1

to install it, just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command below:

sudo apt-get install nmap  

For more information about nmap, and other utilities, go Here


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »