释放Linux占用端口

查看所有被占用的端口列表


	shell> netstat -lntp


	Active Internet connections (only servers)
	Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
	tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      3285/redis-server 1 
	tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd           
	tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      2310/dnsmasq        
	tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1011/sshd           
	tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1007/cupsd          
	tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           
	tcp6       0      0 :::22                   :::*                    LISTEN      1011/sshd           
	tcp6       0      0 ::1:631                 :::*                    LISTEN      1007/cupsd          
	tcp6       0      0 :::4000                 :::*                    LISTEN      10793/docker-proxy 

根据端口号查找到对应进程PID


	# 如查看端口号为 `4000` 的进程占用情况
    
	shell> lsof -i :4000


	COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
	docker-pr 10793 root    4u  IPv6  95507      0t0  TCP *:terabase (LISTEN)

释放端口占用


	# 如释放 `PID` 为 `10793` 的进程
    
	shell> kill -9 10793

posted @ 2017-06-15 23:11  warnerwu  阅读(977)  评论(0编辑  收藏  举报