Sometimes you detect some proccess running on your machine, and you need to know which port is it using

This example is for Red Hat 4.4.7-23, but i think it would work on any linux machine

I'm going to tell you some ways to achive that point

1st netstat -ltnp IN below example you can see ip:port in 4th column linked in last column with PID, for example program tnslsnr running under PID 36996 is using 10.94.3.69:1521 socket as you can see below:
#/home/oracle>netstat -ltnp
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:21135               0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      -
tcp        0      0 10.94.3.66:1521             0.0.0.0:*                   LISTEN      29937/tnslsnr
tcp        0      0 10.94.3.58:1521             0.0.0.0:*                   LISTEN      29937/tnslsnr
tcp        0      0 10.94.3.69:1521             0.0.0.0:*                   LISTEN      36996/tnslsnr
tcp        0      0 169.254.38.186:37233        0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:23571               0.0.0.0:*                   LISTEN      -
tcp        0      0 127.0.0.1:6100              0.0.0.0:*                   LISTEN      36144/ons
tcp        0      0 0.0.0.0:1556                0.0.0.0:*                   LISTEN      -
tcp        0      0 127.0.0.1:1557              0.0.0.0:*                   LISTEN      -
tcp        0      0 127.0.0.1:10006             0.0.0.0:*                   LISTEN      7546/httpd.worker
tcp        0      0 169.254.38.186:24086        0.0.0.0:*                   LISTEN      36996/tnslsnr
tcp        0      0 169.254.38.186:31606        0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:13782               0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      -
tcp        0      0 127.0.0.1:17719             0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:6200                0.0.0.0:*                   LISTEN      36144/ons
tcp        0      0 0.0.0.0:4889                0.0.0.0:*                   LISTEN      7546/httpd.worker
tcp        0      0 0.0.0.0:3481                0.0.0.0:*                   LISTEN      -
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:7802                0.0.0.0:*                   LISTEN      7546/httpd.worker
tcp        0      0 0.0.0.0:22234               0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:9851                0.0.0.0:*                   LISTEN      7546/httpd.worker
tcp        0      0 127.0.0.1:31164             0.0.0.0:*                   LISTEN      39630/nmz
tcp        0      0 0.0.0.0:9788                0.0.0.0:*                   LISTEN      7546/httpd.worker
tcp        0      0 0.0.0.0:13724               0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:6556                0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:53084               0.0.0.0:*                   LISTEN      -
tcp        0      0 10.94.3.58:7102             0.0.0.0:*                   LISTEN      31128/java
tcp        0      0 0.0.0.0:222                 0.0.0.0:*                   LISTEN      -
tcp        0      0 10.94.3.58:9599             0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:59167               0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:3872                0.0.0.0:*                   LISTEN      26734/java
tcp        0      0 0.0.0.0:29505               0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:54817               0.0.0.0:*                   LISTEN      23642/gpnpd.bin
tcp        0      0 0.0.0.0:2049                0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:4900                0.0.0.0:*                   LISTEN      7546/httpd.worker
tcp        0      0 127.0.0.1:23940             0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:9796                0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:28548               0.0.0.0:*                   LISTEN      -
tcp        0      0 10.94.3.58:7301             0.0.0.0:*                   LISTEN      42231/java
tcp        0      0 10.94.3.58:9702             0.0.0.0:*                   LISTEN      8192/java
tcp        0      0 127.0.0.1:199               0.0.0.0:*                   LISTEN      -
tcp        0      0 10.94.3.58:5000             0.0.0.0:*                   LISTEN      -
tcp        0      0 10.94.3.58:7403             0.0.0.0:*                   LISTEN      29750/java
tcp        0      0 0.0.0.0:875                 0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:7788                0.0.0.0:*                   LISTEN      7546/httpd.worker




