为什么 OpenVPN 客户端在 Linux 上无法连接?

为什么 OpenVPN 客户端在 Linux 上无法连接?

此 VPN 在 Windows 中工作正常,但尝试在 CentOS 中启动它会持续几秒钟,最终停止,错误日志中没有任何消息。此外,当 Windows 计算机继续运行时,服务器会立即停止响应 ping,同时进行连接。

client
dev tun
proto udp
remote 151.80.xxx.xxx 1194
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
auth SHA512
cipher AES-256-CBC
ignore-unknown-option block-outside-dns
block-outside-dns
verb 3

没有激活 VPN 的 ip r

default via 51.195.234.254 dev eth0 
51.195.234.254 dev eth0 scope link

有了它的活跃

0.0.0.0/1 via 10.8.0.1 dev tun0 
default via 51.195.234.254 dev eth0 
10.8.0.0/24 dev tun0 proto kernel scope link src 10.8.0.2 
51.195.234.254 dev eth0 scope link 
128.0.0.0/1 via 10.8.0.1 dev tun0 
151.80.xxx.xx via 51.195.234.254 dev eth0

日志

Fri May 21 19:42:19 2021 OpenVPN 2.4.11 x86_64-redhat-linux-gnu [Fedora EPEL patched] [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on Apr 21 2021
Fri May 21 19:42:19 2021 library versions: OpenSSL 1.0.2k-fips  26 Jan 2017, LZO 2.06
Fri May 21 19:42:19 2021 Outgoing Control Channel Encryption: Cipher 'AES-256-CTR' initialized with 256 bit key
Fri May 21 19:42:19 2021 Outgoing Control Channel Encryption: Using 256 bit message hash 'SHA256' for HMAC authentication
Fri May 21 19:42:19 2021 Incoming Control Channel Encryption: Cipher 'AES-256-CTR' initialized with 256 bit key
Fri May 21 19:42:19 2021 Incoming Control Channel Encryption: Using 256 bit message hash 'SHA256' for HMAC authentication
Fri May 21 19:42:19 2021 TCP/UDP: Preserving recently used remote address: [AF_INET]151.80.xxx.xxx:1194
Fri May 21 19:42:19 2021 Socket Buffers: R=[212992->212992] S=[212992->212992]
Fri May 21 19:42:19 2021 UDP link local: (not bound)
Fri May 21 19:42:19 2021 UDP link remote: [AF_INET]151.80.xxx.xxx:1194
Fri May 21 19:42:19 2021 TLS: Initial packet from [AF_INET]151.80.xxx.xxx:1194, sid=3b917597 2f279e15
Fri May 21 19:42:19 2021 VERIFY OK: depth=1, CN=ChangeMe
Fri May 21 19:42:19 2021 VERIFY KU OK
Fri May 21 19:42:19 2021 Validating certificate extended key usage
Fri May 21 19:42:19 2021 ++ Certificate has EKU (str) TLS Web Server Authentication, expects TLS Web Server Authentication
Fri May 21 19:42:19 2021 VERIFY EKU OK
Fri May 21 19:42:19 2021 VERIFY OK: depth=0, CN=server
Fri May 21 19:42:19 2021 Control Channel: TLSv1.2, cipher TLSv1/SSLv3 ECDHE-RSA-AES256-GCM-SHA384, 2048 bit RSA
Fri May 21 19:42:19 2021 [server] Peer Connection Initiated with [AF_INET]151.80.xxx.xxx:1194
Fri May 21 19:42:20 2021 SENT CONTROL [server]: 'PUSH_REQUEST' (status=1)
Fri May 21 19:42:20 2021 PUSH: Received control message: 'PUSH_REPLY,redirect-gateway def1 bypass-dhcp,dhcp-option DNS 213.186.33.99,dhcp-option DNS 213.186.33.199,route-gateway 10.8.0.1,topology subnet,ping 10,ping-restart 120,ifconfig 10.8.0.2 255.255.255.0,peer-id 0,cipher AES-256-GCM'
Fri May 21 19:42:20 2021 OPTIONS IMPORT: timers and/or timeouts modified
Fri May 21 19:42:20 2021 OPTIONS IMPORT: --ifconfig/up options modified
Fri May 21 19:42:20 2021 OPTIONS IMPORT: route options modified
Fri May 21 19:42:20 2021 OPTIONS IMPORT: route-related options modified
Fri May 21 19:42:20 2021 OPTIONS IMPORT: --ip-win32 and/or --dhcp-option options modified
Fri May 21 19:42:20 2021 OPTIONS IMPORT: peer-id set
Fri May 21 19:42:20 2021 OPTIONS IMPORT: adjusting link_mtu to 1624
Fri May 21 19:42:20 2021 OPTIONS IMPORT: data channel crypto options modified
Fri May 21 19:42:20 2021 Data Channel: using negotiated cipher 'AES-256-GCM'
Fri May 21 19:42:20 2021 Outgoing Data Channel: Cipher 'AES-256-GCM' initialized with 256 bit key
Fri May 21 19:42:20 2021 Incoming Data Channel: Cipher 'AES-256-GCM' initialized with 256 bit key
Fri May 21 19:42:20 2021 ROUTE_GATEWAY 51.195.234.254
Fri May 21 19:42:20 2021 TUN/TAP device tun0 opened
Fri May 21 19:42:20 2021 TUN/TAP TX queue length set to 100
Fri May 21 19:42:20 2021 /sbin/ip link set dev tun0 up mtu 1500
Fri May 21 19:42:20 2021 /sbin/ip addr add dev tun0 10.8.0.2/24 broadcast 10.8.0.255
Fri May 21 19:42:20 2021 /sbin/ip route add 151.80.xxx.xxx/32 via 51.195.234.254
Fri May 21 19:42:20 2021 /sbin/ip route add 0.0.0.0/1 via 10.8.0.1
Fri May 21 19:42:20 2021 /sbin/ip route add 128.0.0.0/1 via 10.8.0.1
Fri May 21 19:42:20 2021 WARNING: this configuration may cache passwords in memory -- use the auth-nocache option to prevent this
Fri May 21 19:42:20 2021 Initialization Sequence Completed

Windows ipconfig /全部

Unknown adapter OpenVPN TAP-Windows6:

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : TAP-Windows Adapter V9
   Physical Address. . . . . . . . . : 00-FF-18-08-1B-04
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::5185:de54:7498:6c08%4(Preferred)
   IPv4 Address. . . . . . . . . . . : 10.8.0.2(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : Friday, May 21, 2021 8:55:25 PM
   Lease Expires . . . . . . . . . . : Saturday, May 21, 2022 8:55:25 PM
   Default Gateway . . . . . . . . . :
   DHCP Server . . . . . . . . . . . : 10.8.0.254
   DHCPv6 IAID . . . . . . . . . . . : 184614680
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-28-38-63-9A-02-00-00-F8-D9-D4
   DNS Servers . . . . . . . . . . . : 213.186.33.99
                                       213.186.33.199
   NetBIOS over Tcpip. . . . . . . . : Enabled

Debian 10:

0.0.0.0/1 via 10.8.0.1 dev tun0 
default via 51.195.234.254 dev eth0 onlink 
10.8.0.0/24 dev tun0 proto kernel scope link src 10.8.0.2 
128.0.0.0/1 via 10.8.0.1 dev tun0

连接时 Windows ping:

C:\用户\管理员>ping 10.8.0.1

Pinging 10.8.0.1 with 32 bytes of data:
Reply from 10.8.0.1: bytes=32 time=4ms TTL=64
Reply from 10.8.0.1: bytes=32 time=4ms TTL=64
Reply from 10.8.0.1: bytes=32 time=4ms TTL=64
Reply from 10.8.0.1: bytes=32 time=4ms TTL=64

Ping statistics for 10.8.0.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 4ms, Maximum = 4ms, Average = 4ms

Linux 平:

ping 10.8.0.1
PING 10.8.0.1 (10.8.0.1) 56(84) bytes of data.

--- 10.8.0.1 ping statistics ---
5 packets transmitted, 0 received, 100% packet loss, time 3999ms

答案1

你已经指定了client,这意味着pull。该pull动词从服务器提取路由,并且服务器提供覆盖路由,通过 VPN 发送所有客户端的流量。 (man openvpn有关各种配置选项的详细信息,请参阅 参考资料。)

将所有流量配置为通过 VPN 后,对您的任何回复ping也将通过 VPN,然后丢失。这正是您的配置状态,因此日志中不会有错误。

我想,要么您的 Windows 配置略有不同,并且有一个选项可以阻止所有流量通过 VPN 路由,要么 LAN 的指标使得本地流量可以继续得到服务。

答案2

请检查您的路由表中是否存在复制粘贴错误:

0.0.0.0/1 via 10.8.0.1 dev tun0 
default via 51.195.234.254 dev eth0 
10.8.0.0/24 dev tun0 proto kernel scope link src 10.8.0.2 
51.195.234.254 dev eth0 scope link
128.0.0.0/1 via 10.8.0.1 dev tun0 

dev 是eth,而不是“eth0”,对吧?

151.80.xxx.xx via 51.195.234.254 dev eth

如果您没有出现复制粘贴错误,则意味着对于不执行拆分隧道的 VPN,您将失去与 VPN 网关的连接。

相关内容