スクリプトをOpenVPNに関連付けて、VPNが正常に接続されたときに実行されるようにするにはどうすればよいですか?
ベストアンサー
network-manager-openvpn
そのような機能を提供しない場合は、openvpn
を使用する必要があります 直接。
--script-security 2 --up /path/to/your/script
を渡します 接続するときにそれに。 /etc/openvpn/
にある構成ファイルを使用している場合 、構成ファイルに次の行を追加します:
script-security 2
# run /etc/openvpn/up.sh when the connection is set up
up /etc/openvpn/up.sh
OpenVPNのマンページから:
--script-security level [method] This directive offers policy-level control over OpenVPN’s usage of external programs and scripts. Lower level values are more restrictive, higher values are more permissive. Settings for level: 0 -- Strictly no calling of external programs. 1 -- (Default) Only call built-in executables such as ifconfig, ip, route, or netsh. 2 -- Allow calling of built-in executables and user-defined scripts. 3 -- Allow passwords to be passed to scripts via environmental variables (potentially unsafe). --up cmd Shell command to run after successful TUN/TAP device open (pre --user UID change). The up script is useful for specifying route commands which route IP traffic destined for private subnets which exist at the other end of the VPN connection into the tunnel. Script Order of Execution --up Executed after TCP/UDP socket bind and TUN/TAP open. --down Executed after TCP/UDP and TUN/TAP close.
スクリプト実行のイベントは他にもあります。それらはマニュアルページにあります。
/etc/openvpn/up.sh
を作成します 、実行権限(たとえば、755または700)を付与します。 IPv6アドレスとルートを追加するためのコンテンツの例(教育目的で表示されています。直接コピーしないでください):
#!/bin/sh
# add an IPv6 address to device $dev (environment variable)
ip -6 addr add 2001:db8::1:2/112 dev $dev
# and the IPv6 route for this net using gateway 2001:db8::1
ip -6 route add 2001:db8::1:0/112 via 2001:db8::1 dev $dev
このup
に注意してください スクリプトはrootとして実行されます。 User
を指定していない場合 およびGroup
設定すると、OpenVPNはdown
のようなスクリプトを実行します ルートとしても。