我已经进行了一些研究,发现人们建议使用netstat
检查特定进程使用哪个端口的几个地方。
但是,这就是我得到的:
myMac:~/Documents$ netstat -ap tcp | grep -i "listen"
tcp4 0 0 localhost.mysql *.* LISTEN
localhost.mysql
对端口号说什么?我期望有4位数字,例如3306。
有什么想法吗?
答案 0 :(得分:2)
对于netstat,您应该使用-n来将网络地址显示为数字。
netstat -nap tcp | grep -i "listen"
man netstat
-n Show network addresses as numbers (normally netstat interprets addresses and attempts to display them symbolically). This option may be used with any of the display formats.
或使用lsof:
lsof -n -P -i TCP -s TCP:LISTEN
或使用mysql客户端检查mysql端口:
mysql> SHOW GLOBAL VARIABLES LIKE 'PORT';
答案 1 :(得分:-1)