我的 Wireguard 昨天突然停止工作了,之前没有任何配置或密钥更改。为了排除故障,我将其精简到最简单的配置。我网络上的客户端应该连接到运行在 VPS 上的服务器。
服务器(“前哨”)配置:
outpost:~# cat /etc/wireguard/wg0.conf
[Interface]
PrivateKey = <outpost-privkey>
Address = 10.5.0.1/16
MTU = 1440
ListenPort = 51820
[Peer]
PublicKey = <rp-pubkey>
AllowedIPs = 10.5.0.2/32
PersistentKeepAlive = 13
客户端(“rp”)配置:
rp:~# cat /etc/wireguard/wg0.conf
[Interface]
PrivateKey = <rp-privkey>
Address = 10.5.0.2/16
MTU = 1440
[Peer]
PublicKey = <outpost-pubkey>
Endpoint = <outpost-ip>:51820
AllowedIPs = 10.5.0.1/32
PersistentKeepAlive = 23
使用dmesg
,tcpdump
我可以观察到客户端发送了反复的握手尝试:
rp:~# dmesg -wT
...
[Fri Apr 25 23:45:18 2025] wireguard: wg0: Sending handshake initiation to peer 1 (<outpost-ip>:51820)
rp:~# tcpdump -n -vvv -i ens18 udp port 51820
...
23:45:19.115710 IP (tos 0x88, ttl 64, id 34886, offset 0, flags [none], proto UDP (17), length 176)
<rp-ip>.48825 > <outpost-ip>.51820: [bad udp cksum 0x825d -> 0x3db4!] UDP, length 148
服务器收到数据包:
outpost:~# tcpdump -n -vvv -i enp0s6 udp port 51820
...
23:45:19.129033 IP (tos 0x8, ttl 55, id 34886, offset 0, flags [none], proto UDP (17), length 176)
<rp-ip>.46567 > <outpost-rp>.51820: [udp sum ok] UDP, length 148
但服务器上的 Wireguard 没有显示任何收到任何信息的迹象。
outpost:~# wg
interface: wg0
public key: <outpost-pubkey>
private key: (hidden)
listening port: 51820
peer: <rp-pubkey>
allowed ips: 10.5.0.2/32
persistent keepalive: every 13 seconds
服务器定期尝试发送自己的握手启动:
outpost:~# dmesg -wT
[Fri Apr 25 23:46:45 2025] wireguard: wg0: Sending handshake initiation to peer 1 ((einval))
但由于服务器不知道客户端的(动态)公共 IP,因此这种握手启动不会出现在使用 的服务器或客户端上tcpdump
。
两台机器使用同一个 NTP 服务器 ( ntp.ubuntu.com
),并且同步正确。我的 MTU 为 1440,已针对我的设置进行了优化,即使没有这行代码,行为也不会改变。我还多次重新生成了服务器/客户端密钥,但行为没有任何变化。
iptables 在服务器/客户端上设置正确:
# iptables -S
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
...
UFW未安装。
任何建议都值得赞赏。