$ netstat --version
net-tools 1.60
netstat 1.42 (2001-04-15)
Fred Baumgarten, Alan Cox, Bernd Eckenfels, Phil Blundell, Tuan Hoang and others
+NEW_ADDRT +RTF_IRTT +RTF_REJECT +FW_MASQUERADE +I18N
AF: (inet) +UNIX +INET +INET6 +IPX +AX25 +NETROM +X25 +ATALK +ECONET +ROSE
HW: +ETHER +ARC +SLIP +PPP +TUNNEL -TR +AX25 +NETROM +X25 +FR +ROSE +ASH +SIT +FDDI +HIPPI +HDLC/LAPB +EUI64
$ netstat --wide --inet | head -5
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 192.168.1.11:38752 jl-in-f188.1e100.net:https ESTABLISHED
tcp 0 0 192.168.1.11:50882 lga15s44-in-f14.1e100.net:https ESTABLISHED
tcp 0 0 192.168.1.11:45874 151.101.1.69:https ESTABLISHED
根据我的 Ubuntu Linux 上的 netstat 手册页:
--numeric-ports
shows numerical port numbers but does not affect the resolution of host or user names.
然而,该选项似乎也会影响主机名的解析。
$ netstat --wide --inet --numeric-ports | head -5
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 192.168.1.11:38752 209.85.200.188:443 ESTABLISHED
tcp 0 0 192.168.1.11:50882 172.217.1.78:443 ESTABLISHED
tcp 0 0 192.168.1.11:45874 151.101.1.69:443 ESTABLISHED
我希望看到主机名和端口号。
答案1
我有net-tools 1.60_p20170221182432
(Gentoo)并且它按照文档工作,因此您拥有的版本中可能存在错误。如果可用ss
,您可以使用以下命令获得非常相似的结果ss -4rn
(-4
:仅限 IPv4、:-r
解析名称、-n
:数字服务号码);区别在于数据的显示顺序和一些格式细节。