1、查看当前所有已经使用的端口情况
命令:netstat -nultp
[root@VM-0-10-centos conf]# netstat -nultp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 21774/nginx: master tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1123/sshd tcp6 0 0 :::45023 :::* LISTEN 4072/java tcp6 0 0 127.0.0.1:8005 :::* LISTEN 4072/java tcp6 0 0 :::8009 :::* LISTEN 4072/java tcp6 0 0 :::36361 :::* LISTEN 4072/java tcp6 0 0 :::9999 :::* LISTEN 4072/java tcp6 0 0 :::8080 :::* LISTEN 4072/java udp 0 0 0.0.0.0:68 0.0.0.0:* 907/dhclient udp 0 0 172.17.0.10:123 0.0.0.0:* 639/ntpd udp 0 0 127.0.0.1:123 0.0.0.0:* 639/ntpd udp6 0 0 fe80::5054:ff:fe29::123 :::* 639/ntpd udp6 0 0 ::1:123 :::* 639/ntpd
2、查看具体端口是否被占用
命令:netstat -anp |grep 端口号
[root@VM-0-10-centos conf]# netstat -anp | grep 9999 tcp6 0 0 :::9999 :::* LISTEN 4072/java
主要看监控状态为LISTEN表示已经被占用。
3、lsof -i:port命令
[root@VM-0-10-centos bin]# lsof -i:9999 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME java 18396 root 22u IPv6 46964003 0t0 TCP *:distinct (LISTEN)