WireGuard/wireguard-go
GitHub: WireGuard/wireguard-go
WireGuard VPN 协议的 Go 语言用户态实现,为不支持内核模块的平台提供跨平台 VPN 隧道能力。
Stars: 4311 | Forks: 1621
# [WireGuard](https://www.wireguard.com/) 的 Go 实现
这是 WireGuard 的 Go 实现。
## 用法
大多数 Linux kernel WireGuard 用户习惯使用 `ip link add wg0 type wireguard` 来添加接口。而对于 wireguard-go,只需运行:
```
$ wireguard-go wg0
```
这将创建一个接口并在后台运行。要删除该接口,请使用常用的 `ip link del wg0` 命令;或者,如果你的系统不支持直接删除接口,你可以通过 `rm -f /var/run/wireguard/wg0.sock` 删除控制 socket,这将导致 wireguard-go 关闭。
要在不进入后台运行的情况下运行 wireguard-go,请传入 `-f` 或 `--foreground`:
```
$ wireguard-go -f wg0
```
当接口正在运行时,你可以使用 [`wg(8)`](https://git.zx2c4.com/wireguard-tools/about/src/man/wg.8) 进行配置,以及使用常用的 `ip(8)` 和 `ifconfig(8)` 命令。
要获取更详细的日志,你可以设置环境变量 `LOG_LEVEL=debug`。
## 平台
### Linux
这可以在 Linux 上运行;但是你应该改用 kernel module,它更快并且与操作系统的集成度更高。有关说明,请参阅[安装页面](https://www.wireguard.com/install/)。
### macOS
这在 macOS 上使用 utun 驱动运行。它目前还不支持 sticky sockets,并且由于 Darwin 的限制,也不会支持 fwmarks。由于 utun 驱动不能使用任意的接口名称,你必须使用 `utun[0-9]+` 作为显式接口名,或者使用 `utun` 让 kernel 为你分配一个。如果你选择 `utun` 作为接口名,并且定义了环境变量 `WG_TUN_NAME_FILE`,那么 kernel 所选定的实际接口名称将被写入该变量指定的文件中。
### Windows
这可以在 Windows 上运行,但你应该改为使用功能更丰富的 [Windows 应用](https://git.zx2c4.com/wireguard-windows/about/),该应用将此作为模块使用。
### FreeBSD
这可以在 FreeBSD 上运行。它目前还不支持 sticky sockets。Fwmark 映射到 `SO_USER_COOKIE`。
### OpenBSD
这可以在 OpenBSD 上运行。它目前还不支持 sticky sockets。Fwmark 映射到 `SO_RTABLE`。由于 tun 驱动不能使用任意的接口名称,你必须使用 `tun[0-9]+` 作为显式接口名,或者使用 `tun` 让程序为你分配一个。如果你选择 `tun` 作为接口名,并且定义了环境变量 `WG_TUN_NAME_FILE`,那么 kernel 所选定的实际接口名称将被写入该变量指定的文件中。
## 构建
这需要安装最新版本的 [Go](https://go.dev/)。
```
$ git clone https://git.zx2c4.com/wireguard-go
$ cd wireguard-go
$ make
```
## 许可证
```
Copyright (C) 2017-2025 WireGuard LLC. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
标签:EVTX分析, Go, Ruby工具, VPN, WireGuard, 密码学, 手动系统调用, 日志审计, 网络安全协议, 网络通信, 虚拟网卡