Page 1 of 1

Automatically mount network drive when openvpn connects

Posted: Tue Mar 08, 2011 4:24 am
by lucasd
Hi

Is there a way or a script i can add to the config file that will automatically mount a network drive
once openvpn has connected from a clients computer to the server?

Currently i have a script which they click on once the vpn is connected but would love to automate the whole
process.

Cheers,

Lucas

Re: Automatically mount network drive when openvpn connects

Posted: Tue Mar 08, 2011 10:47 am
by janjust
yes this is possible ; add a 'up' or 'route-up' script to the config which maps the drives in the background. If you're using the OpenVPN GUI it is also possible to create a GUI-specific post-connect script: if your openvpn configuration is named <config>.ovpn then place a script named <config>_up.bat in the same directory. This script will be executed after the openvpn tunnel turns "green".

Re: Automatically mount network drive when openvpn connects

Posted: Thu Mar 10, 2011 4:42 am
by lucasd
Thanks for the help, i was able to get it to work with the <config>_up.bat
Would you have any examples you could point me in the right direction of
the --up and --route-up scripts included in the client config file.

Re: Automatically mount network drive when openvpn connects

Posted: Thu Mar 10, 2011 7:03 am
by janjust
a 'route-up' configuration in the client config file would look something like

Code: Select all

script-security 2
route-up route-up.bat
or

Code: Select all

script-security 2
route-up ..\\scripts\\route-up.bat
In the first example the route-up.bat file must be present in the same directory as the openvpn config file (usually c:\program files\openvpn\config) ; in the second example the script must be present in c:\program files\openvpn\scripts

For Windows Vista/7 client it is sometimes useful to use

Code: Select all

script-security 2 system
route-up ..\\scripts\\route-up.bat
as you can avoid some privilege escalation problems with that , but this is considered less secure.

Re: Automatically mount network drive when openvpn connects

Posted: Thu Mar 10, 2011 12:11 pm
by lucasd
perfect thanks again.