Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

5 Answers 5

up vote 74 down vote accepted

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

I use this command to have a full detail :

sudo netstat -taupen

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

sudo netstat -tapen | grep ":8000 "

There is no process that can hide from netstat.

share|improve this answer

Open your terminal and type as

lsof -i :8000

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

for example

enter image description here

Hope that helps.

share|improve this answer
1  
This also works on OSX for what its worth..... –  reevesy Mar 11 at 12:36

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.

share|improve this answer
1  
In one command: lsof -t -i :8000 | xargs ps -fp –  brett Aug 13 at 23:41

'ss' from iproute2 package. Try:

ss -nlp | grep 8000
share|improve this answer
    
ss also has its own filtering capabilities: ss -nlp '( sport = :8000 )'. –  gnp Dec 9 at 21:21

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

1Source:garron.me

share|improve this answer
    
nmap will only tell you THAT a port is open, not which process opened it. –  Andrew Burns Jun 17 at 15:49
    
I clicked through to your source to read [nmap] tries to guess which service is listening on each port, but it can make mistakes right before it suggests an actual method to find out which process owns the socket. –  gnp Dec 9 at 21:24
    
@gnp You may also want to take a look at This. –  Mitch Dec 10 at 6:15
    
@Mitch I did. The OP needs to know the exact PID of a process on the local system. Nmap is not the right tool here, not even with service and version detection. Either it will match an item on nmaps database, which still lets OP on the dark as to what process to kill or reconfigure, or it won't and OP will have a nice fingerprint and a link to insecure.org –  gnp Dec 10 at 14:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.