仅为一个接口配置 openvpn 客户端

configure openvpn client for only one interface

见鬼的伙计们, 我正在尝试设置开放式 vpn 客户端以连接到 tunnelbear vpn,并使用它在 php 中使用 curl 执行一些匿名请求。

我在远程 VPS 上这样做,所以如果我做错了,vpn 会阻止我,我不得不重新启动 vps。 实际上我的客户端配置是这样的:

client
dev tun0
proto udp
nobind
ns-cert-type server
persist-key
persist-tun
reneg-sec 0
dhcp-option DNS 8.8.8.8
dhcp-option DNS 8.8.4.4
verb 3
auth-user-pass login.key
ca CACertificate.crt
cert UserCertificate.crt
key PrivateKey.key
remote fr.lazerpenguin.com 443
cipher AES-256-CBC
auth SHA256
keysize 256
keepalive 10 30
script-security 2

我没有任何重定向网关设置,因为如果我添加它,我的所有流量都会通过 vpn,一切都会被阻止。 我只想使用 vpn 来满足一些特殊要求。

喜欢: 整个流量 -> 除了 tun0 请求外没有 vpn

我在 php 中使用这个来使用 vpn 接口: curl_setopt($ch, CURLOPT_INTERFACE, "tun0");

但流量似乎没有使用 vpn,因为 curl 请求的 public ip 不是匿名的。

我对所有这些路由设置感到非常迷茫,请帮助我:(

使用这个 "up" 脚本解决了:

#!/bin/sh

echo "$dev : $ifconfig_local -> $ifconfig_remote gw: $route_vpn_gateway"

ip route add default via $route_vpn_gateway dev $dev table 20
ip rule add from $ifconfig_local table 20
ip rule add to $route_vpn_gateway table 20
ip route flush cache

exit 0

和这个客户端会议:

   client
dev tun0
proto udp
remote fr.lazerpenguin.com 443
resolv-retry infinite
nobind
persist-key
persist-tun
ca CACertificate.crt
cert UserCertificate.crt
key PrivateKey.key
verb 5
route-method exe
route-delay 2
tun-mtu 1500
tun-mtu-extra 32
mssfix 1450
cipher AES-256-CBC
auth SHA256
keysize 256
comp-lzo
auth-user-pass login.key
script-security 2
route-noexec
route-up vpn_up.sh

现在,如果我在 curl 中将接口设置为 tun0,它将使用 openvpn,如果不是经典网络接口