我正在通过命令行使用 OpenVPN 连接到我当前 Linux 发行版上的 VPN,因为没有可用的 GUI(它有一个 killswitch 复选框)。
我的问题是,当 VPN 失效时,我找不到任何方法来添加终止开关或防止回退到我的默认连接。
这是我目前用于连接的命令:
openvpn --config /etc/openvpn/gateway.conf
Run Code Online (Sandbox Code Playgroud)
基本上,我想找到一种简单的方法来防止我的 VPN 在它断开时回退到默认连接。我只希望我的连接在 VPN 连接恢复之前停止。
网关配置文件
client
dev tun
proto udp
remote us-california.privateinternetaccess.com 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca /etc/openvpn/ca.crt
tls-client
remote-cert-tls server
auth-user-pass /etc/openvpn/login.conf
comp-lzo
verb 1
reneg-sec 0
crl-verify /etc/openvpn/crl.pem
auth-nocache
script-security 2
up /etc/openvpn/update-resolv-conf.sh
down /etc/openvpn/update-resolv-conf.sh
Run Code Online (Sandbox Code Playgroud)
源文件:https : //aur.archlinux.org/packages/private-internet-access-vpn
您应该能够通过设置具有更高度量的黑洞规则来做到这一点:对于每个路由规则,您希望添加一个具有较低优先级(较高度量)的重复路由,当 OpenVPN 的路由被拆除时,该路由将保留在原处。该附加路线是blackhole,prohibit或unreachable路线。
您应该能够通过以下方式做到这一点:
#!/bin/sh
set -e
ip route replace blackhole "$ifconfig_local/$ifconfig_netmask"
i=1
while true; do
route_network_i="$(eval echo \$route_network_$i)"
route_netmask_i="$(eval echo \$route_netmask_$i)"
route_metric_i="$(eval echo \$route_metric_$i)"
if [ -z "$route_network_i" ]; then
break
fi
ip route replace blackhole "$route_network_i"/"$route_netmask_i" metric $(( $route_metric_i + 1 ))
i=$(( $i + 1 )
done
Run Code Online (Sandbox Code Playgroud)