Mat*_*t C 9 networking linux netstat
我对这个命令感到疯狂netstat。
在 man 中我们可以读到,在 Active Internet Connections (TCP, UDP, raw) 的输出中,我们应该有:
User :套接字所有者的用户名或用户 ID (UID)。
但是当我这样做时
netstat -natp
Run Code Online (Sandbox Code Playgroud)
我的输出没有显示任何所有者(或 UID)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:4713 0.0.0.0:* LISTEN 2159/pulseaudio
(...)
Run Code Online (Sandbox Code Playgroud)
并且我在 man 中看不到任何选项来显示 PID 的所有者。
有--numeric-users 选择,但它不会改变任何东西。
有什么我想念的吗?还是 netstat 有问题?
还有其他方法可以获取这些信息吗?
谢谢你的帮助 :)
小智 17
使用netstat -natpe.
从手册页:
-e, --extend
Display additional information. Use this option twice for maximum detail.
Run Code Online (Sandbox Code Playgroud)
清澈如泥。
这将在显示中添加两列 User 和 Inode。
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 100 13119 1901/mysqld
Run Code Online (Sandbox Code Playgroud)
或者,您可以使用lsof -iwhich 向您显示用户。
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 32500 apache 4u IPv6 14390 0t0 TCP *:http (LISTEN)
httpd 32501 apache 4u IPv6 14390 0t0 TCP *:http (LISTEN)
httpd 32502 apache 4u IPv6 14390 0t0 TCP *:http (LISTEN)
httpd 32503 apache 4u IPv6 14390 0t0 TCP *:http (LISTEN)
Run Code Online (Sandbox Code Playgroud)