登录后使用 OpenVPN 客户端自动连接到多个站点

登录后使用 OpenVPN 客户端自动连接到多个站点

我已经将 OpenVPN 设置为自动启动。这很容易,因为设置中有一个复选框,可以自动将 OpenVPN 服务设置为自动。我通过重新启动桌面尝试了这一点,它成功了。

我有几个(目前是 4 个)连接脚本。OpenVPN 将它们很好地存储在配置文件夹中。我可以选择“连接”到相应的站点,然后就可以连接了。我设置了静默。这也很好用。

我无法弄清楚如何操作,当我登录到我的计算机时,OpenVPN 会自动连接到我的网站。

我的 OVPN 扩展文件很好地存储在我的文件夹中:

C:\Users\<user>\OpenVPN\config

我做了研究,想出了 OpenVPN 服务器,但我对其他方法不感兴趣。我只想在登录计算机时自动连接到服务器。

OpenVPN 设置

OpenVPN 客户端设置选项卡

OpenVPN 关于

OpenVPN 关于框选项卡

OpenVPN 登录

OpenVPN 登录选项卡

我的研究发现了以下命令,我认为该命令安排在我的计算机启动后一两分钟。

openvpn-gui.exe --connect C:\Users\username\OpenVPN\config\ClientConnection1\clientconnection1.ovpn

由于两个原因,我可以忽略上面的说法。

  1. 我在 OpenVPN 启动后尝试了该命令,但没有成功。是的,我尝试从管理命令窗口进行操作。我并不感到惊讶,因为 OpenVPN 已经启动。这让我想到了第 2 点。(是的,我意识到我可以手动启动 OpenVPN 并让任务计划程序运行上述命令。)

  2. 我想在我的桌面上自动连接到 4 个(可以是任意数量)站点并且命令行提供对其中一个站点的支持。

这是如何实现的?

有什么想法吗?

强文本更新

根据以下评论,我将脚本文件复制到以下config-auto文件夹中:

C:\Program Files\OpenVPN\config-auto
    client-connect1 (a subdirectory)
    README.txt
C:\Program Files\OpenVPN\config-auto\client-connect1
    caConnection1.crt
    clientConnection1.crt
    clientConnection1.key
    clientConnection1.ovpn

脚本内容如下:

client
dev tap
proto udp
dev-node NETGEAR-VPN
remote connection1.ddns.net 12974
resolv-retry infinite
nobind
key-direction 1
persist-key
persist-tun
ca caConnection1.crt
cert clientConnection1.crt
key clientConnection1.key
cipher AES-128-CBC
comp-lzo
verb 5

如上所述,该脚本放在任一config文件夹中都可以工作。

我使用如上所示的文件夹中的配置文件重新启动了计算机(现在已经两次了)config-auto,但即使等待了 5 分钟,也什么也没有。

我确实看到了,谢谢,这个README.txt文件在config-auto目录中证实了该评论,但它不起作用。

This directory or its subdirectories should contain OpenVPN
configuration files each having an extension of .ovpn
that should be automatically started at boot up.

When OpenVPNService is started, a separate OpenVPN
process will be instantiated for each configuration file.

OpenVPN GUI does not scan this directory.

更新

我找到了日志文件,这里是问题,所以有进展,现在只需要解决它。

2021-04-10 18:26:50 WARNING: Compression for receiving enabled. Compression has been used in the past to break encryption. Sent packets are not compressed unless "allow-compression yes" is also set.
2021-04-10 18:26:50 us=900373 DEPRECATED OPTION: --cipher set to 'AES-128-CBC' but missing in --data-ciphers (AES-256-GCM:AES-128-GCM). Future OpenVPN version will ignore --cipher for cipher negotiations. Add 'AES-128-CBC' to --data-ciphers or change --cipher 'AES-128-CBC' to --data-ciphers-fallback 'AES-128-CBC' to silence this warning.
Options error: --ca fails with 'catheclient.crt': No such file or directory (errno=2)
Options error: --cert fails with 'clienttheclient.crt': No such file or directory (errno=2)
2021-04-10 18:26:50 us=900373 WARNING: cannot stat file 'clienttheclient.key': No such file or directory (errno=2)
Options error: --key fails with 'clienttheclient.key': No such file or directory (errno=2)
Options error: Please correct these errors.
Use --help for more information.
  1. OpenVPN 会持续尝试连接,而不是只尝试一次。日志文件会显示每隔一分钟左右的连接尝试次数。
  2. 有问题的 3 个文件位于同一目录中,即 config/auto-config 文件夹的子目录中。我可能需要对整个路径进行硬编码。

答案1

日志文件确实有帮助,但是OpenVPN注意事项页面略有错误。

  1. 查看OpenVPN Serviceconfig-auto一个并忽略文件夹中至少同名的内容config

  2. 我必须对路径进行硬编码,所以:

    客户端 dev tap proto udp dev-node NETGEAR-VPN 远程 theclient2.ddns.net 12974 解析重试无限无绑定键方向 1 持久密钥持久 tun ca“C:/Program Files/OpenVPN/config/client-Th/caTheClient2.crt”证书“C:/Program Files/OpenVPN/config/client-TheClient2/clientTheClient2.crt”密钥“C:/Program Files/OpenVPN/config/client-TheClient2/clientTheClient2.key”密码 AES-128-CBC comp-lzo 动词 5

我使用正斜杠,因为我有使用基于 Linux 的工具的经验,即使移植到 Windows,它们也不喜欢 Windows 反斜杠,有时甚至加倍,所以我只是 KISS 并使用正斜杠。

然后我打开一个命令/终端窗口,并发出“ping 10.0.0.1”并且成功!

日志文件保持静态,没有新条目。

最后。

相关内容