Linux中查看并删除端口

一、查看端口

lsof -i:端口号

root@ubuntu:~# lsof -i:8000
COMMAND   PID USER   FD   TYPE    DEVICE SIZE/OFF NODE NAME
java    87955 root   25u  IPv6 392398042      0t0  TCP *:8000 (LISTEN)

netstat -tunlp|grep 端口号

精确查询

root@ubuntu:~# netstat -nplt |grep 8000
tcp6       0      0 :::8000                 :::*                    LISTEN      87955/java

root@ubuntu:~# netstat -tunlp|grep 8000
tcp6       0      0 :::8000                 :::*                    LISTEN      87955/java 

查询全部

root@ubuntu:~# sudo netstat -nplt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 192.168.10.125:9093     0.0.0.0:*               LISTEN      153865/docker-proxy
tcp        0      0 192.168.10.125:9000     0.0.0.0:*               LISTEN      29952/docker-proxy
tcp        0      0 0.0.0.0:25672           0.0.0.0:*               LISTEN      2025/beam.smp   
tcp        0      0 0.0.0.0:27017           0.0.0.0:*               LISTEN      1332/mongod     
tcp        0      0 192.168.10.125:3306     0.0.0.0:*               LISTEN      100285/mysqld   
tcp        0      0 192.168.10.125:26379    0.0.0.0:*               LISTEN      20022/docker-proxy
tcp        0      0 192.168.10.125:26380    0.0.0.0:*               LISTEN      20039/docker-proxy
tcp        0      0 192.168.10.125:6380     0.0.0.0:*               LISTEN      19805/docker-proxy
tcp        0      0 192.168.10.125:6381     0.0.0.0:*               LISTEN      20076/docker-proxy
tcp        0      0 192.168.10.125:26381    0.0.0.0:*               LISTEN      20053/docker-proxy
tcp        0      0 192.168.10.125:6382     0.0.0.0:*               LISTEN      19944/docker-proxy

模糊查询

root@ubuntu:~# netstat -ap | grep 8000
tcp        0      0 172.17.0.1:58000        172.17.0.20:8113        FIN_WAIT2   244146/docker-proxy
tcp        0      0 172.17.0.1:48000        172.17.0.20:8113        FIN_WAIT2   244146/docker-proxy
tcp        0      0 172.17.0.1:38000        172.17.0.20:8113        FIN_WAIT2   244146/docker-proxy

二、删除端口

查询所有进程

root@ubuntu:~# ps -ef
UID         PID   PPID  C STIME TTY          TIME CMD
root          1      0  0 Apr18 ?        00:32:41 /sbin/init
root          2      0  0 Apr18 ?        00:00:04 [kthreadd]
root          3      2  0 Apr18 ?        00:04:25 [ksoftirqd/0]
root          5      2  0 Apr18 ?        00:00:00 [kworker/0:0H]

在这里插入图片描述

查询对应进程

root@ubuntu:~# ps -ef|grep node
root       5380   5357  0 Jun24 ?        00:02:20 node server.js
root      90715  87407  0 16:02 pts/6    00:00:00 grep --color=auto node
nobody    97745  97711  0 Jul26 ?        00:01:19 /bin/node_exporter
root     245173 242899  0 Apr19 ?        00:00:11 node server.js
root     245180 242999  0 Apr19 ?        00:00:10 node server.js

删除进程

kill -9 <PID>
Logo

更多推荐