WireGuard 一致断开连接 - Ubuntu 服务器和 Android 客户端

WireGuard 一致断开连接 - Ubuntu 服务器和 Android 客户端

问题描述:Wireguard Android 客户端每隔约 10 分钟就会断开连接。

我疯狂的尝试e: 1. 调整 KeepAlive 2. 多次更改 IP 地址(私有)并重启服务 3. 调整 MTU

观察:客户端断线后,从客户端更改端口。(见下方日志)

[Oct10 20:01] wireguard: wg0: Receiving keepalive packet from peer 1 (CLIENT_IP:47581)
[ +32.141624] wireguard: wg0: Receiving handshake initiation from peer 1 (CLIENT_IP:40667)

提供的信息:服务器:Ubuntu 20.4 / 客户端:Android / wireguard-tools v1.0.20200513

服务器配置:

[Interface]
Address = 10.88.88.1/24
#SaveConfig = true
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
ListenPort = 8080
PrivateKey = key

[Peer]
PublicKey = key
AllowedIPs = 10.88.88.2/32, 192.168.1.0/24
PersistentKeepalive = 10

客户端配置:

[Interface]
PrivateKey = KEY
Address = 10.88.88.2/32
DNS = 8.8.8.8, 1.1.1.1
MTU = 1412
[Peer]
PublicKey = KEY
Endpoint = Server_IP:PORT
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 10

Wireguard 日志:可能是在某个断开/连接过程中

