我有一個 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 電腦會產生完美的連線。我設定伺服器這個安裝腳本並在以下命令的幫助下手動新增靜態IP本指南產生伺服器端設定:
./伺服器.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) 解決了這個問題。