• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 400
  • Last Modified:

Run script in Debian 6 when VPN is established

I'm a relative novice in the inner workings of Linux... so I apologize if this is a very basic question...

I have a Linux box running Debian 6 (Squeeze). One of the applications that runs at startup is OpenVPN which establishes a VPN connection (tun0). I have a script which I currently run manually after startup which establishes routing over the VPN - it is just a series of "ip route add" statements which point packets bound for various IP ranges to the VPN tunnel.

I'm trying to find a way to run this script automatically when the box starts but can't figure out how to do this. Also it sometimes takes up to 30 seconds for the VPN to establish and if the script runs too soon it fails because the system does not yet know about tun0.

So:

<> Is there a way to get the script to run after an extended delay (say 60 seconds)?
<> Better, is there a way to get the script to run automatically when the tun0 interface comes up?
<> Or is there a better way of achieving what I'm trying to do?

I'm running the box in console mode - so no GUI.

Thanks for your help,

Regards, Chris
0
chrwil
Asked:
chrwil
  • 2
1 Solution
 
speculatrixCommented:

openvpn allows you to specify routes in the config file, just add in
"route 10.0.0.0 255.255.255.0 10.3.0.1"

for example.


for script delays, just put a "sleep 60" in the script.
0
 
chrwilAuthor Commented:

Thanks Speculatrix. Adding to the ovpnxxx.conf file is a good solution.

Do you know if there is any way of including another file into the conf file by reference (instead of inserting the long list of ip route add commands into the file itself)? I looked and couldn't see an option for this but it would be nice if there was.

If I want to stick with running a standalone script (with the sleep line) then where do I put the script and how do I tell the system to run it? I more-or-less knew how to do this in Lenny but Squeeze seems to have changed things...

Thanks, Chris
 
0
 
chrwilAuthor Commented:
Unfortunately I could not add all my routes to the ovpnxxx.conf file (my guess is that there is a limit to the size of the conf file or to the number of route commands that it can contain). My fallback was to run the separate script with sleep 60 as suggested - I managed to figure out how to use insserv to add this to the startup scripts.

Thanks, Chris
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now