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
SSH Essentials: Working with SSH Servers, Clients, and Keys
Viewed 3957 times since Wed, Jun 27, 2018
AIX: How to determine which application created the OS core file
Viewed 2190 times since Mon, Jun 11, 2018
ILMT Procedure - ILMT / TAD4D / SUA / BFI
Viewed 9833 times since Fri, Jul 5, 2019
How To Mirror Your Root Disk On AIX (a.k.a. rootvg)
Viewed 4786 times since Mon, May 21, 2018
How to upgrade TL and SP in AIX using alternate disk(alt_disk_copy)
Viewed 10340 times since Sun, Jun 30, 2019
Checking HBA status on AIX
Viewed 17280 times since Fri, Oct 5, 2018
AIX, Red Hat, Security, System Admin↑ System-wide separated shell history files for each user and session
Viewed 1995 times since Fri, Apr 19, 2019
AIX How to Investigate a System Reboot
Viewed 5966 times since Tue, Aug 14, 2018
Practical Guide to AIX - network
Viewed 17234 times since Thu, Sep 20, 2018
HMC: HMC and LPAR management commands
Viewed 6674 times since Sun, Jun 3, 2018