Hi 大家好,我是钟义林,大家查看端口的的方式有如下命令


windows cmd

netstat -aon | findstr "端口号"


linux

netstat -anl | grep "端口号"

lsof -i:端口号


但是,你又到这样的问题吗?

-bash: lsof: command not found


lsof 命令不能用,我找了一下,网上说的方法多少都行不通过,今天给大家说下我的解决方法


yum install lsof -y


======================================================================================

[root@Evil ~]# lsof -i:3306  

-bash: lsof: command not found

[root@Evil ~]# yum install lsof

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

* base: mirrors.163.com

* extras: mirrors.163.com

* updates: mirrors.163.com

Setting up Install Process

Resolving Dependencies

--> Running transaction check

---> Package lsof.x86_64 0:4.82-4.el6 will be installed

--> Finished Dependency Resolution


Dependencies Resolved


=======================================================================================

Package           Arch                Version                 Repository         Size

=======================================================================================

Installing:

lsof              x86_64              4.82-4.el6              base              319 k


Transaction Summary

=======================================================================================

Install       1 Package(s)


Total download size: 319 k

Installed size: 890 k

Is this ok [y/N]: y

Downloading Packages:

lsof-4.82-4.el6.x86_64.rpm                                      | 319 kB     00:00    

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

 Installing : lsof-4.82-4.el6.x86_64                                              1/1

 Verifying  : lsof-4.82-4.el6.x86_64                                              1/1


Installed:

 lsof.x86_64 0:4.82-4.el6                                                            


Complete!

[root@Evil ~]# lsof -i:3306

[root@Evil ~]# lsof -i:22

COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

sshd    3044 root    3u  IPv4  32288      0t0  TCP *:ssh (LISTEN)

sshd    3044 root    4u  IPv6  32290      0t0  TCP *:ssh (LISTEN)

sshd    9243 root    3r  IPv4  50830      0t0  TCP 192.168.1.234:ssh->192.168.1.1:33540 (ESTABLISHED)