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
VIO Server Howto
Viewed 10071 times since Mon, Jun 11, 2018
AIX - How to get network speed and statistic of ethernet adapter in AIX
Viewed 13777 times since Fri, Jun 8, 2018
IBM V7000f Performance Test with Vdbench Tool on IBM AIX
Viewed 15976 times since Thu, Jan 23, 2020
Rootvg Mirroring in AIX
Viewed 2681 times since Mon, May 21, 2018
Part 1, Memory overview and tuning memory parameters AIX7
Viewed 4180 times since Wed, Jun 19, 2019
AIX Password expiry /etc/passwd
Viewed 18678 times since Wed, Jul 3, 2019
Getting bosboot errors, don’t reboot just yet
Viewed 2831 times since Tue, Apr 16, 2019
AIX - How to get IP and MAC address of ethernet adapter in AIX
Viewed 24975 times since Fri, Jun 8, 2018
Unlock User ID in IBM AIX
Viewed 15119 times since Mon, May 28, 2018
AIX Booting
Viewed 10248 times since Tue, Apr 16, 2019