使用MikroTik搭建的L2TP服务,通过NAT暴露端口,在MacOS和iPhone下连接状况良好。但是在Windows上,尤其是Windows10/11上,会出现连接失败的故障。类似下面这种提示: ``` 无法建立计算机与VPN服务器之际的网络连接,因为远程服务器未响应。这可能是因为... ``` 由于MacOS和iPhone上连接良好,所以基本可以排除是服务端的问题。那么就要找出Windows上有哪些因素会影响L2TP的连接了。 最终找到了一篇微软的说明:[Configure a L2TP/IPsec server behind a NAT-T device](https://docs.microsoft.com/en-US/troubleshoot/windows-server/networking/configure-l2tp-ipsec-server-behind-nat-t-device)。不想看可以直接跳到后面的解决方案。 > By default, Windows Vista and Windows Server 2008 don't support Internet Protocol security (IPsec) network address translation (NAT) Traversal (NAT-T) security associations to servers that are located behind a NAT device. If the virtual private network (VPN) server is behind a NAT device, a Windows Vista or Windows Server 2008-based VPN client computer can't make a Layer 2 Tunneling Protocol (L2TP)/IPsec connection to the VPN server. This scenario includes VPN servers that are running Windows Server 2008 and Windows Server 2003. > > Because of the way in which NAT devices translate network traffic, you may experience unexpected results in the following scenario: > > You put a server behind a NAT device. > You use an IPsec NAT-T environment. > If you must use IPsec for communication, use public IP addresses for all servers that you can connect to from the Internet. If you must put a server behind a NAT device, and then use an IPsec NAT-T environment, you can enable communication by changing a registry value on the VPN client computer and the VPN server. 中文版:[https://docs.microsoft.com/zh-CN/troubleshoot/windows-server/networking/configure-l2tp-ipsec-server-behind-nat-t-device](https://docs.microsoft.com/zh-CN/troubleshoot/windows-server/networking/configure-l2tp-ipsec-server-behind-nat-t-device) > 默认情况下,Windows Vista 和 Windows Server 2008 不支持 Internet 协议安全性 (IPsec) 网络地址转换 (NAT) 遍历 (NAT-T) 安全关联到位于 NAT 设备后面的服务器。 如果虚拟专用网络 (VPN) 服务器位于 NAT 设备后面,则基于 Windows Vista 或 Windows Server 2008 的 VPN 客户端计算机无法与 VPN 服务器建立第 2 层隧道协议 (L2TP) /IPsec 连接。 此方案包括运行 Windows Server 2008 和 Windows Server 2003 的 VPN 服务器。 > > 由于 NAT 设备转换网络流量的方式,在以下情况中可能会遇到意外结果: > > 将服务器置于 NAT 设备后面。 > 使用 IPsec NAT-T 环境。 > 如果必须使用 IPsec 进行通信,请对可以从 Internet 连接到的所有服务器使用公用 IP 地址。 如果必须将服务器置于 NAT 设备后面,然后使用 IPsec NAT-T 环境,则可以通过更改 VPN 客户端计算机和 VPN 服务器的注册表值来启用通信。 ## 解决方案 按照文档提到的操作设置。 1. 使用Win+R快捷键打开运行对话框,输入`regedit`,点击确定。如果出现用户账户控制对话框,给予管理员权限,即可打开注册表编辑器。 2. 在打开的注册表编辑器中,找到并选择以下注册表子项: `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PolicyAgent` > 您还可以将 `AssumeUDPEncapsulationContextOnSendRule` DWORD 值应用到基于 MICROSOFT Windows XP Service Pack 2 (SP2) VPN 客户端计算机。 为此,请找到注册表子 `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\IPSec` 项,然后选择该子项。 3. 在“编辑”菜单上,指向“新建”,然后选择“DWORD(32 位)值”。 4. 键入 `AssumeUDPEncapsulationContextOnSendRule`,然后按Enter。 5. 右键单击 `AssumeUDPEncapsulationContextOnSendRule`,然后选择“修改”。 6. 在“值数据“框中,键入下列值之一: - 0 它是默认值。 设置为 0 时,Windows无法与位于 NAT 设备后面的服务器建立安全关联。 - 1 当设置为 1 时,Windows与位于 NAT 设备后面的服务器建立安全关联。 - 2 设置为 2 时,当服务器和 VPN 客户端计算机 (Windows Vista 或基于 Windows Server Windows 2008) 的服务器和 VPN 客户端计算机都支持 NAT 设备时,) 可以建立安全关联。 7. 选择“确定”,然后退出注册表编辑器。 8. 重启计算机。 ## 后续方案 如果上述没有能解决问题,在控制面板-网络和Internet-网络连接中,找到L2TP使用的连接,打开属性进行编辑,切换到安全选项卡,将数据加密设置为需要加密,同时勾选运行使用这些协议,只勾选Microsoft CHAP Version 2(MS-CHAP v2)。 如果还不能连接,找到注册表`HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\RasMan\Parameters`,新建“DWORD(32位)值”,ProhibitIPSec,并设置值为0。 Loading... 使用MikroTik搭建的L2TP服务,通过NAT暴露端口,在MacOS和iPhone下连接状况良好。但是在Windows上,尤其是Windows10/11上,会出现连接失败的故障。类似下面这种提示: ``` 无法建立计算机与VPN服务器之际的网络连接,因为远程服务器未响应。这可能是因为... ``` 由于MacOS和iPhone上连接良好,所以基本可以排除是服务端的问题。那么就要找出Windows上有哪些因素会影响L2TP的连接了。 最终找到了一篇微软的说明:[Configure a L2TP/IPsec server behind a NAT-T device](https://docs.microsoft.com/en-US/troubleshoot/windows-server/networking/configure-l2tp-ipsec-server-behind-nat-t-device)。不想看可以直接跳到后面的解决方案。 > By default, Windows Vista and Windows Server 2008 don't support Internet Protocol security (IPsec) network address translation (NAT) Traversal (NAT-T) security associations to servers that are located behind a NAT device. If the virtual private network (VPN) server is behind a NAT device, a Windows Vista or Windows Server 2008-based VPN client computer can't make a Layer 2 Tunneling Protocol (L2TP)/IPsec connection to the VPN server. This scenario includes VPN servers that are running Windows Server 2008 and Windows Server 2003. > > Because of the way in which NAT devices translate network traffic, you may experience unexpected results in the following scenario: > > You put a server behind a NAT device. > You use an IPsec NAT-T environment. > If you must use IPsec for communication, use public IP addresses for all servers that you can connect to from the Internet. If you must put a server behind a NAT device, and then use an IPsec NAT-T environment, you can enable communication by changing a registry value on the VPN client computer and the VPN server. 中文版:[https://docs.microsoft.com/zh-CN/troubleshoot/windows-server/networking/configure-l2tp-ipsec-server-behind-nat-t-device](https://docs.microsoft.com/zh-CN/troubleshoot/windows-server/networking/configure-l2tp-ipsec-server-behind-nat-t-device) > 默认情况下,Windows Vista 和 Windows Server 2008 不支持 Internet 协议安全性 (IPsec) 网络地址转换 (NAT) 遍历 (NAT-T) 安全关联到位于 NAT 设备后面的服务器。 如果虚拟专用网络 (VPN) 服务器位于 NAT 设备后面,则基于 Windows Vista 或 Windows Server 2008 的 VPN 客户端计算机无法与 VPN 服务器建立第 2 层隧道协议 (L2TP) /IPsec 连接。 此方案包括运行 Windows Server 2008 和 Windows Server 2003 的 VPN 服务器。 > > 由于 NAT 设备转换网络流量的方式,在以下情况中可能会遇到意外结果: > > 将服务器置于 NAT 设备后面。 > 使用 IPsec NAT-T 环境。 > 如果必须使用 IPsec 进行通信,请对可以从 Internet 连接到的所有服务器使用公用 IP 地址。 如果必须将服务器置于 NAT 设备后面,然后使用 IPsec NAT-T 环境,则可以通过更改 VPN 客户端计算机和 VPN 服务器的注册表值来启用通信。 ## 解决方案 按照文档提到的操作设置。 1. 使用Win+R快捷键打开运行对话框,输入`regedit`,点击确定。如果出现用户账户控制对话框,给予管理员权限,即可打开注册表编辑器。 2. 在打开的注册表编辑器中,找到并选择以下注册表子项: `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PolicyAgent` > 您还可以将 `AssumeUDPEncapsulationContextOnSendRule` DWORD 值应用到基于 MICROSOFT Windows XP Service Pack 2 (SP2) VPN 客户端计算机。 为此,请找到注册表子 `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\IPSec` 项,然后选择该子项。 3. 在“编辑”菜单上,指向“新建”,然后选择“DWORD(32 位)值”。 4. 键入 `AssumeUDPEncapsulationContextOnSendRule`,然后按Enter。 5. 右键单击 `AssumeUDPEncapsulationContextOnSendRule`,然后选择“修改”。 6. 在“值数据“框中,键入下列值之一: - 0 它是默认值。 设置为 0 时,Windows无法与位于 NAT 设备后面的服务器建立安全关联。 - 1 当设置为 1 时,Windows与位于 NAT 设备后面的服务器建立安全关联。 - 2 设置为 2 时,当服务器和 VPN 客户端计算机 (Windows Vista 或基于 Windows Server Windows 2008) 的服务器和 VPN 客户端计算机都支持 NAT 设备时,) 可以建立安全关联。 7. 选择“确定”,然后退出注册表编辑器。 8. 重启计算机。 ## 后续方案 如果上述没有能解决问题,在控制面板-网络和Internet-网络连接中,找到L2TP使用的连接,打开属性进行编辑,切换到安全选项卡,将数据加密设置为需要加密,同时勾选运行使用这些协议,只勾选Microsoft CHAP Version 2(MS-CHAP v2)。 如果还不能连接,找到注册表`HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\RasMan\Parameters`,新建“DWORD(32位)值”,ProhibitIPSec,并设置值为0。 最后修改:2023 年 08 月 02 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 1 如果觉得我的文章对你有用,请随意赞赏