2nd lsof -i :[port] Sometimes you need to know which processes are using some port (listening and connecting)..
#/home/oracle> lsof -i :1521
COMMAND     PID   USER   FD   TYPE    DEVICE SIZE/OFF NODE NAME
java       8192 oracle  527u  IPv4 472820831      0t0  TCP host1.subhost.net.intra:54520->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java       8192 oracle  546u  IPv4    285555      0t0  TCP host1.subhost.net.intra:11194->orafgrid001b-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java       8192 oracle  569u  IPv4    300752      0t0  TCP host1.subhost.net.intra:25746->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java       8192 oracle  570u  IPv4    300760      0t0  TCP host1.subhost.net.intra:25750->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java       8192 oracle  571u  IPv4    300762      0t0  TCP host1.subhost.net.intra:25754->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
tnslsnr   29937 oracle   15u  IPv4    183934      0t0  TCP host1.subhost.net.intra:ncube-lm (LISTEN)
tnslsnr   29937 oracle   16u  IPv4    183954      0t0  TCP oragrid001a-vip.eu.net.intra:ncube-lm (LISTEN)
tnslsnr   29937 oracle   18u  IPv4    209995      0t0  TCP oragrid001a-vip.eu.net.intra:ncube-lm->oragrid001a-vip.eu.net.intra:10928 (ESTABLISHED)
java      31128 oracle  552u  IPv4    125753      0t0  TCP host1.subhost.net.intra:24848->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      31128 oracle  574u  IPv4 472509952      0t0  TCP host1.subhost.net.intra:39550->orafgrid001b-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      31128 oracle  651u  IPv4    162963      0t0  TCP host1.subhost.net.intra:24938->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      31128 oracle  652u  IPv4    163028      0t0  TCP host1.subhost.net.intra:24942->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      31128 oracle  653u  IPv4    163076      0t0  TCP host1.subhost.net.intra:24946->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
sqlplus   33547 oracle   11u  IPv4 473348916      0t0  TCP host1.subhost.net.intra:29233->eurvlid07754.xmp.net.intra:ncube-lm (ESTABLISHED)
asm_lreg_ 34317 oracle   15u  IPv4    209994      0t0  TCP oragrid001a-vip.eu.net.intra:10928->oragrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
tnslsnr   36996 oracle   16u  IPv4    161690      0t0  TCP oragrid001-scan.eu.net.intra:ncube-lm (LISTEN)
java      42231 oracle  489u  IPv4    179933      0t0  TCP host1.subhost.net.intra:25120->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle  505u  IPv4 473421262      0t0  TCP host1.subhost.net.intra:55370->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle  513u  IPv4 472706528      0t0  TCP host1.subhost.net.intra:54362->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle  514u  IPv4    187161      0t0  TCP host1.subhost.net.intra:25148->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle  515u  IPv4    187171      0t0  TCP host1.subhost.net.intra:25152->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1682u  IPv4    210844      0t0  TCP host1.subhost.net.intra:10756->orafgrid001b-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1684u  IPv4    579691      0t0  TCP host1.subhost.net.intra:26030->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1685u  IPv4    209997      0t0  TCP host1.subhost.net.intra:10706->orafgrid001b-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1687u  IPv4 471344697      0t0  TCP host1.subhost.net.intra:52044->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1688u  IPv4    210793      0t0  TCP host1.subhost.net.intra:10748->orafgrid001b-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1689u  IPv4    210347      0t0  TCP host1.subhost.net.intra:10714->orafgrid001b-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1690u  IPv4    210349      0t0  TCP host1.subhost.net.intra:10718->orafgrid001b-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1691u  IPv4    210366      0t0  TCP host1.subhost.net.intra:10722->orafgrid001b-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1692u  IPv4    210376      0t0  TCP host1.subhost.net.intra:10726->orafgrid001b-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1693u  IPv4    210380      0t0  TCP host1.subhost.net.intra:10732->orafgrid001b-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1694u  IPv4    210381      0t0  TCP host1.subhost.net.intra:10734->orafgrid001b-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1695u  IPv4 472986697      0t0  TCP host1.subhost.net.intra:54744->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1696u  IPv4    210874      0t0  TCP host1.subhost.net.intra:25302->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1697u  IPv4    210886      0t0  TCP host1.subhost.net.intra:25306->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1698u  IPv4 473076086      0t0  TCP host1.subhost.net.intra:54850->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1699u  IPv4 473475031      0t0  TCP host1.subhost.net.intra:40890->orafgrid001b-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1700u  IPv4 468459341      0t0  TCP host1.subhost.net.intra:32748->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1701u  IPv4 454724739      0t0  TCP host1.subhost.net.intra:56479->orafgrid001b-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1702u  IPv4 472593175      0t0  TCP host1.subhost.net.intra:39668->orafgrid001b-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1705u  IPv4    584291      0t0  TCP host1.subhost.net.intra:26044->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1707u  IPv4 471521693      0t0  TCP host1.subhost.net.intra:52514->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1709u  IPv4   4660931      0t0  TCP host1.subhost.net.intra:29418->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1711u  IPv4 470340890      0t0  TCP host1.subhost.net.intra:35876->orafgrid001b-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1713u  IPv4 473251848      0t0  TCP host1.subhost.net.intra:55122->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1714u  IPv4    591417      0t0  TCP host1.subhost.net.intra:26078->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1717u  IPv4    223373      0t0  TCP host1.subhost.net.intra:10872->orafgrid001b-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1722u  IPv4    225369      0t0  TCP host1.subhost.net.intra:25432->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
java      42231 oracle 1723u  IPv4    225370      0t0  TCP host1.subhost.net.intra:25434->orafgrid001a-vip.eu.net.intra:ncube-lm (ESTABLISHED)
sqlplus   45751 oracle   11u  IPv4 465613441      0t0  TCP host1.subhost.net.intra:60011->ora130b-vip.uk.net.intra:ncube-lm (ESTABLISHED)
sqlplus   46702 oracle   11u  IPv4 468364749      0t0  TCP host1.subhost.net.intra:39335->macvlid02210.xmp.net.intra:ncube-lm (ESTABLISHED)




