Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have Tomcat and I am trying to bind to 2 specific ports (using custom connectors). E.g. port A and port B.
Problem:
When I do netstat -a |grep A I do NOT see the port listed.
If I do netstat -antp I see both ports A and B listed.

What is the difference between the commands?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

The -n option is the difference. Without it, netstat converts well-known ports such as 3306 and 80 into names such as mysql and http.

If A is a well-known port and B isn't, only one of your ports will be listed by the first command.

If a port is well-known, it should be listed in /etc/services.

share|improve this answer
    
+1 Ah!Port A is 8443.How can I verify if it is transformed to a name? –  Jim Mar 27 '12 at 8:34
2  
grep 8443 /etc/services – should be mapped to pcsync-https –  Creshal Mar 27 '12 at 8:45

By specifying -n you tell netstat to use the port number instead of the service name. If you look at the output of netstat -a you will see that the port numbers are instead human-readable service names. These are mapped from /etc/services, so if you are listening on port 80 you will see *:http or hostname:http, and if you are listening on port 8080 you will see *:webcache or hostname:webcache.

From the netstat man page on Fedora 16:

  --numeric , -n
       Show  numerical addresses instead of trying to determine symbolic host,
       port or user names.
share|improve this answer
    
But why is my port listed only in the second form? –  Jim Mar 27 '12 at 8:29
2  
That's what netstat does. By default, it tries to show human-readable ports (unless you specify -n). When it succeeds, the port number does not appear in the output. –  David Schwartz Mar 27 '12 at 8:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.