[Linux](EN) Find process id of process using specific port with netstat

Find process id of process using specific port with netstat


Environment and Prerequisite

  • Ubuntu
  • CentOS
  • netstat(8)


Find process id of process using specific port with netstat

netstat

netstat -nltup | grep [port_number]

Usage

twpower@twpower-private-server:~$ netstat -nltup | grep 8888
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 127.0.0.1:8888          0.0.0.0:*               LISTEN      622522/python3.9


netstat and option

netstat

  • Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships
NETSTAT(8)               Linux System Administrator's Manual              NETSTAT(8)

NAME
       netstat  -  Print  network connections, routing tables, interface statistics, masquerade connections, and multicast memberships

Used Options

  • n: Show numeric IP address not hostname.
  • l: Show LISTEN state of network connections and unix sockets.
  • t: Show TCP protocol datas.
  • u: Show UDP protocol datas.
  • p: Show process id and name.


Reference