
使っていますウブントゥ12.04openvpn サーバーに接続します。
2つのスクリプト、解決設定の更新そしてvpn-up.sh接続が確立されたときに、/etc/openvpn 内の を実行する必要があります。
次のコマンドがconfigureファイルに追加されますクライアント.ovpnopenvpn が接続したときに 2 つのスクリプトを実行し、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
簡単なハックとしては、最後のスクリプトの最後から 2 番目のスクリプトを呼び出すことです。
'/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"'