为什么我的 OpenVPN 连接在约 40 秒后断开?

为什么我的 OpenVPN 连接在约 40 秒后断开?

我正在测试以下设备之间的 OpenVPN 连接:

服务器 (Amazon Linux 2)

Linux xxxxx 4.14.146-120.181.amzn2.x86_64 #1 SMP Fri Oct 18 17:01:06 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

OpenVPN 2.4.7 x86_64-redhat-linux-gnu [Fedora EPEL patched] [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on Feb 20 2019
library versions: OpenSSL 1.0.2k-fips  26 Jan 2017, LZO 2.06
Originally developed by James Yonan
Copyright (C) 2002-2018 OpenVPN Inc <[email protected]>
Compile time defines: enable_async_push=no enable_comp_stub=no enable_crypto=yes enable_crypto_ofb_cfb=yes enable_debug=yes enable_def_auth=yes enable_dependency_tracking=no enable_dlopen=unknown enable_dlopen_self=unknown enable_dlopen_self_static=unknown enable_fast_install=yes enable_fragment=yes enable_iproute2=yes enable_libtool_lock=yes enable_lz4=yes enable_lzo=yes enable_management=yes enable_multihome=yes enable_pam_dlopen=no enable_pedantic=no enable_pf=yes enable_pkcs11=yes enable_plugin_auth_pam=yes enable_plugin_down_root=yes enable_plugins=yes enable_port_share=yes enable_selinux=yes enable_server=yes enable_shared=yes enable_shared_with_static_runtimes=no enable_small=no enable_static=yes enable_strict=no enable_strict_options=no enable_systemd=yes enable_werror=no enable_win32_dll=yes enable_x509_alt_username=yes with_aix_soname=aix with_crypto_library=openssl with_gnu_ld=yes with_mem_check=no with_sysroot=no

客户端 (Yocto Linux)

Linux xxxxx 4.4.185-cip35 #1 PREEMPT Wed Oct 30 15:03:38 UTC 2019 i586 i586 i386 GNU/Linux

OpenVPN 2.4.6 i586-poky-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [MH/PKTINFO] [AEAD] built on Oct 30 2019
library versions: OpenSSL 1.1.1b  26 Feb 2019, LZO 2.10
Originally developed by James Yonan
Copyright (C) 2002-2018 OpenVPN Inc <[email protected]>
Compile time defines: enable_async_push=no enable_comp_stub=no enable_crypto=yes enable_crypto_ofb_cfb=yes enable_debug=yes enable_def_auth=yes enable_dependency_tracking=no enable_dlopen=unknown enable_dlopen_self=unknown enable_dlopen_self_static=unknown enable_fast_install=yes enable_fragment=yes enable_iproute2=yes enable_libtool_lock=yes enable_lz4=yes enable_lzo=yes enable_management=yes enable_multihome=yes enable_pam_dlopen=no enable_pedantic=no enable_pf=yes enable_pkcs11=no enable_plugin_auth_pam=no enable_plugin_down_root=yes enable_plugins=yes enable_port_share=yes enable_selinux=no enable_server=yes enable_shared=yes enable_shared_with_static_runtimes=no enable_silent_rules=no enable_small=no enable_static=no enable_strict=no enable_strict_options=no enable_systemd=no enable_werror=no enable_win32_dll=yes enable_x509_alt_username=no with_aix_soname=aix with_broken_putenv=no with_crypto_library=openssl with_gnu_ld=yes with_libtool_sysroot=/home/xxxxx/poky/build/tmp/work/i586-nlp-32-poky-linux/openvpn/2.4.6-r0/recipe-sysroot with_mem_check=no

我使用 Easy-RSA 脚本生成了密钥和证书,并将它们分发到服务器和客户端之间。服务器和客户端都创建了一个 tap0 虚拟网络适配器,我手动为服务器 tap 适配器分配了 IP 地址 192.168.20.1/24,为客户端分配了 192.168.20.2/24。服务器和客户端在同一子网上都没有其他网络适配器。

我有以下配置文件:

服务器:

proto tcp
port 1194

dev tap0

ca /etc/openvpn/ca.crt
cert /etc/openvpn/server.crt
key /etc/openvpn/server.key
dh /etc/openvpn/dh.pem

server-bridge

client-to-client

keepalive 10 120

verb 5

客户:

port 1194

ca ca.crt
cert client.crt
key client.key

client

remote-cert-tls server

auth-nocache
reneg-sec 0

dev tap0

keepalive 10 120

verb 5

我可以启动服务器,然后客户端就可以连接。然后,在初始连接后,我可以使用 IP 192.168.20.1 从客户端 ping 或建立到服务器的 SSH 连接。

然而,差不多 40 秒后,我的 ping 命令没有响应。我可以在服务器上看到它不再接收数据(动词 5 显示数据包何时被读取/写入)。我还可以看到客户端仍在“写入”数据 - 符合 ping 命令。

最终,OpenVPN 发现超时并重新连接 - 给我另外 40 秒的通信时间。

我尝试过降低 MTU 设置;我尝试过关闭身份验证和加密。我尝试过 TCP 和 UDP 连接。

我已经在 Debian 9 机器上使用相同的证书和密钥测试了完全相同的配置文件,没有发现相同的问题。因此,这几乎肯定是 Yocto Linux 客户端的问题。

相关内容