What processes are using which ports on unix?
Asked Answered
B

9

35

I need to find out what ports are attached to which processes on a Unix machine (HP Itanium). Unfortunately, lsof is not installed and I have no way of installing it.

Does anyone know an alternative method? A fairly lengthy Googling session hasn't turned up anything.

Balladry answered 24/9, 2008 at 8:20 Comment(2)
this depend of the unix used. what is it ?Crankcase
Similar, in Unix & Linux: What is using this network socket? (2010-08-10)Zionism
A
10

Assuming this is HP-UX? What about the Ptools - do you have those installed? If so you can use "pfiles" to find the ports in use by the application:

pfiles prints information about all open file descriptors of a process. If file descriptor corresponds to a file, then pfiles prints the fstat(2) and fcntl(2) information.

If the file descriptor corresponds to a socket, then pfiles prints socket related info, such as the socket type, socket family, and protocol family.

In the case of AF_INET and AF_INET6 family of sockets, information about the peer host is also printed.

for f in $(ps -ex | awk '{print $1}'); do echo $f; pfiles $f | grep PORTNUM; done

switch PORTNUM for the port number. :) may be child pid, but gets you close enough to identify the problem app.

Arin answered 25/9, 2008 at 20:37 Comment(0)
P
44

netstat -l (assuming it comes with that version of UNIX)

Poland answered 24/9, 2008 at 8:21 Comment(0)
D
28

Given (almost) everything on unix is a file, and lsof lists open files...

Linux : netstat -putan or lsof | grep TCP

OSX : lsof | grep TCP

Other Unixen : lsof way...

Dowry answered 24/9, 2008 at 8:26 Comment(0)
S
13
netstat -pln

EDIT: linux only, on other UNIXes netstat may not support all these options.

Salina answered 24/9, 2008 at 8:31 Comment(0)
A
10

Assuming this is HP-UX? What about the Ptools - do you have those installed? If so you can use "pfiles" to find the ports in use by the application:

pfiles prints information about all open file descriptors of a process. If file descriptor corresponds to a file, then pfiles prints the fstat(2) and fcntl(2) information.

If the file descriptor corresponds to a socket, then pfiles prints socket related info, such as the socket type, socket family, and protocol family.

In the case of AF_INET and AF_INET6 family of sockets, information about the peer host is also printed.

for f in $(ps -ex | awk '{print $1}'); do echo $f; pfiles $f | grep PORTNUM; done

switch PORTNUM for the port number. :) may be child pid, but gets you close enough to identify the problem app.

Arin answered 25/9, 2008 at 20:37 Comment(0)
S
6
netstat -ln | awk '/^(tcp|udp)/ { split($4, a, /:/); print $1, a[2]}' | sort -u

gives you the active tcp/udp ports. Then you can use the ports with fuser -n tcp or fuser -n udp, as root, and supposing that fuser is GNU fuser or has similar options.

If you need more help, let me know.

Sill answered 24/9, 2008 at 8:43 Comment(0)
E
3

I use this command:

netstat -tulpn | grep LISTEN

You can have a clean output that shows process id and ports that's listening on

Exine answered 31/1, 2019 at 14:29 Comment(1)
was going to answer the same, thanks that you've already posted this :)Solange
H
2

Try pfiles PID to show all open files for a process.

Hakon answered 24/9, 2008 at 8:24 Comment(0)
A
1

Which process uses port in unix;

1. netstat -Aan | grep port

root> netstat -Aan | grep 3872

output> f1000e000bb5c3b8 tcp 0 0 *.3872 . LISTEN

2. rmsock f1000e000bb5c3b8 tcpcb

output> The socket 0xf1000e000bb5c008 is being held by proccess 13959354 (java).

3. ps -ef | grep 13959354

Apportionment answered 17/6, 2015 at 10:5 Comment(0)
R
0

If you want to know all listening ports along with its details: local address, foreign address and state as well as Process ID (PID). You can use following command for it in linux.

 netstat -tulpn
Roller answered 12/3, 2019 at 5:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.