Hyper-V 端口占用问题
· 阅读需 2 分钟
参考:
- 自 Windows Vista 和 Windows Server 2008 以来,TCP/IP 的默认动态端口范围已更改 | Microsoft Learn
- 服务名称和传输协议端口号注册表 | INNA
- Network shell (netsh) | Microsoft Learn
管理员身份运行以下命令:
# 设置 IPv4 和 IPv6 动态端口范围为 60001-64999
netsh interface ipv4 set dynamic tcp start=60001 num=4998
netsh interface ipv6 set dynamic tcp start=60001 num=4998
# 设置 IPv4 和 IPv6 排除端口范围为 2000-9000
netsh interface ipv4 add excludedportrange protocol=tcp startport=2000 numberofports=7000
netsh interface ipv6 add excludedportrange protocol=tcp startport=2000 numberofports=7000
# 重启 Windows NAT Driver 使配置生效
net stop winnat
net start winnat
# 查看 TCP 协议动态端口范围
netsh interface ipv4 show dynamicport tcp
netsh interface ipv6 show dynamicport tcp
# 查看 TCP 协议端口排除范围
netsh interface ipv4 show excludedportrange protocol=tcp
netsh interface ipv6 show excludedportrange protocol=tcp
# 查看特定端口是否被占用
netstat -ano | findstr 3000