[Oct10 19:50] wireguard: wg0: Receiving handshake initiation from peer 1 (CLIENT_IP:47581)
[  +0.000007] wireguard: wg0: Sending handshake response to peer 1 (CLIENT_IP:47581)
[  +0.000136] wireguard: wg0: Keypair 44 destroyed for peer 1
[  +0.000002] wireguard: wg0: Keypair 46 created for peer 1
[  +0.134181] wireguard: wg0: Receiving keepalive packet from peer 1 (CLIENT_IP:47581)
[Oct10 19:52] wireguard: wg0: Sending keepalive packet to peer 1 (CLIENT_IP:47581)
[  +0.145818] wireguard: wg0: Receiving keepalive packet from peer 1 (CLIENT_IP:47581)
[ +22.076924] wireguard: wg0: Receiving handshake initiation from peer 1 (CLIENT_IP:47581)
[  +0.000008] wireguard: wg0: Sending handshake response to peer 1 (CLIENT_IP:47581)
[  +0.000135] wireguard: wg0: Keypair 45 destroyed for peer 1
[  +0.000002] wireguard: wg0: Keypair 47 created for peer 1
[  +0.145898] wireguard: wg0: Receiving keepalive packet from peer 1 (CLIENT_IP:47581)
[Oct10 19:54] wireguard: wg0: Receiving handshake initiation from peer 1 (CLIENT_IP:47581)
[  +0.000007] wireguard: wg0: Sending handshake response to peer 1 (CLIENT_IP:47581)
[  +0.000136] wireguard: wg0: Keypair 46 destroyed for peer 1
[  +0.000002] wireguard: wg0: Keypair 48 created for peer 1
[  +0.114982] wireguard: wg0: Receiving keepalive packet from peer 1 (CLIENT_IP:47581)
[Oct10 19:55] wireguard: wg0: Receiving keepalive packet from peer 1 (CLIENT_IP:47581)
[  +0.018194] wireguard: wg0: Sending keepalive packet to peer 1 (CLIENT_IP:47581)
[Oct10 19:56] wireguard: wg0: Receiving handshake initiation from peer 1 (CLIENT_IP:47581)
[  +0.000008] wireguard: wg0: Sending handshake response to peer 1 (CLIENT_IP:47581)
[  +0.000135] wireguard: wg0: Keypair 47 destroyed for peer 1
[  +0.000003] wireguard: wg0: Keypair 49 created for peer 1
[  +0.216988] wireguard: wg0: Receiving keepalive packet from peer 1 (CLIENT_IP:47581)
[Oct10 19:57] wireguard: wg0: Sending keepalive packet to peer 1 (CLIENT_IP:47581)
[  +0.132072] wireguard: wg0: Receiving keepalive packet from peer 1 (CLIENT_IP:47581)
[  +0.002179] wireguard: wg0: Receiving keepalive packet from peer 1 (CLIENT_IP:47581)
[Oct10 19:58] wireguard: wg0: Receiving handshake initiation from peer 1 (CLIENT_IP:47581)
[  +0.000007] wireguard: wg0: Sending handshake response to peer 1 (CLIENT_IP:47581)
[  +0.000135] wireguard: wg0: Keypair 48 destroyed for peer 1
[  +0.000002] wireguard: wg0: Keypair 50 created for peer 1
[  +0.204722] wireguard: wg0: Receiving keepalive packet from peer 1 (CLIENT_IP:47581)
[Oct10 20:00] wireguard: wg0: Receiving handshake initiation from peer 1 (CLIENT_IP:47581)
[  +0.000007] wireguard: wg0: Sending handshake response to peer 1 (CLIENT_IP:47581)
[  +0.000138] wireguard: wg0: Keypair 49 destroyed for peer 1
[  +0.000002] wireguard: wg0: Keypair 51 created for peer 1
[Oct10 20:01] wireguard: wg0: Receiving keepalive packet from peer 1 (CLIENT_IP:47581)
[ +32.141624] wireguard: wg0: Receiving handshake initiation from peer 1 (CLIENT_IP:40667)
[  +0.000007] wireguard: wg0: Sending handshake response to peer 1 (CLIENT_IP:40667)
[  +0.000136] wireguard: wg0: Keypair 50 destroyed for peer 1
[  +0.000002] wireguard: wg0: Keypair 52 created for peer 1
[  +0.130602] wireguard: wg0: Receiving keepalive packet from peer 1 (CLIENT_IP:40667)
[Oct10 20:03] wireguard: wg0: Receiving handshake initiation from peer 1 (CLIENT_IP:40667)
[  +0.000008] wireguard: wg0: Sending handshake response to peer 1 (CLIENT_IP:40667)
[  +0.000135] wireguard: wg0: Keypair 51 destroyed for peer 1
[  +0.000002] wireguard: wg0: Keypair 53 created for peer 1
[  +0.138579] wireguard: wg0: Receiving keepalive packet from peer 1 (CLIENT_IP:40667)
[Oct10 20:04] wireguard: wg0: Sending keepalive packet to peer 1 (CLIENT_IP:40667)
[  +0.032138] wireguard: wg0: Receiving keepalive packet from peer 1 (CLIENT_IP:40667)
[Oct10 20:05] wireguard: wg0: Receiving keepalive packet from peer 1 (CLIENT_IP:40667)
[ +31.605691] wireguard: wg0: Receiving handshake initiation from peer 1 (CLIENT_IP:40667)
[  +0.000008] wireguard: wg0: Sending handshake response to peer 1 (CLIENT_IP:40667)
[  +0.000135] wireguard: wg0: Keypair 52 destroyed for peer 1
[  +0.000002] wireguard: wg0: Keypair 54 created for peer 1
[  +0.171474] wireguard: wg0: Receiving keepalive packet from peer 1 (CLIENT_IP:40667)
[Oct10 20:07] wireguard: wg0: Receiving handshake initiation from peer 1 (CLIENT_IP:40667)
[  +0.000008] wireguard: wg0: Sending handshake response to peer 1 (CLIENT_IP:40667)
[  +0.000137] wireguard: wg0: Keypair 53 destroyed for peer 1
[  +0.000002] wireguard: wg0: Keypair 55 created for peer 1
[  +0.197794] wireguard: wg0: Receiving keepalive packet from peer 1 (CLIENT_IP:40667)
[Oct10 20:09] wireguard: wg0: Receiving handshake initiation from peer 1 (CLIENT_IP:40667)
[  +0.000007] wireguard: wg0: Sending handshake response to peer 1 (CLIENT_IP:40667)
[  +0.000135] wireguard: wg0: Keypair 54 destroyed for peer 1
[  +0.000002] wireguard: wg0: Keypair 56 created for peer 1
[  +0.199167] wireguard: wg0: Receiving keepalive packet from peer 1 (CLIENT_IP:40667)
[ +19.727691] wireguard: wg0: Receiving keepalive packet from peer 1 (CLIENT_IP:40667)
[  +0.173295] wireguard: wg0: Sending keepalive packet to peer 1 (CLIENT_IP:40667)
[Oct10 20:10] wireguard: wg0: Receiving keepalive packet from peer 1 (CLIENT_IP:40667)
[  +0.148877] wireguard: wg0: Sending keepalive packet to peer 1 (CLIENT_IP:40667)
[ +19.819577] wireguard: wg0: Receiving keepalive packet from peer 1 (CLIENT_IP:40667)
[  +0.148292] wireguard: wg0: Sending keepalive packet to peer 1 (CLIENT_IP:40667)
[Oct10 20:11] wireguard: wg0: Sending keepalive packet to peer 1 (CLIENT_IP:4066)

答案1

听起来客户端位于一个挑剔的 NAT 后面,该 NAT 每 10 分钟重置一次其 UDP 状态。您可能对此无能为力。

但是,从连接的两端都发送保持活动可能只会使情况变得更糟,因为它为两端不同步创造了更多机会。

从服务器端删除PersistentKeepalive设置 - 通常您应该仅在包含该设置的连接端使用此设置Endpoint

相关内容