解决windows的诡异的端口占用问题
在某天如往常一样我运行了我的nacos,发现报错:
1 | org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grpcServerThreadPoolMonitor': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grpcSdkServer': Invocation of init method failed; nested exception is java.io.IOException: Failed to bind to address 0.0.0.0/0.0.0.0:9848 |
心想不就是占用了端口嘛,把对应进程kill掉不就行了?
于是执行
1 | netstat -ano | findstr "9848" |
发现没有进程占用,我有使用管理员运行也不行,ps运行也不行。
然后我又搭建了一个vue应用监听到这个端口发现:
1 | 15:49:55 [vite] vite.config.ts changed, restarting server... |
我以为是win的命令有问题,我又使用了微软的tcpview可视化查找,结果仍然没有发现9848这个端口。
此时我急了,问了各种各样的ai,最后只有claude sonnet给了我答案:
端口被系统保留了
执行:
1 | netsh interface ipv4 show excludedportrange protocol=tcp |
结果:
1 | C:\Windows\system32>netsh interface ipv4 show excludedportrange protocol=tcp |
这些端口好像都不是什么重要的系统保留端口,留着是隐患:
1 | # 0. 先停止 WinNAT 服务 |
再次查看:
1 | C:\Windows\system32>netsh interface ipv4 show excludedportrange protocol=tcp |
发现9848已经成功释放,这些端口没有释放可能确实有用。
评论