如何找到哪个服务正在使用端口?
# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.6 (Maipo)
# netstat -natpv | grep 9090
tcp6 0 0 :::9090 :::* LISTEN 1/systemd
#
请指教。
# systemctl status cockpit.service
● cockpit.service - Cockpit Web Service
Loaded: loaded (/usr/lib/systemd/system/cockpit.service; static; vendor preset: disabled)
Active: inactive (dead) since Mon 2019-06-10 12:43:51 EDT; 4 days ago
Docs: man:cockpit-ws(8)
Main PID: 15922 (code=exited, status=0/SUCCESS)
Jun 10 12:41:48 X.X.X systemd[1]: Starting Cockpit Web Service...
Jun 10 12:41:48 X.X.X systemd[1]: Started Cockpit Web Service.
Jun 10 12:41:48 X.X.X cockpit-ws[15922]: Using certificate: /etc/cockpit/ws-certs.d/0-self-signed.cert
Jun 10 12:42:05 X.X.X cockpit-session[16311]: pam_ssh_add: Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)
Jun 10 12:42:07 X.X.X cockpit-ws[15922]: logged in user session
Jun 10 12:42:07 X.X.X cockpit-ws[15922]: New connection to session from 10.52.208.221
Jun 10 12:42:21 X.X.X cockpit-ws[15922]: WebSocket from 10.52.208.221 for session closed
Jun 10 12:42:36 X.X.X cockpit-ws[15922]: session timed out
# lsof -i :9090
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
systemd 1 root 75u IPv6 7761202 0t0 TCP *:websm (LISTEN)
#
答案1
systemctl list-sockets
应显示准确的单位名称和相关服务。
LISTEN UNIT ACTIVATES
[::]:9090 cockpit.socket [email protected]
答案2
虽然不理想,但总比没有好:
# systemctl | grep listening
dm-event.socket loaded active listening Device-mapper event daemon FIFOs
iscsid.socket loaded active listening Open-iSCSI iscsid Socket
iscsiuio.socket loaded active listening Open-iSCSI iscsiuio Socket
lvm2-lvmpolld.socket loaded active listening LVM2 poll daemon socket
systemd-initctl.socket loaded active listening /dev/initctl Compatibility Named Pipe
systemd-shutdownd.socket loaded active listening Delayed Shutdown Socket
virtlockd.socket loaded active listening Virtual machine lock manager socket
virtlogd.socket loaded active listening Virtual machine log manager socket
#
就我而言,cockpit.socket
不是cockpit.service
答案3
您可以使用云来ss
解决netstat
此问题。
sudo ss -ntpulo
或者
sudo netstat -ntpul
两者都显示网络 tcp
和udp
协议,以及它的程序名称作为长列表最后你grep
可以标准输出喜欢:
sudo ss -ntpulo | grep 9090
还要记住netstat
附带了名为的包net-tools
,如果您的系统上找不到它,只需安装:
# Ubuntu/debian
sudo apt install net-tools
# centos
yum install net-tools
PS:我喜欢netstat
,它有更好的输出:)