Wireguard
User-space Wireguard 协议实现。
DANGER
Wireguard 协议并非专门为翻墙而设计,若在最外层过墙,存在特征可能导致服务器被封锁
InboundConfigurationObject
{
"secretKey": "PRIVATE_KEY",
"address": [
// optional, default ["10.0.0.1", "fd59:7153:2388:b5fd:0000:0000:0000:0001"]
"10.0.0.1/32",
"fd59:7153:2388:b5fd::1/128"
],
"peers": [
{
"publicKey": "PUBLIC_KEY",
"preSharedKey": "PRE_SHARED_KEY",
"endpoint": "ENDPOINT_ADDR",
"keepAlive": 0,
"allowedIPs": ["10.0.0.2/32", "fd59:7153:2388:b5fd::2/128"]
}
],
"mtu": 1420 // optional, default 1420
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
secretKey: string
私钥。必填。
mtu: int
Wireguard 底层 tun 的分片大小。
address: string array
Wireguard 虚拟网卡的接口地址列表。支持以下两种格式:
- IP:如
"10.0.0.1"/"fd59:...::1" - CIDR:仅允许
/32(IPv4)或/128(IPv6),如"10.0.0.1/32"/"fd59:...::1/128"
不填写时默认 ["10.0.0.1", "fd59:7153:2388:b5fd:0000:0000:0000:0001"]。
MTU的计算方法
一个wireguard数据包的结构如下
- 20-byte IPv4 header or 40 byte IPv6 header
- 8-byte UDP header
- 4-byte type
- 4-byte key index
- 8-byte nonce
- N-byte encrypted data
- 16-byte authentication tag2
3
4
5
6
7
N-byte encrypted data即为我们需要的MTU的值,根据endpoint是IPv4还是IPv6,具体的值可以是1440(IPv4)或者1420(IPv6),如果处于特殊环境下再额外减掉即可(如家宽PPPoE额外-8)。
peers: [ Peers ]
peers 服务器列表,其中每一项是一个服务器配置。
Peers
{
"publicKey": "PUBLIC_KEY",
"preSharedKey": "PRE_SHARED_KEY",
"endpoint": "ENDPOINT_ADDR",
"keepAlive": 0,
"allowedIPs": ["10.0.0.2/32"] // optional, default ["0.0.0.0/0", "::0/0"]
}2
3
4
5
6
7
publicKey: string
公钥,用于验证
allowedIPs: string array
允许的源 IP(WireGuard 的 AllowedIPs)。不填写时默认 ["0.0.0.0/0", "::0/0"]。
WARNING
作为 WG 入站(服务端)时,强烈建议为每个 peer 明确设置其可用地址段(通常是 /32 或 /128),避免误路由。
preSharedKey: string
预共享密钥(可选)。
endpoint: string
对端地址(可选)。通常为 host:port,例如 example.com:51820 或 162.159.192.1:2408。
keepAlive: int
心跳包时间间隔,单位为秒。默认为 0 表示无心跳。
说明
WG 入站当前不支持 kernel TUN(始终使用 gVisor TUN),因此 noKernelTun 在入站模式下无效。
以下字段当前仅对 WireGuard 出站生效(WireGuard 入站会忽略):
workersreserved(必须为空或 3 字节)domainStrategy