Find out which port the daemon is using on AIX OS. (similar like command netstat -anp for Linux)

How to find which port TCP or UDP are being used by daemons on AIX OS.

For TCP protocol:

netstat -Aan |grep -E "\*.[0-9].+LISTEN" |awk  '{print $1, substr($5,3)}' |while read socket port
do
  echo "TCP Ports: " $port "--->" $(rmsock $socket tcpcb | grep held | awk -F'proccess|\\(|\\)' '{print "PID:", $2, "CMD:", $3}')
done

See an example:

(aix61):[root] /-> netstat -Aan |grep -E "\*.[0-9].+LISTEN" |awk  '{print $1, substr($5,3)}' |while read socket port
> do
>   echo "TCP Ports: " $port "--->" $(rmsock $socket tcpcb | grep held | awk -F'proccess|\\(|\\)' '{print "PID:", $2, "CMD:", $3}')
> done
TCP Ports:  22 ---> PID: 2883734 CMD: sshd
TCP Ports:  22 ---> PID: 2883734 CMD: sshd
TCP Ports:  23 ---> PID: 4194332 CMD: inetd
TCP Ports:  80 ---> PID: 4260016 CMD: httpd
TCP Ports:  111 ---> PID: CMD:
TCP Ports:  199 ---> PID: 6095056 CMD: snmpdv3ne
TCP Ports:  443 ---> PID: 4260016 CMD: httpd
TCP Ports:  513 ---> PID: 4194332 CMD: inetd
TCP Ports:  514 ---> PID: 4194332 CMD: inetd
TCP Ports:  515 ---> PID: 3735700 CMD: lpd
TCP Ports:  657 ---> PID: 3801282 CMD: rmcd
TCP Ports:  2049 ---> PID: CMD:
TCP Ports:  3901 ---> PID: 3145864 CMD: nimsh
TCP Ports:  5666 ---> PID: 4194332 CMD: inetd
TCP Ports:  6174 ---> PID: 15138912 CMD: clinfo
TCP Ports:  6181 ---> PID: 4194332 CMD: inetd
TCP Ports:  6191 ---> PID: 5046478 CMD: clcomd
TCP Ports:  32768 ---> PID: CMD:
TCP Ports:  32769 ---> PID: CMD:
TCP Ports:  32771 ---> PID: CMD:
TCP Ports:  32778 ---> PID: 6095056 CMD: snmpdv3ne
TCP Ports:  16191 ---> PID: 5046478 CMD: clcomd
TCP Ports:  42112 ---> PID: CMD:

For UDP protocol:

netstat -Aan |grep -E "udp.+\*.[0-9]" |awk  '{print $1, substr($5,3)}' |while read socket port
do
  echo "UDP Ports: " $port "--->" $(rmsock $socket inpcb | grep held | awk -F'proccess|\\(|\\)' '{print "PID:", $2, "CMD:", $3}')
done

See an example:

(aix61):[root] /->  netstat -Aan |grep -E "udp.+\*.[0-9]" |awk  '{print $1, substr($5,3)}' |while read socket port
> do
>   echo "UDP Ports: " $port "--->" $(rmsock $socket inpcb | grep held | awk -F'proccess|\\(|\\)' '{print "PID:", $2, "CMD:", $3}')
> done
UDP Ports:  111 ---> PID: CMD:
UDP Ports:  123 ---> PID: 2556010 CMD: xntpd
UDP Ports:  161 ---> PID: 6095056 CMD: snmpdv3ne
UDP Ports:  514 ---> PID: 4128792 CMD: syslogd
UDP Ports:  657 ---> PID: 3801282 CMD: rmcd
UDP Ports:  2049 ---> PID: CMD:
UDP Ports:  2279 ---> PID: 4194332 CMD: inetd
UDP Ports:  54358 ---> PID: 15138912 CMD: clinfo
UDP Ports:  54359 ---> PID: 15138912 CMD: clinfo
UDP Ports:  6179 ---> PID: 8192182 CMD: hagsd
UDP Ports:  32773 ---> PID: CMD:
UDP Ports:  32793 ---> PID: CMD:
UDP Ports:  32794 ---> PID: CMD:
UDP Ports:  32795 ---> PID: CMD:
UDP Ports:  32833 ---> PID: CMD:
UDP Ports:  32918 ---> PID: 4128792 CMD: syslogd
UDP Ports:  32934 ---> PID: 4128792 CMD: syslogd

Just thanks if the post was helpful

0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
AIX oslevel version OS
Viewed 4864 times since Wed, Apr 17, 2019
Authenticate AIX using MS DC’s kerberos servers (Active Directory)
Viewed 2148 times since Thu, Feb 21, 2019
n a perfect world....rootvg would always reside on hdisk0
Viewed 2243 times since Thu, Jun 6, 2019
How to build a NIM Server on AIX 6.1 from the Scratch :: Part 1
Viewed 4925 times since Thu, Nov 29, 2018
AIX HA / HACMP, System Admin↑ Mountguard
Viewed 6681 times since Mon, Jun 3, 2019
Trick to Purge/Clean Swap Usage on AIX
Viewed 7873 times since Thu, Nov 29, 2018
AIX, Monitoring, System Admin↑ NMON recordings
Viewed 2969 times since Fri, Apr 19, 2019
0516-404 allocpThis system cannot fulfill the allocation
Viewed 10038 times since Thu, Sep 20, 2018
Changing ’defined’ or ’missing’ hard disk states to ’Available’ in IBM Smart Analytics System for AIX environment
Viewed 2369 times since Thu, Sep 20, 2018
Mirroring the rootvg Volume Group for AIX 4.1/4.2
Viewed 3045 times since Mon, May 21, 2018