openvpn 路由脚本在被 openvpn 调用时无法执行

openvpn 路由脚本在被 openvpn 调用时无法执行

大家好,我正在关注这个脚本deluge-vpn 当脚本被 openvpn 调用时,它在下面的路由脚本中失败。如果我在没有启动脚本的情况下启动 openvpn 并单独执行脚本,它会运行良好。如果我没有正确设置它,请原谅,但任何帮助都会有很大帮助。

这是错误

/etc/openvpn/link_up_user_filter.sh  
Device "tun0" does not exist.  
Error: an inet address is expected rather than "table".  
net.ipv4.conf.all.rp_filter = 2
net.ipv4.conf.default.rp_filter = 2  
sysctl: cannot stat /proc/sys/net/ipv4/conf/tun0/rp_filter: No such file or directory

这是正确运行的结果

Nov 17 16:16:46 hp-server openvpn[48795]: /usr/sbin/ip link set dev tun0 up mtu 1500  
Nov 17 16:16:46 hp-server openvpn[48795]: /usr/sbin/ip addr add dev tun0 10.4.1.252/16 broadcast 10.4.255.255    
Nov 17 16:16:51 hp-server openvpn[48795]: /usr/sbin/ip route add 213.152.161.116/32 via 192.168.1.254  
Nov 17 16:16:51 hp-server openvpn[48795]: /usr/sbin/ip route add 0.0.0.0/1 via 10.4.0.1  
Nov 17 16:16:51 hp-server openvpn[48795]: /usr/sbin/ip route add 128.0.0.0/1 via 10.4.0.1
Nov 17 16:16:51 hp-server openvpn[48795]: Initialization Sequence Completed

脚本如下:

#!/usr/bin/env bash
SRC_DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$SRC_DIR" ]]; then SRC_DIR="$PWD"; fi
source "$SRC_DIR/vpn_base.sh"

VPN_IP=`get_nic_ip $VPNIF`
# Remove old table

ip route flush table $TABLE_ID

# Add rule to use TABLE_ID for marked packets
if [[ `ip rule list | grep -c $MARK_ID` == 0 ]]; then
ip rule add from all fwmark $MARK_ID lookup $TABLE_ID
fi

ip route replace default via $VPN_IP table $TABLE_ID
ip route append default via 127.0.0.1 dev lo table $TABLE_ID
ip route flush cache

# Set reverse path source validation to lose mode
sysctl -w net.ipv4.conf.all.rp_filter=2
sysctl -w net.ipv4.conf.default.rp_filter=2
sysctl -w net.ipv4.conf.$VPNIF.rp_filter=2    

按照要求打开openvpn.conf

client
dev tun
proto udp
remote *.*.*.* *
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
cipher AES-256-CBC
comp-lzo no
route-delay 5
verb 3
explicit-exit-notify 5
script-security 2


#up and down scripts to be executed when VPN starts or stops
up /etc/openvpn/link_up_user_filter.sh

答案1

我无法让这个脚本正常运行,因此转移到单独的网络命名空间,这正是我想要的方式。 Linux 上单个应用程序的 OpenVPN

相关内容