如何在Windows 10上配置wg0接口?

huangapple go评论95阅读模式
英文:

How to configure wg0 interface on Windows 10?

问题

我无法使用wgctl在Windows(10)上管理wireguard接口。我在Linux上使用它一切正常。我正在使用最新更新的Windows 10、最新的wireguard.exe和最新的go 1.17.3。

我使用wireguard.exe /installtunnelservice /path/wg0.conf创建了一个隧道。如果我使用wireguard GUI管理隧道,一切正常。但我需要以编程的方式进行管理。

以下代码会出现“文件不存在”的错误。我已经逐步调试了代码库,我认为wireguard.exe正在使用NT内核模式,而该库不支持它。有人可以确认一下吗?有什么好的解决方法吗?

package main
import (
	"log"

	"golang.zx2c4.com/wireguard/wgctrl"
	"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)
func main() {
	wgc, err := wgctrl.New()
	if err != nil {
		log.Printf("wgctrl.New: %s", err)
	}
	defer wgc.Close()

	cfg := wgtypes.Config{}

	port := 51822
	cfg.ListenPort = &port

	err = wgc.ConfigureDevice("wg0", cfg)
	if err != nil {
		log.Printf("wgc.ConfigureDevice: %s", err)
	}
}
英文:

I am not able to manage the wireguard interface using wgctl on Windows (10). I have used it on linux and all is fine. I'm using Windows 10 latest updates, wireguard.exe latest, go 1.17.3 latest.

I am using a tunnel created with wireguard.exe /installtunnelservice /path/wg0.conf. If I manage the tunnel with the wireguard GUI, it all works fine. But I need to do it programatically.

C:\>wg
interface: wg0
  public key: K0BZ3Bk...5tCWo=
  private key: (hidden)
  listening port: 57538

peer: 7W6tOXI...F7zAo=
  endpoint: 159....105:51820
  allowed ips: 100.127.128.0/18
  latest handshake: 43 seconds ago
  transfer: 31.61 KiB received, 115.69 KiB sent
  persistent keepalive: every 25 seconds

...

The following code exits with "file does not exist". Having stepped the code into the library, I think that wireguard.exe is using NT Kernel mode and the library does not support it? Can someone please confirm? What is the best way around this?

package main
import (
	"log"

	"golang.zx2c4.com/wireguard/wgctrl"
	"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)
func main() {
	wgc, err := wgctrl.New()
	if err != nil {
		log.Printf("wgctrl.New: %s", err)
	}
	defer wgc.Close()

	cfg := wgtypes.Config{}

	port := 51822
	cfg.ListenPort = &port

	err = wgc.ConfigureDevice("wg0", cfg)
	if err != nil {
		log.Printf("wgc.ConfigureDevice: %s", err)
	}
}

答案1

得分: 0

在将问题升级到GitHub后,结果发现这是一个库中的错误,我发布后不久就得到了修复。

英文:

After escalating the issue on GitHub, it turned out to be a bug in the library which was promptly fixed not long after I posted this.

huangapple
  • 本文由 发表于 2021年12月4日 23:11:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/70226837.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定