Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
81
rated 0 times [  81] [ 0]  / answers: 1 / hits: 120045  / 3 Years ago, wed, september 8, 2021, 9:53:47

Given a port number how can we find which process is using it?


More From » networking

 Answers
7

We have a variety of options:








netstat



sudo netstat -nlp


will give you all open network connections.



$ netstat -nlp
(No info could be read for "-p": geteuid()=901743 but you should be root.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:44886 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:8139 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:10000 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:81 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:48562 0.0.0.0:* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -
tcp6 0 0 :::46871 :::* LISTEN -
tcp6 0 0 ::1:6010 :::* LISTEN -
tcp6 0 0 :::57179 :::* LISTEN -
tcp6 0 0 :::5666 :::* LISTEN -
tcp6 0 0 :::111 :::* LISTEN -
tcp6 0 0 :::4949 :::* LISTEN -
udp 0 0 127.0.0.1:896 0.0.0.0:* -
udp 0 0 0.0.0.0:45467 0.0.0.0:* -
udp 0 0 0.0.0.0:111 0.0.0.0:* -
udp 0 0 10.105.2.3:123 0.0.0.0:* -
udp 0 0 127.0.0.1:123 0.0.0.0:* -
udp 0 0 0.0.0.0:123 0.0.0.0:* -
udp 0 0 0.0.0.0:39554 0.0.0.0:* -
udp 0 0 0.0.0.0:711 0.0.0.0:* -
udp 0 0 0.0.0.0:10000 0.0.0.0:* -
udp6 0 0 :::53766 :::* -
udp6 0 0 :::49696 :::* -
udp6 0 0 :::111 :::* -
udp6 0 0 fe80::5054:ff:fed0::123 :::* -
udp6 0 0 ::1:123 :::* -
udp6 0 0 :::123 :::* -
udp6 0 0 :::711 :::* -
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node PID/Program name Path
unix 2 [ ACC ] STREAM LISTENING 7943 - /var/run/dbus/system_bus_socket
unix 2 [ ACC ] STREAM LISTENING 8494 - /run/rpcbind.sock
unix 2 [ ACC ] STREAM LISTENING 729659 - /var/run/mysqld/mysqld.sock
unix 2 [ ACC ] STREAM LISTENING 11324 - /var/run/php5-fpm.sock
unix 2 [ ACC ] STREAM LISTENING 11082 - /var/run/nscd/socket
unix 2 [ ACC ] STREAM LISTENING 7607 - @/com/ubuntu/upstart
unix 2 [ ACC ] STREAM LISTENING 668784 - /var/run/nslcd/socket
unix 2 [ ACC ] SEQPACKET LISTENING 6768 - /run/udev/control
unix 2 [ ACC ] STREAM LISTENING 8924 - /var/run/acpid.socket





lsof



lsof -i tcp:43796


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



$ lsof -i tcp:1723
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
pptpd 2870 root 6u IPv4 17638 0t0 TCP *:1723 (LISTEN)





fuser



fuser 43796/tcp


will give you the list of pids using tcp port 43796.



$ fuser 1723/tcp
1723/tcp: 2870





Source


[#33787] Thursday, September 9, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tresein

Total Points: 197
Total Questions: 113
Total Answers: 112

Location: Hungary
Member since Wed, Nov 9, 2022
2 Years ago
tresein questions
Tue, Jun 28, 22, 17:57, 2 Years ago
Sun, Apr 3, 22, 07:11, 2 Years ago
Thu, Feb 3, 22, 18:03, 2 Years ago
Sat, May 13, 23, 13:00, 1 Year ago
;