1831170 Members
2671 Online
110021 Solutions
New Discussion

port usage

 
SOLVED
Go to solution
navin
Super Advisor

port usage

Hello ,

Can you please let me know ..how can we find out an active port ...i need to verify if a particular port is free ...i tried using
netstat -a|grep port
it did not return anything - does that mean the port that i greped was free - and able to make use of it .
pls advice
thanks
Learning ...
5 REPLIES 5
Steven Schweda
Honored Contributor
Solution

Re: port usage

> netstat -a|grep port

Did you actually use "port", or did you
specify some port number or service name?

Are you hiding important details only to make
this stuff more difficult, or did you have
some valid reason?

If you're looking for a number, then you
might do better with:

netstat -an

> ...i need to verify if a particular port is
> free [...]

Which "a particular port"? Why? Normally,
if you try to use a port which is already in
use, someone complains.

> [...] does that mean [...]

If I could see what you actually did, then I
might be able to tell you what it actually
means. Sadly, my psychic powers are very
weak.
Doug O'Leary
Honored Contributor

Re: port usage

Hey;

netstat -an | grep ${port}

is the right command. The -n option will circumvent dns lookups.

netstat -an | grep " 22 "

for instance, will show you the sshd daemon.

Another option is lsof although that doesn't come with the generic OS. I believe you can download it from software.hp.com or from one of the porting centers.

lsof -i :22

will show all the processes that are using port 22. It's a bit better than the netstat option, but, if you don't have lsof, your options are obviously somewhat limited...

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
navin
Super Advisor

Re: port usage

i need to use the port 9876 - once i grep it from netstat -an |grep -i 9876 - if it does not return anything - i'm safe to use that port right.
thanks
Learning ...
Michal Kapalka (mikap)
Honored Contributor

Re: port usage

hi

i need to use the port 9876 - once i grep it from netstat -an |grep -i 9876 - if it does not return anything - i'm safe to use that port right.

yes it should be possible to assign the port for your purpose.

mikap
Steven Schweda
Honored Contributor

Re: port usage

> [...] i'm safe to use that port right.

Well, no one else is using it now. If that
means "safe", then you're safe.