Finding the process that is using a certain port in Linux

139

57

I'd like to be able to find out which process is currently using a certain port in Linux. Is there any way to do this?

Evan Fosmark

Posted 2009-09-17T18:52:03.637

Reputation: 1 615

3On Windows, the command is : netstat -anb – djangofan – 2009-12-11T21:39:03.677

Answers

146

You have a couple of options:

lsof -i tcp:80

will give you the list of processes using tcp port 80.

Alternatively,

sudo netstat -nlp

will give you all open network connections.

user4358

Posted 2009-09-17T18:52:03.637

Reputation:

I usually add -P to lsof -i tcp:$PORTNUMBER so that the port gets printed back to me as a number. – js. – 2015-06-23T08:42:19.217

2lsof -i | grep {username} is also very useful, i.e. lsof -i | grep apache – LawrenceC – 2011-10-30T03:20:00.257

1For anyone wondering, -n : don't resolve names, -l : display listening server sockets, -p : display PID/Program name for sockets. – yellavon – 2014-05-12T15:18:59.370

9

netstat -lp

Nick

Posted 2009-09-17T18:52:03.637

Reputation: 766

4on mac you have to add a protocol option to -p. so something like: netstat -lp tcp. – vrish88 – 2010-05-25T14:59:28.913

8

I am using "CentOS 7 minimal" which has nor netstat neither lsof. But a lot of linux distributions have the socket statistics command (i.e. ss).

Here is an example of execution:

# ss -tanp | grep 6379
LISTEN   0    128  127.0.0.1:6379   *:*   users:(("redis-server",pid=2531,fd=4))

Oleksandr

Posted 2009-09-17T18:52:03.637

Reputation: 181

2

In Linux, To find a process running on a port, do below:

lsof -i :<port_number>

example:

lsof -i :8080

Amit Kaneria

Posted 2009-09-17T18:52:03.637

Reputation: 121

Thanks for trying to help. This command was mentioned in the accepted answer. If you have something new, please edit your post. – Ben N – 2016-01-06T00:22:25.700