Get Used Port List

Hi All-

How to get used port list in UNIX?

Thanks,
Mani Muthu

What is a "Used Port List"?
Can you give an example?

You would be best to look at the output from netstat (and the man pages) and also a read through /etc/services for registered ports on your server.

Does that help?

Robin

Thanks Robin,
I am using 'netstat -an'

Glad it helped, but I must wonder why you're looking. Not that I need to know, but if there is a good reason to be trying to trace where things are coming in from, there is a free tool called lsof (originally LiSt Open Files) that is good for this sort of thing. See

http://uk.ask.com/wiki/Lsof

for a pointer on that.

I have used it when I have found a remote oracle process chewing up CPU. The first thing I would do is

lsof -o -p $suspect_process

... and it lists out the open files and TCP/IP ports. You can see (like netstat output) where the other end of the connection is. That helped track many things down, but some were started on the local machine but directed as thgouh they were remote, so the next trick was (knowning the oracle port was 1521)

lsof -i tcp:$source_port

and putting in the opposing port to 1521. That would return the process I started with and the source process of the TCP connection. it may be an iterative process, but it's great for tracing. Of course, it's real-time, so if the connection closes before you finish, you lose it.

Robin