如何在 Linux 中的特定端口上使用 netstat

15 networking linux netstat

伙计们,我想知道我的特定端口是否正在使用 netstat 运行服务器?我如何做到这一点?

小智 15

您可以使用

netstat -pnlt | grep ':portno'
Run Code Online (Sandbox Code Playgroud)

另一种选择,您可以使用 nmap 工具检查服务器上的开放端口

nmap -sT -O localhost
Run Code Online (Sandbox Code Playgroud)

输出

Starting nmap 3.55 ( http://www.insecure.org/nmap/ ) at 2004-09-24 13:49 EDT
Interesting ports on localhost.localdomain (127.0.0.1):
(The 1653 ports scanned but not shown below are in state: closed)
PORT      STATE SERVICE
22/tcp    open  ssh 
25/tcp    open  smtp
111/tcp   open  rpcbind
Device type: general purpose
Run Code Online (Sandbox Code Playgroud)

网络统计示例:

[root@krizna ~]# netstat -pnlt | grep ':80'
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name 
tcp        0      0 :::80                       :::*                        LISTEN      1164/httpd          
Run Code Online (Sandbox Code Playgroud)