如何在Windows上在后台启动wireguard客户端?

nag*_*lzs 4 windows-10 wireguard

我有多台计算机(Win10 pro)放置在不同的远程位置(我的合作伙伴),我需要管理。我需要从中心位置访问它们。所以我有一个中央VPN服务器,我想要多个Win10专业版实例连接到它。我正在使用 L2TP,但我想迁移到wireguard。使用 L2TP,可以从任务计划程序在后台启动 rasdial.exe。主要目标是在计算机启动时立即启动隧道,并在隧道出现故障时自动重新连接。我需要在任何用户登录计算机之前(例如在后台)。我想知道wireguard是否可以做到同样的事情?

我注意到有一个名为 C:\Program Files\Wireguard\wg.exe 的程序,其命令行选项与 wg (linux) 程序非常相似:

C:\Program Files\WireGuard>wg.exe --help
Usage: wg.exe <cmd> [<args>]

Available subcommands:
  show: Shows the current configuration and device information
  showconf: Shows the current configuration of a given WireGuard interface, for use with `setconf'
  set: Change the current configuration, add peers, remove peers, or change peers
  setconf: Applies a configuration file to a WireGuard interface
  addconf: Appends a configuration file to a WireGuard interface
  syncconf: Synchronizes a configuration file to a WireGuard interface
  genkey: Generates a new private key and writes it to stdout
  genpsk: Generates a new preshared key and writes it to stdout
  pubkey: Reads a private key from stdin and writes a public key to stdout
You may pass `--help' to any of these subcommands to view usage.
Run Code Online (Sandbox Code Playgroud)

但我认为这仅用于配置。我认为它不能用来激活隧道。原始文档(https://www.wireguard.com/quickstart/#command-line-interface)解释说“该接口可以......使用 ifconfig(8) 或 ip-link(8) 激活”,但是当然仅适用于 UNIX。在该文档中,还有另一条注释“非Linux用户将改为编写wireguard-go wg0”,但我不确定它们在这里的意思。任何地方都没有程序名称“wireguard-go”。仅当隧道已处于活动状态时,隧道的网络适配器才会显示在网络适配器列表中。例如,当隧道关闭时,我没有可以“启用”或“激活”的网络适配器。最后还有wireguard.exe。当不带参数启动时,它是一个 GUI 应用程序。如果没有登录用户和桌面,它就无法运行,并且不会自动激活任何隧道。它有一些有趣的命令行选项。“wireguard.exe /managerservice”用于将其作为 Windows 服务启动。“wireguard.exe /tunnelservice CONFIG_PATH”看起来很有希望,但我无法启动它。我收到此错误,即“进程无法连接到服务管理器”或类似的错误。(当我以管理员身份启动它时,我也会收到此错误。)

我没主意了。我该怎么做?

小智 5

此问题的所有其他解决方案都不理想。我见过的方法有:

\n
    \n
  1. 只需以管理员身份运行

    \n
  2. \n
  3. 将用户帐户添加到网络配置操作员

    \n
      \n
    • 优点:Wireguard gui,工作流畅
    • \n
    • 缺点:您的普通用户会被添加到管理员组中,并将出现在 UAC 提示中。这很烦人。
    • \n
    \n
  4. \n
  5. 将 WireGuard 隧道作为 Windows 服务运行(如答案中的建议)

    \n
      \n
    • 优点:完美运作
    • \n
    • 缺点:没有图形用户界面,需要一个高架控制台。
    • \n
    \n
  6. \n
\n

解决方案:

\n
    \n
  1. 安装最新的 MSI: https: //download.wireguard.com/windows-client/

    \n
  2. \n
  3. 然后使用您的 .conf 文件在提升的控制台中运行此命令:

    \n

    wireguard /installtunnelservice C:\\path\\to\\some\\myconfname.conf

    \n
  4. \n
\n
\n

这将创建一个名为 的服务WireGuardTunnel$myconfname,可以使用标准 Windows 服务管理实用程序(例如 services.msc 或 sc)来控制该服务。\n\xe2\x80\x94

\n
\n
    \n
  1. 使用“ServiceTray”控制服务:https://www.coretechnologies.com/products/ServiceTray/

    \n

    (这会在系统托盘上显示一个漂亮的图标,显示 WireGuard 隧道服务的启动状态。绿色=已连接,红色=未连接,您可以通过右键单击来启动和停止它。请参见下图)

    \n

    注意:创建服务控制器时,将快捷方式保存到桌面而不是启动(好像不起作用,可以稍后复制到启动)

    \n
  2. \n
  3. (可选)如果您不想在启动时连接到隧道,请将服务的启动类型更改为手动。

    \n
  4. \n
\n

Win 10 上的示例。将鼠标悬停在图标上会显示隧道的名称。

\n