Finding port number !!

Hi all ,

I want know the port no on which a particular application is running.

How to find that?

Thanks in anticipation

If you have lsof, that is often a good tool for this.

Try using lsof. lsof -i | grep -i listen should get what you're looking for. You may also grep for a pid or port number too if you're looking for something specific.
What does port number [whatever] mean?

I tried location the same in different post and got couple of answer also as user

  1. I am using Solaris 10 - Solaris 10 5/08 s10s_u5wos_10 SPARC
  2. i am unable to get the above command

I did tried and got the output, now I am confused . While executing

I got below as output

Which is port number in above ?

Thanks Guys

I do not have lsof , is this is a part of some add on package ?

Actually ".telnet" is the "port number". You can look up the numeric port number in /etc/services

LISTEN is the server which is running all the time and accepting incoming connections.

Thanks era,

Please tell me what is the difference between /etc/services port number and the one I am getting through nestata �a

and

There is no "difference", there is a "relationship". netstat consults /etc/services and uses the label it finds there if you don't explicitly ask it to show raw port numbers always (with the -n option, in my version of netstat).

basically, you can define what you want your port number to be called as defined in /etc/services. when you run netstat -a you will see this output with what is defined in /etc/services. if you run netstat -n you will not consult the /etc/services and just display port numbers.

Output with my apache server undefined in /etc/services:

#netstat -a
... 

TCP: IPv4
   Local Address        Remote Address    Swind Send-Q Rwind Recv-Q    State
-------------------- -------------------- ----- ------ ----- ------ -----------
      *.*                  *.*                0      0 49152      0 IDLE
      *.3306               *.*                0      0 49152      0 LISTEN
      *.80                 *.*                0      0 49152      0 LISTEN  

...

Look at the *.80 . this is my apache web server. now i will define it in /etc/services and make sure its tab delimited.

#vi /etc/services
...
bootpc          68/udp                          # BOOTP/DHCP client
apache          80/tcp          apache          # Apache webserver <--- here
kerberos        88/udp          kdc             # Kerberos V5 KDC
kerberos        88/tcp          kdc             # Kerberos V5 KDC
...

new output of netstat -a

# netstat -a
...

TCP: IPv4
   Local Address        Remote Address    Swind Send-Q Rwind Recv-Q    State
-------------------- -------------------- ----- ------ ----- ------ -----------
      *.*                  *.*                0      0 49152      0 IDLE
      *.3306               *.*                0      0 49152      0 LISTEN
      *.apache             *.*                0      0 49152      0 LISTEN
      *.*                  *.*                0      0 49152      0 IDLE
....

notice how *.80 has now turned into *.apache!

again, netstat -n will NOT consult /etc/services in its naming output.

hahah era beat me to it :smiley:

try this one: PCP - Show open ports and PIDs on Solaris

best regards
mutifo

1 Like

all the ports which need specifc to which protocol was mentioned in the /etc/services

if you need to add new ports to yur server you need to have the entry on this file..

#grep telnet /etc/services
telnet 23/tcp

this gave you that telnet connectio was comming thrugh port 23

netstat -a|grep telnet

gave all the telnet connection established and the ports listening to telnet connectionto the server

which means the telnet was working through the port 23 and which uses tcp

netstat -an

will gave yo all the connection to your server... :slight_smile:

1 Like