Linux 客户端无法连接到 OpenVPN 服务器(Nexthop 的网关无效。)

Linux 客户端无法连接到 OpenVPN 服务器(Nexthop 的网关无效。)

我有一个 Linux 客户端,我正尝试将其连接到我自己托管的异地 OpenVPN 服务器。我为此绞尽脑汁了一段时间。Windows
客户端连接良好且正常工作(所有流量都已路由,可通过子网访问等),而尝试连接 Linux 客户端(尝试过 ubuntu 16.04 服务器和少量 openvpn 客户端 docker)时,似乎成功连接到了服务器,然后出现:

TUN/TAP device tun0 opened
TUN/TAP TX queue length set to 100
do_ifconfig, tt->did_ifconfig_ipv6_setup=0
/usr/bin/ip link set dev tun0 up mtu 1500

/usr/bin/ip addr add dev tun0 10.8.0.101/26 broadcast 10.8.0.127

/usr/bin/ip route add 0.0.0.0/1 via 10.8.0.1
Error: Nexthop has invalid gateway.
ERROR: Linux route add command failed: external program exited with error status: 2

/usr/bin/ip route add 128.0.0.0/1 via 10.8.0.1
Error: Nexthop has invalid gateway.
ERROR: Linux route add command failed: external program exited with error status: 2

Initialization Sequence Completed

这会阻止流量通过 VPN。看起来ifconfig正确,但(当然)iptables 看起来不太正确(在 docker 容器上测试):

# ip route
default via 172.17.0.1 dev eth0
10.8.0.64/26 dev tun0 proto kernel scope link src 10.8.0.101
172.17.0.0/16 dev eth0 proto kernel scope link src 172.17.0.7

将客户端 ovpn 移至 Windows 计算机可实现完美连接。我使用以下方式设置服务器这个安装脚本并在本指南产生服务器端设置:

./服务器.conf

port 42069
proto udp
dev tun
user nobody
group nogroup
persist-key
persist-tun
keepalive 10 120
topology subnet
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "dhcp-option DNS 208.67.222.222"
push "dhcp-option DNS 208.67.220.220"
push "redirect-gateway def1" 
crl-verify crl.pem
ca ca.crt
cert server_fWRfyP6vszBv9CaM.crt
key server_fWRfyP6vszBv9CaM.key
tls-auth tls-auth.key 0
dh dh.pem
auth SHA256
cipher AES-128-CBC
tls-server
tls-version-min 1.2
tls-cipher TLS-DHE-RSA-WITH-AES-128-GCM-SHA256
status openvpn.log
verb 3
client-config-dir /etc/openvpn/staticclients

./staticclients/[客户端名称]

ifconfig-push 10.8.0.101 255.255.255.192

以及客户端配置:

[客户端名称].ovpn

remote *** 42069
client
proto udp
dev tun
resolv-retry infinite
nobind
persist-key
remote-cert-tls server
verify-x509-name server_fWRfyP6vszBv9CaM name
auth SHA256
auth-nocache
cipher AES-128-CBC
tls-client
tls-version-min 1.2
tls-cipher TLS-DHE-RSA-WITH-AES-128-GCM-SHA256
setenv opt block-outside-dns
verb 3
<ca>
-----BEGIN CERTIFICATE-----
...

任何帮助都将不胜感激,我愿意根据需要提供更多详细信息。

答案1

./staticclients/[clientname]将子网从 255.255.255.192 (/26)更改为 255.255.255.0 (/24) 解决了该问题。

相关内容