Lsof show listening ports and processes
From AIXWiki
Show all running processes using lsof
How can I find out which process is listening on which port?
Type the following command to see IPv4 port(s), enter:
lsof -Pnl +M -i4
Type the following command to see IPv6 listing port(s), enter:
lsof -Pnl +M -i6
Example output
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME rslgsend 90136 800 6u IPv4 0xf100020004f1c800 0t0 UDP *:3700 db2sysc 131280 203 48u IPv4 0xf1000200059b9398 0t0 TCP *:523 (LISTEN) db2sysc 131280 203 49u IPv4 0xf100020004e0ae00 0t0 UDP *:523 disp+work 155790 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 msg_serve 164018 800 6u IPv4 0xf100020004f17398 0t0 TCP *:3600 (LISTEN) db2sysc 176322 801 4u IPv4 0xf100020005a11398 0t0 TCP *:5912 (LISTEN) disp+work 204980 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 disp+work 204980 800 7u IPv4 0xf100020004fae600 0t0 UDP 127.0.0.1:3200 disp+work 204980 800 8u IPv4 0xf100020006ff2b98 0t0 TCP *:3200 (LISTEN) db2sysc 208930 203 49u IPv4 0xf100020004e0ae00 0t0 UDP *:523 gwrd 213070 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 gwrd 213070 800 9u IPv4 0xf100020005291b98 0t0 TCP *:3300 (LISTEN) gwrd 213070 800 11u IPv4 0xf100020004de3800 0t0 UDP 127.0.0.1:42822->127.0.0.1:3200 disp+work 221328 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 disp+work 225336 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 db2sysc 229614 801 4u IPv4 0xf100020005a11398 0t0 TCP *:5912 (LISTEN) igsmux_mt 233706 800 9u IPv4 0xf100020006c83398 0t0 TCP *:40080 (LISTEN) igsmux_mt 233706 800 11u IPv4 0xf100020006fbb398 0t0 TCP *:40000 (LISTEN) igspw_mt 262384 800 6u IPv4 0xf1000200059a9b98 0t0 TCP *:40002 (LISTEN) disp+work 266398 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 disp+work 270520 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 sapstarts 286758 800 6u IPv4 0xf100020005a0eb98 0t0 TCP *:50013 (LISTEN) disp+work 299124 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 disp+work 319726 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 sshd 331966 0 3u IPv4 0xf100020005940398 0t0 TCP *:22 (LISTEN) disp+work 352452 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 db2sysc 356534 203 48u IPv4 0xf1000200059b9398 0t0 TCP *:523 (LISTEN) db2sysc 356534 203 49u IPv4 0xf100020004e0ae00 0t0 UDP *:523 disp+work 360634 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 db2sysc 409806 203 49u IPv4 0xf100020004e0ae00 0t0 UDP *:523 disp+work 413888 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 sshd 426068 1171791 3u IPv4 0xf100020004f14b98 0t429041 TCP 10.101.2.2:22->10.101.0.92:51911 (ESTABLISHED) db2sysc 430296 203 48u IPv4 0xf1000200059b9398 0t0 TCP *:523 (LISTEN) db2sysc 430296 203 49u IPv4 0xf100020004e0ae00 0t0 UDP *:523 db2sysc 434394 203 48u IPv4 0xf1000200059b9398 0t0 TCP *:523 (LISTEN) db2sysc 434394 203 49u IPv4 0xf100020004e0ae00 0t0 UDP *:523 db2sysc 438494 203 48u IPv4 0xf1000200059b9398 0t0 TCP *:523 (LISTEN) db2sysc 438494 203 49u IPv4 0xf100020004e0ae00 0t0 UDP *:523 db2sysc 442592 203 48u IPv4 0xf1000200059b9398 0t0 TCP *:523 (LISTEN) db2sysc 442592 203 49u IPv4 0xf100020004e0ae00 0t0 UDP *:523 db2sysc 446692 203 48u IPv4 0xf1000200059b9398 0t0 TCP *:523 (LISTEN) db2sysc 446692 203 49u IPv4 0xf100020004e0ae00 0t0 UDP *:523 db2sysc 450790 203 48u IPv4 0xf1000200059b9398 0t0 TCP *:523 (LISTEN) db2sysc 450790 203 49u IPv4 0xf100020004e0ae00 0t0 UDP *:523 db2sysc 463086 203 48u IPv4 0xf1000200059b9398 0t0 TCP *:523 (LISTEN) db2sysc 463086 203 49u IPv4 0xf100020004e0ae00 0t0 UDP *:523 rmcd 475374 0 3u IPv4 0xf100020004575e00 0t0 UDP *:657 rmcd 475374 0 4u IPv4 0xf100020004e0d600 0t0 UDP *:* rmcd 475374 0 16u IPv4 0xf1000200059b8b98 0t0 TCP *:657 (LISTEN) disp+work 495622 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 hostmibd6 499720 0 4u IPv4 0xf100020006229c00 0t0 UDP *:50351 inetd 503812 0 9u IPv4 0xf100020004e07600 0t0 UDP *:518 inetd 503812 0 12u IPv4 0xf100020005955398 0t0 TCP *:9090 (LISTEN) inetd 503812 0 14u IPv4 0xf100020004e1ca00 0t0 UDP *:2279 syslogd 507930 0 4u IPv4 0xf10002000456b000 0t0 UDP *:514 disp+work 544904 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 writesrv 606286 0 3u IPv4 0xf100020005950b98 0t0 TCP *:1334 (LISTEN) disp+work 639182 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 disp+work 655446 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 igspw_mt 659654 800 7u IPv4 0xf1000200057aeb98 0t0 TCP *:40001 (LISTEN) disp+work 712746 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 disp+work 716888 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 disp+work 766154 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 icman 774370 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 icman 774370 800 9u IPv4 0xf100020007195398 0t0 TCP *:65000 (LISTEN) icman 774370 800 11u IPv4 0xf100020005a49600 0t0 UDP 127.0.0.1:64999 icman 774370 800 12u IPv4 0xf100020005a58e00 0t0 UDP 127.0.0.1:42815->127.0.0.1:64999 icman 774370 800 13u IPv4 0xf100020004fa9c00 0t0 UDP 127.0.0.1:42816->127.0.0.1:3200 icman 774370 800 14u IPv4 0xf100020006250e00 0t0 UDP 127.0.0.1:42817 icman 774370 800 15u IPv4 0xf1000200062c4200 0t0 UDP 127.0.0.1:42818->127.0.0.1:42817 icman 774370 800 16u IPv4 0xf1000200058c5398 0t0 TCP *:8080 (LISTEN) icman 774370 800 18u IPv4 0xf100020006218600 0t0 UDP 127.0.0.1:64998 icman 774370 800 19u IPv4 0xf10002000624d800 0t0 UDP 127.0.0.1:42819->127.0.0.1:64998 icman 774370 800 20u IPv4 0xf10002000626b398 0t0 TCP *:8025 (LISTEN) disp+work 778468 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 disp+work 782564 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 disp+work 794864 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 rslgcoll 798812 800 6u IPv4 0xf10002000626a200 0t0 UDP *:4000 rslgcoll 798812 800 7u IPv4 0xf100020004f0f398 0t0 TCP *:3900 (LISTEN) disp+work 815252 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 db2sysc 835694 801 4u IPv4 0xf100020005a11398 0t0 TCP *:5912 (LISTEN) disp+work 852082 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 db2sysc 860318 801 4u IPv4 0xf100020005a11398 0t0 TCP *:5912 (LISTEN) disp+work 868586 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 db2sysc 888926 801 4u IPv4 0xf100020005a11398 0t0 TCP *:5912 (LISTEN) disp+work 905424 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 disp+work 913516 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 disp+work 925914 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 disp+work 938200 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 disp+work 942292 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 disp+work 966896 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 disp+work 987370 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 disp+work 991466 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 db2sysc 1007808 801 4u IPv4 0xf100020005a11398 0t0 TCP *:5912 (LISTEN) disp+work 1036430 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 sshd 1204478 0 3u IPv4 0xf100020004f14b98 0t429041 TCP 10.101.2.2:22->10.101.0.92:51911 (ESTABLISHED) dsmc 1208496 0 5u IPv4 0xf100020005187398 0t0 TCP *:1501 (LISTEN) disp+work 1249372 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 db2sysc 1318914 801 4u IPv4 0xf100020005a11398 0t0 TCP *:5912 (LISTEN) disp+work 1351698 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 xntpd 1437704 0 4u IPv4 0xf100020006255600 0t0 UDP *:123 xntpd 1437704 0 5u IPv4 0xf100020006208c00 0t0 UDP 10.101.2.2:123 xntpd 1437704 0 6u IPv4 0xf100020004e07e00 0t0 UDP 127.0.0.1:123 xntpd 1437704 0 9u IPv4 0xf100020006209e00 0t0 UDP 10.101.2.255:123 xntpd 1437704 0 10u IPv4 0xf100020004568a00 0t0 UDP 127.255.255.255:123 dsmcad 1441832 0 5u IPv4 0xf10002000520c398 0t0 TCP *:64945 (LISTEN) dsmcad 1441832 0 6u IPv4 0xf10002000589ab98 0t0 TCP *:1581 (LISTEN) db2sysc 1454216 801 4u IPv4 0xf100020005a11398 0t0 TCP *:5912 (LISTEN) disp+work 1536178 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 disp+work 1548380 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200 disp+work 1572990 800 6u IPv4 0xf100020005a52400 0t0 UDP 127.0.0.1:42814->127.0.0.1:3200
Flag explanation
- -P : This option inhibits the conversion of port numbers to port names for network files. Inhibiting the conversion may make lsof run a little faster. It is also useful when port name lookup is not working properly.
- -n : This option inhibits the conversion of network numbers to host names for network files. Inhibiting conversion may make lsof run faster. It is also useful when host name lookup is not working properly.
- -l : This option inhibits the conversion of user ID numbers to login names. It is also useful when login name lookup is working improperly or slowly.
- +M : Enables the reporting of portmapper registrations for local TCP and UDP ports.
- -i4 : IPv4 listing only
- -i6 : IPv6 listing only
Different way to do the same
You can also use
lsof -i -n | egrep 'COMMAND|LISTEN'
