Thursday, January 1, 2015

Linux - Find Port

-- list the open ports and the process that owns them
root# lsof -i

-- Old style netstat
root#netstat -tulpn | less

-- See which process is bound to port 3872
root# lsof -i:3872


Example-->   root# lsof -i

CMD      PID        USER   FD   TYPE   DEVICE       SIZE NODE NAME
oracle      354        oracle   19u  IPv4 2894616637       UDP 169.254.111.254:49430
oracle      354        oracle   22u  IPv4 2894616638       UDP localhost.localdomain:31489
oracle      354        oracle   24u  IPv4 2894616640       UDP 169.254.111.254:65139
oracle      356        oracle   19u  IPv4 2894616648       UDP 169.254.111.254:52799
oracle      356        oracle   22u  IPv4 2894616650       UDP localhost.localdomain:10267
oracle      356        oracle   24u  IPv4 2894616652       UDP 169.254.111.254:61528
oracle      358        oracle   19u  IPv4 2894616669       UDP 169.254.111.254:31016
oracle      358        oracle   22u  IPv4 2894616670       UDP localhost.localdomain:65134
oracle      358        oracle   24u  IPv4 2894616671       UDP 169.254.111.254:11811
oracle      405        oracle   19u  IPv4  501716719       UDP 169.254.111.254:49059
oracle      405        oracle   22u  IPv4  501716720       UDP localhost.localdomain:39383
oracle      405        oracle   24u  IPv4  501716724       UDP 169.254.111.254:55199
oracle      407        oracle   19u  IPv4  501716638       UDP 169.254.111.254:59708
oracle      407        oracle   22u  IPv4  501716646       UDP localhost.localdomain:24933
oracle      407        oracle   24u  IPv4  501716655       UDP 169.254.111.254:63862
oracle      488        oracle   19u  IPv4 3821891154       UDP 169.254.111.254:9376

Example  ->  netstat -tulpn | less

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 127.0.0.1:2016           0.0.0.0:*                   LISTEN      16794/oraagent.bin
tcp        0      0 0.0.0.0:736                 0.0.0.0:*                   LISTEN      14549/rpc.mountd
tcp        0      0 0.0.0.0:59936             0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:2049               0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:643                 0.0.0.0:*                   LISTEN      14455/rpc.rquotad
tcp        0      0 127.0.0.1:199             0.0.0.0:*                   LISTEN      14324/snmpd
tcp        0      0 127.0.0.1:7017           0.0.0.0:*                   LISTEN      16455/p_ctmat
tcp        0      0 127.0.0.1:57386         0.0.0.0:*                   LISTEN      11154/pbx_exchange
tcp        0      0 0.0.0.0:139                 0.0.0.0:*                   LISTEN      14752/smbd
tcp        0      0 0.0.0.0:683                 0.0.0.0:*                   LISTEN      11101/rpc.statd
tcp        0      0 0.0.0.0:49133             0.0.0.0:*                   LISTEN      16815/gpnpd.bi


Example : root# lsof -i:2016


COMMAND   PID   USER   FD   TYPE     DEVICE SIZE NODE NAME
oraagent.        16794 oracle   40u  IPv4 308843       TCP localhost.localdomain:bootserver (LISTEN)