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 POWERHA/HACMP: Basic commands
Viewed 5219 times since Sat, Jun 2, 2018
HMC: HMC and LPAR management commands
Viewed 7003 times since Sun, Jun 3, 2018
AIX NTP Client configuration
Viewed 11806 times since Tue, Jul 17, 2018
AIX, Storage, System Admin↑ Identifying a Disk Bottleneck Using filemon
Viewed 9758 times since Fri, Apr 19, 2019
Customizing a NIM Client Restore With a Post-Install Script
Viewed 10841 times since Wed, May 30, 2018
How to Investigate a System Reboot
Viewed 4468 times since Mon, Jul 16, 2018
How to setup an user in AIX
Viewed 3053 times since Mon, May 28, 2018
AIX QHA
Viewed 10970 times since Mon, Jun 3, 2019
Check connection (rsh or nimsh) between NIM server and LPAR
Viewed 10154 times since Thu, Feb 21, 2019
Processes and Devices—It’s All About the Children
Viewed 2069 times since Wed, May 30, 2018