linux下端口被占用

1.查看端口

netstat -ano

参数含义:

-a, --all  显示监听或非监听状态的接口

       Show  both listening and non-listening (for TCP this means established connections) sockets. 

-o, --timers  包括相关信息网络定时器。

       Include information related to networking timers.

-n 拒绝显示别名,能显示数字的全部转化成数字。

       Show numerical addresses instead of trying to determine symbolic host, port or user names.

下图中status是LISTEN 状态,Timer定时器off表示已关闭,on则表示打开;

status是ESTABLISHED 状态表示建立连接,这时本地IP和远程IP和端口都显示出来,

on后面的数字是连接的时长;

协议 本地地址 外部地址 状态 PID 

2.查找被占用的端口

  1. netstat -tln  
  2. netstat -tln | grep 3000 

 netstat -tln 查看端口使用情况,而netstat -tln | grep 3000 则是只查看端口3000的使用情况

 

3.查看端口属于哪个程序?端口被哪个进程占用

  1. lsof -i :3000

 

4.杀掉占用端口的进程

kill -9 进程id 

 

posted on 2016-08-29 19:24  bobo327  阅读(343)  评论(0编辑  收藏  举报