当我的以太网连接建立时,我尝试自动启动 OpenVPN(它将连接到专用互联网访问 VPN)。
我有 /etc/NetworkManager/disaptcher.d/99-custom_script_handler
#!/bin/bash
if [ "$1" = "eth0" ] && [ "$2" = "up" ]
then
echo "$(date): Starting tunnel script" >> /root/tunnel.log
/bin/bash /root/start_tunnel_script
else
echo No action for this combination
fi
这可以正常执行并启动“start_tunnel_script”
/根/启动隧道脚本
#!/bin/bash
echo "$(date): Running tunnel script as $(whoami)" >> /root/tunnel.log
LOCATION="Netherlands"
openvpn --echo --daemon --cd /etc/openvpn/client/pia_ovpn/ --config "$LOCATION.ovpn" --auth-user-pass /root/.pia_credentials --script-security 2 --syslog --up /root/bootstrap
但 OpenVPN 报告找不到配置文件
Sep 3 15:12:39 test openvpn[4056]: Options error: In [CMD-LINE]:1: Error opening configuration file: Netherlands.ovpn
Sep 3 15:12:39 test openvpn[4056]: Use --help for more information.
Sep 3 15:12:39 test nm-dispatcher: req:4 'up' [eth0], "/etc/NetworkManager/dispatcher.d/99-custom_script_handler": complete: failed with Script '/etc/NetworkManager/dispatcher.d/99-custom_script_handler' exited with error status 1.
Sep 3 15:12:39 test NetworkManager[645]: <warn> [1504465959.2123] dispatcher: (40) 99-custom_script_handler failed (failed): Script '/etc/NetworkManager/dispatcher.d/99-custom_script_handler' exited with error status 1.
Sep 3 15:12:40 test NetworkManager[645]: <info> [1504465960.9892] policy: set 'eth0' (eth0) as default for IPv6 routing and DNS
但配置文件显然存在:
# ls -al /etc/openvpn/client/pia_ovpn/
total 160
drwxr-xr-x. 2 root root 4096 Sep 2 14:37 .
drwxr-x---. 3 root root 22 Sep 2 14:37 ..
-rw-r--r--. 1 root root 295 Feb 6 2017 AU Melbourne.ovpn
-rw-r--r--. 1 root root 285 Feb 6 2017 AU Sydney.ovpn
-rw-r--r--. 1 root root 288 Feb 6 2017 Brazil.ovpn
-rw-r--r--. 1 root root 284 Feb 6 2017 CA Montreal.ovpn
-rw-r--r--. 1 root root 2025 Feb 6 2017 ca.rsa.2048.crt
-rw-r--r--. 1 root root 292 Feb 6 2017 CA Toronto.ovpn
-rw-r--r--. 1 root root 869 Feb 6 2017 crl.rsa.2048.pem
-rw-r--r--. 1 root root 289 Feb 6 2017 Denmark.ovpn
-rw-r--r--. 1 root root 284 Feb 6 2017 Finland.ovpn
-rw-r--r--. 1 root root 288 Feb 6 2017 France.ovpn
-rw-r--r--. 1 root root 289 Feb 6 2017 Germany.ovpn
-rw-r--r--. 1 root root 284 Feb 6 2017 Hong Kong.ovpn
-rw-r--r--. 1 root root 284 Feb 6 2017 India.ovpn
-rw-r--r--. 1 root root 289 Feb 6 2017 Ireland.ovpn
-rw-r--r--. 1 root root 288 Feb 6 2017 Israel.ovpn
-rw-r--r--. 1 root root 287 Feb 6 2017 Italy.ovpn
-rw-r--r--. 1 root root 287 Feb 6 2017 Japan.ovpn
-rw-r--r--. 1 root root 288 Feb 6 2017 Mexico.ovpn
-rw-r--r--. 1 root root 284 Feb 6 2017 Netherlands.ovpn
-rw-r--r--. 1 root root 284 Feb 6 2017 New Zealand.ovpn
-rw-r--r--. 1 root root 284 Feb 6 2017 Norway.ovpn
-rw-r--r--. 1 root root 284 Feb 6 2017 Romania.ovpn
-rw-r--r--. 1 root root 284 Feb 6 2017 Singapore.ovpn
-rw-r--r--. 1 root root 284 Feb 6 2017 South Korea.ovpn
-rw-r--r--. 1 root root 288 Feb 6 2017 Sweden.ovpn
-rw-r--r--. 1 root root 287 Feb 6 2017 Switzerland.ovpn
-rw-r--r--. 1 root root 288 Feb 6 2017 Turkey.ovpn
-rw-r--r--. 1 root root 291 Feb 6 2017 UK London.ovpn
-rw-r--r--. 1 root root 296 Feb 6 2017 UK Southampton.ovpn
-rw-r--r--. 1 root root 295 Feb 6 2017 US California.ovpn
-rw-r--r--. 1 root root 292 Feb 6 2017 US Chicago.ovpn
-rw-r--r--. 1 root root 289 Feb 6 2017 US East.ovpn
-rw-r--r--. 1 root root 292 Feb 6 2017 US Florida.ovpn
-rw-r--r--. 1 root root 292 Feb 6 2017 US Midwest.ovpn
-rw-r--r--. 1 root root 296 Feb 6 2017 US New York City.ovpn
-rw-r--r--. 1 root root 292 Feb 6 2017 US Seattle.ovpn
-rw-r--r--. 1 root root 298 Feb 6 2017 US Silicon Valley.ovpn
-rw-r--r--. 1 root root 290 Feb 6 2017 US Texas.ovpn
-rw-r--r--. 1 root root 289 Feb 6 2017 US West.ovpn
如果我以 root 身份从 shell 运行“start_tunnel_script”,它就可以正常工作——这就是最棒的。问题在于 start_tunnel_script 是如何启动的,但我一生都无法弄清楚有什么不同。
答案1
“pia_ovpn”文件夹上的 SELinux 上下文设置不正确
restorecon -R /etc/openvpn/client