3th fuser [port]/tcp with fuser [port]/tcp you will get only processes listening on some port:
#/home/oracle >fuser 1521/tcp
1521/tcp:            29937 36996
oracle@host1:(NONE:/home/oracle)>ps -ef | grep 29937
oracle   11577 16360  0 10:39 pts/25   00:00:00 grep 29937
oracle   29937     1  0 Aug06 ?        00:00:04 /oracle/grid/12.1.0.2/bin/tnslsnr LISTENER -inherit
oracle@host1:(NONE:/home/oracle)>ps -ef | grep 36996
oracle   14021 16360  0 10:39 pts/25   00:00:00 grep 36996
oracle   36996     1  0 Aug06 ?        00:00:04 /oracle/grid/12.1.0.2/bin/tnslsnr LISTENER_SCAN1 -no_crs_notify -inherit
oracle@host1:(NONE:/home/oracle)>


4th lsof -Pan -p [PID] -i with "lsof -Pan -p [PID] -i·" you will get all ports used by a PID
oracle@host1:(NONE:/home/oracle)>lsof -Pan -p 36996 -i
COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
tnslsnr 36996 oracle   13u  IPv4 159717      0t0  TCP 127.0.0.1:62668->127.0.0.1:6100 (ESTABLISHED)
tnslsnr 36996 oracle   15u  IPv4 161039      0t0  TCP 192.254.38.186:24086 (LISTEN)
tnslsnr 36996 oracle   16u  IPv4 161690      0t0  TCP 10.11.3.69:1521 (LISTEN)

Comments

Popular posts from this blog

Oracle Historical Session Information with ASH >10g

Purging and archiving Oracle alert.log and listener.log

Check sessions and processes limits in Oracle