How can I associate a script to OpenVPN so that it runs when the VPN is connected successfully?
|
Pass
From the OpenVPN manpage: --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.
There are more events for script execution, those can be found on the manual page. Create
Note that this |
|||||||||||||||||||||
|
|
To the question: "How can I associate a script to OpenVPN so that it runs when the VPN is connected successfully?" I want to point out that Lekensteyn provided an excellent answer. But, at the time his answer was composed, it lacked a little clarity on how openvpn command line arguments should be provided to start openvpn on an ubuntu machine, especially so that it works the same after reboots. Openvpn command line arguments on Ubuntu:Naturally, one can start openvpn from a command line with any avalable legal options. But, on an Ubuntu machine, if one wants to start openvpn with the same command line arguments after a reboot, they should consider editing the file
From the community openvpn man page on --script-security level
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).
OpenVPN releases before v2.3 also supported a method flag which indicated how
OpenVPN should call external commands and scripts. This could be either execve
or system. As of OpenVPN v2.3, this flag is no longer accepted. In most *nix
environments the execve() approach has been used without any issues.
Some directives such as --up allow options to be passed to the external script.
In these cases make sure the script name does not contain any spaces or the
configuration parser will choke because it can't determine where the script
name ends and script options start.
Combined with an abbreviated section on
--up cmd
Run command cmd after successful TUN/TAP device open (pre --user UID change).
cmd consists of a path to script (or executable program), optionally followed
by arguments. The path and arguments may be single- or double-quoted and/or
escaped using a backslash, and should be separated by one or more spaces.
Example:On my machine with a openpvn server.conf, I have the following lines in my
Indecently, the nat.sh sets up network address translation for routing private network traffic from openvpn clients to the public internet; which is good for when one does not trust a public WIFI access point. Aside from allowing to restart as expected after a reboot, when
Other useful options available for |
||||
|
|
|
As that is a quite old thread I'm not sure if still of interest. If you still want to use the NetworkManager to connect to a VPN you can add a simple udev rule like that:
This should run any script after the VPN is created. |
|||
|
|
network-manger-openvpn. – Oxwivi Mar 2 '11 at 17:29