V2Ray启动 提示端口占用

Posted by Sunday on 2021-04-20

电脑开机或重启时V2ray提示:

1
Fatal error: can't bind to 127.0.0.1:1081:(error number)

1. 端口冲突

1
2
3
4
5
6
7
8
C:\Users\Administrator>netstat -ano | findstr 1081
TCP 0.0.0.0:1081 0.0.0.0:0 LISTENING 7864

C:\Users\Administrator>tasklist | findstr 7864
WXWork.exe 7864 Console 1 9,436 K

C:\Users\Administrator> taskkill /PID 7864
成功: 给进程发送了终止信号,进程的 PID 为 7864。

2. 系统保留端口

使用netstat找不到连接信息
根据2018年2月13日发布的 KB4074588里的 known issue,这个补丁会调整操作系统的 reserve port ranges,可以通过运行 netsh interface ipv4 show excludedportrange protocol=tcp 查看。

1
2
3
4
5
6
7
8
C:\Users\Administrator>netsh interface ipv4 show excludedportrange protocol=tcp

协议 tcp 端口排除范围

开始端口 结束端口
---------- --------
5357 5357
* - 管理的端口排除。

若安装过hyper-v,必须卸载hyper-v(hyper-v保留了这些端口),保留想要保留的端口,再安装开启hyper-v功能
控制面板\程序 启用或关闭 Windows功能

1
2
3
4
5
6
7
8
9
10
11
C:\Users\Administrator>netsh int ipv4 add excludedportrange protocol=tcp startport=1080 numberofports=3  # 1080-1082
确定。

C:\Users\Administrator>netsh interface ipv4 show excludedportrange protocol=tcp

协议 tcp 端口排除范围

开始端口 结束端口
---------- --------
1080 1082 *
5357 5357

方式2 命令卸载hyper-v

1
2
3
4
5
6
7
8
9
1.Disable hyper-v (which will required a couple of restarts) 
dism.exe /Online /Disable-Feature:Microsoft-Hyper-V # 命令卸载hyper-v

2.When you finish all the required restarts, reserve the port you want so hyper-v doesn't reserve it back
netsh int ipv4 add excludedportrange protocol=tcp startport=1080 numberofports=3 # 1080-1082
netsh int ipv4 add excludedportrange protocol=tcp startport=3306 numberofports=1 # 3306

3.Re-Enable hyper-V (which will require a couple of restart)
dism.exe /Online /Enable-Feature:Microsoft-Hyper-V /All # 命令安装hyper-v

github shadowsocks-windows 端口禁止访问
Unable to bind ports: Docker-for-Windows & Hyper-V excluding but not using important port ranges
13 de febrero de 2018: KB4074588 (compilación del SO 16299.248)