Is it possible to list all processes which connected to particular ip and port?

I want to list the processes which connected to Particular IP and port. Is there any command to achieve this?

Take a look at ss which is a replacement for the old netstat

For example:

 ss -atp

As root, will list all current TCP connections on the server with processes names and PIDs.

man ss for more options.

Best regards

Answered By: ob_dev

With lsof:

lsof -nPi @192.168.1.123:443

(add -t if your only want the process ids).

That lists sockets bound to that address as well.

With ss (from iproute2 on Linux):

ss state established dst 192.168.1.123 'dport = :443'

With PSMisc’s fuser:

fuser -n tcp ,192.168.1.123,443
fuser -n udp ,192.168.1.123,443

However note that it (at least version 22.21 here) won’t report the IPv6-mapped IPv4 addresses, you’d need separate queries for those:

fuser -n tcp ,::FFFF:C0A8:017B,443

(::FFFF:C0A8:017B being the IPv6-mapped version of 192.168.1.123).

Answered By: Stéphane Chazelas

The format is:

lsof -i [tcp|udp][@hostaddr][:[service name|port]]

E.g.,

lsof -i TCP@172.12.1.45:443

See lsof(8).

Answered By: Sreedhar
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.