我正在使用ubuntu 12.04连接到 openvpn 服务器。
建立连接时应执行 /etc/openvpn 中的两个脚本update-resolv-conf和vpn-up.sh。
在配置文件client.ovpn中添加以下命令,使两个脚本在openvpn连接时运行,openvpn断开时停止:
script-security 2
up /etc/openvpn/update-resolv-conf
up /etc/openvpn/vpn-up.sh
down /etc/openvpn/vpn-down.sh
down /etc/openvpn/update-resolv-conf
Run Code Online (Sandbox Code Playgroud)
但是,在连接期间仅执行第一个脚本。每次我必须手动单独运行脚本vpn-up.sh 时。所以我想知道如何在建立 openvpn 隧道时让它们都工作?
dro*_*ren 10
仅供参考。如果您有几个脚本并且时间并不重要,您还可以使用另一个参数来执行脚本。
Script Order of Execution
--up
Executed after TCP/UDP socket bind and TUN/TAP open.
--tls-verify
Executed when we have a still untrusted remote peer.
--ipchange
Executed after connection authentication, or remote IP address change.
--client-connect
Executed in --mode server mode immediately after client authentication.
--route-up
Executed after connection authentication, either immediately after, or some number of seconds after as defined by the --route-delay option.
--client-disconnect
Executed in --mode server mode on client instance shutdown.
--down
Executed after TCP/UDP and TUN/TAP close.
--learn-address
Executed in --mode server mode whenever an IPv4 address/route or MAC address is added to OpenVPN's internal routing table.
--auth-user-pass-verify
Executed in --mode server mode on new client connections, when the client is still untrusted.
Run Code Online (Sandbox Code Playgroud)
https://openvpn.net/index.php/open-source/documentation/manuals/65-openvpn-20x-manpage.html
一个快速的技巧是从最后一个脚本的末尾调用第二个脚本:
只需将以下内容添加到“/etc/openvpn/update-resolv-conf”脚本的末尾:
/etc/openvpn/vpn-up.sh
我相信这里的人们会提供一种更优雅的方式来做到这一点。