php - 只为一个接口配置 openvpn 客户端
问题描述
伙计们,我正在尝试设置打开的 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请求的公共IP不是匿名的。
我对所有这些路线设置感到非常迷茫,请帮助我:(
解决方案
通过使用这个“向上”脚本解决:
#!/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,如果不是经典网络接口
推荐阅读
- java - 写入带有子文件夹的新文件时自动创建整个路径
- c# - MSSQL CLR 函数 webreqest 401 未授权
- ios - FirebaseAnalytics:将事件记录到多个项目
- powershell - Powershell Add-Content 未添加到文件末尾
- php - Laravel 的返回值预计为 'illuminate\Http\Response',返回 'string'
- react-native - React-native-image-picker:如何以网格方式直接访问画廊图像
- powershell - Azure AD - 使用 SP 创建应用注册及其凭据
- python-3.x - 美丽的汤。如何在一次搜索中找到具有特定属性但属性值不同的标签?
- python - 如何用 100k 数据样本泛化基于序列的模型?
- bash - 在远程机器上运行两个 shell 脚本