openvpn建立时如何执行多个脚本?

openvpn建立时如何执行多个脚本?

我在用Ubuntu 12.04连接到 openvpn 服务器。

两个脚本,更新解析配置vpn-up.sh,在 /etc/openvpn 中应该在建立连接时执行。

在configure文件中增加以下命令客户端.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

但是,在连接期间,只执行第一个脚本。每次我都必须运行脚本vpn-up.sh手动单独操作。所以我想知道当建立 openvpn 隧道时如何让它们都工作?

答案1

一个快速的破解方法是从最后一个脚本的末尾调用第二个脚本:

只需将以下内容添加到“/etc/openvpn/update-resolv-conf”脚本的末尾:

/etc/openvpn/vpn-up.sh

我相信这里的人们会提供更优雅的方法来做到这一点。

答案2

仅供参考。如果您有几个脚本并且时间不是很重要,您也可以使用另一个参数来执行脚本。

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.

https://openvpn.net/index.php/open-source/documentation/manuals/65-openvpn-20x-manpage.html

答案3

up '/bin/bash -c "/etc/openvpn/update-resolv-conf; /etc/openvpn/vpn-up.sh"'

相关内容