Operating System - HP-UX
1822899 Members
3543 Online
109645 Solutions
New Discussion юеВ

is there a command to show ports being used

 
mike worrell
Regular Advisor

is there a command to show ports being used

Does anyone know if there is a command to see
which ports are being used on a unix server and how to kill the process/service using that port?
Thanx
MIke
11 REPLIES 11
harry d brown jr
Honored Contributor

Re: is there a command to show ports being used

LSOF

http://hpux.asknet.de/hppd/hpux/Sysadmin/lsof-4.55/


live free or die
harry
Live Free or Die
A. Clay Stephenson
Acclaimed Contributor

Re: is there a command to show ports being used

netstat -a can help but the very best tool is lsof; it's one of those that no admin should be without. You can download it from any of the HP-UX Porting Centre's. The last time I looked only the 32-bit version was available for 11x. If you need 64-bit 11x, you will have to download the source and compile/link it. That's easy too.

If it ain't broke, I can fix that.
Sridhar Bhaskarla
Honored Contributor

Re: is there a command to show ports being used

There is no default command that maps ports and the attached processes. You can use lsof to get this information. Available free.

http://hpux.cs.utah.edu/hppd/hpux/Sysadmin/lsof-4.55/

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Kofi ARTHIABAH
Honored Contributor

Re: is there a command to show ports being used

Mike: the tool you want is lsof - which is available at http://hpux.cs.utah.edu/hppd/hpux/Sysadmin/lsof-4.55/

once you install and run it you can find what process is holding what port open

netstat -a gives you a quick look-see of what port/sockets are in use.
nothing wrong with me that a few lines of code cannot fix!
Deshpande Prashant
Honored Contributor

Re: is there a command to show ports being used

HI
Besides netstat -a the utility you will need is "lsof"

Thanks.
Prashant.
Take it as it comes.
Sanjay_6
Honored Contributor

Re: is there a command to show ports being used

Hi Mike,

Use "netstat -an" to list all ports being used. you can also use lsof as advised above,

Here is the "lsof" FAQ,

ftp://vic.cc.purdue.edu/pub/tools/unix/lsof/FAQ

You can download lsof from this site,

http://www-rcd.cc.purdue.edu/~abe/

Hope this helps.

Regds
Uday_S_Ankolekar
Honored Contributor

Re: is there a command to show ports being used

hi,

/etc/services file actullay the reference file for all the assigned port and service
Typical services entries are of the form:

SERVNAME PORT/PROTO

From /var/adm/inetd.sec file you can control the access to any services .

Like every one said get lsof. It's a good tool to have.

-USA..
Good Luck..
mike worrell
Regular Advisor

Re: is there a command to show ports being used

thanx everyone, the netstat -an was helpful enough
Santanu Bhadra
Advisor

Re: is there a command to show ports being used

Hi all,

I got the file lsof-4.55-sd-11.00.depot.gz
from the website mentioned earlier. i run
gunzip on it to get lsof-4.55-sd-11.00.depot

Then I run the following to install lsof.
#swinstall -s /tmp/lsof-4.55-sd-11.00.depot

When I run swlist, it shows lsof4.55 installed.

But when I run "lsof -ou username", it pops up
"/sbin/sh: lsof not found".

Can you guys please suggest me the way out?

Thanks in advance!

Santanu
Work hard and be realistically optimistic.
Kofi ARTHIABAH
Honored Contributor

Re: is there a command to show ports being used

Santanu - I suspect that is because /opt/lsof/bin is not on your $PATH try this:

# PATH=$PATH:/opt/lsof/bin
and then
# lsof

that should work... you might want to include it in your /etc/PATH file.

good luck
nothing wrong with me that a few lines of code cannot fix!
Santanu Bhadra
Advisor

Re: is there a command to show ports being used

Kofi,

You are correct. I got it working.

Thanks
Santanu
Work hard and be realistically optimistic.