Why is the port listed only in the specific format of netstat?
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.
Related videos on Youtube
Jim
Updated on September 18, 2022Comments
-
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 portB
.
Problem:
When I donetstat -a |grep A
I do NOT see the port listed.
If I donetstat -antp
I see both portsA
andB
listed.What is the difference between the commands?
-
Jim about 12 yearsBut why is my port listed only in the second form?
-
David Schwartz about 12 yearsThat'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 about 12 years+1 Ah!Port
A
is8443
.How can I verify if it is transformed to a name? -
Creshal about 12 yearsgrep 8443 /etc/services – should be mapped to pcsync-https