AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1179926
Accepted
one_new_message
one_new_message
Asked: 2025-04-26 08:03:14 +0800 CST2025-04-26 08:03:14 +0800 CST 2025-04-26 08:03:14 +0800 CST

Wireguard 突然不工作;已收到数据包但未进行握手

  • 772

我的 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未安装。

任何建议都值得赞赏。

networking
  • 1 1 个回答
  • 118 Views

1 个回答

  • Voted
  1. Best Answer
    one_new_message
    2025-04-27T06:39:25+08:002025-04-27T06:39:25+08:00

    我遗漏了表iptables中的一条规则filter(需要将其添加为INPUT链中的第一条规则):

    iptables -I INPUT 1 -j ACCEPT
    

    现在 WireGuard 连接成功了。我之前误解了处理数据包的顺序iptables,以为这样-P INPUT ACCEPT就足够了。现在有了可用的配置,我可以用一条更具选择性(更安全)的规则替换这条规则。

    • 1

相关问题

  • 谁能指出我的 802.11n 范围扩展器?

  • 我怎样才能得到一个网站的IP地址?

  • 在一个 LAN 中使用两台 DHCP 服务器

  • 如何在 Linux 下监控每个进程的网络 I/O 使用情况?

  • 为本地网络中的名称解析添加自定义 dns 条目

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve