Why is the port listed only in the specific format of netstat?

6,256

Solution 1

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.

Solution 2

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:
6,256

Related videos on Youtube

Jim
Author by

Jim

Updated on September 18, 2022

Comments

  • Jim
    Jim over 1 year

    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?

  • Jim
    Jim about 12 years
    But why is my port listed only in the second form?
  • David Schwartz
    David Schwartz about 12 years
    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.
  • Jim
    Jim about 12 years
    +1 Ah!Port A is 8443.How can I verify if it is transformed to a name?
  • Creshal
    Creshal about 12 years
    grep 8443 /etc/services – should be mapped to pcsync-https