How to call a script after a tunnel is fully established

How to customize and extend your OpenVPN installation.

Moderators: TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech

Post Reply
netmass
OpenVpn Newbie
Posts: 2
Joined: Fri Sep 16, 2011 4:13 am

How to call a script after a tunnel is fully established

Post by netmass » Fri Sep 16, 2011 4:40 am

Hi all,

I have OpenVPN running in server mode. I have set up the --client-connect and --learn-address scripts and they are executing just fine.

Inside one of these scripts (either one) I want to use SSH to access the remote private VPN address over the VPN connection. The IP address of the remote is presented to the script. However, it seems that in both scripts, the tunnel is not fully established (it appears the routes have not been entered in to the VPN server).

How can I get a script called when a client connects and the tunnel is fully configured (i.e. routes added) such that an SSH to the IP address would make a successful connection?

It seems like another script option like "--tunnel-established" would be required...

Is there an easier way?

Thanks in advance for any thoughts,

- Steve

User avatar
ecrist
Forum Team
Posts: 237
Joined: Wed Nov 26, 2008 10:33 pm
Location: Northern Minnesota, USA
Contact:

Re: How to call a script after a tunnel is fully established

Post by ecrist » Fri Sep 16, 2011 5:14 am

The client-connect option should work. Try adding a few Seine delay into your script a d see if that helps.

Sent from my HTC Glacier using Tapatalk
OpenVPN Community Administrator
IRC: #openvpn, #openvpn-devel
Co-Author of Mastering OpenVPN
Author of Troubleshooting OpenVPN

User avatar
janjust
Forum Team
Posts: 2703
Joined: Fri Aug 20, 2010 2:57 pm
Location: Amsterdam
Contact:

Re: How to call a script after a tunnel is fully established

Post by janjust » Fri Sep 16, 2011 7:52 am

when the --client-connect and --learn-address scripts are executed the tunnel is indeed not completely established yet. your best bet is , like ecrist said, to wait a few seconds after the learn-address script finishes and then try to SSH to the VPN client side.

netmass
OpenVpn Newbie
Posts: 2
Joined: Fri Sep 16, 2011 4:13 am

Re: How to call a script after a tunnel is fully established

Post by netmass » Fri Sep 16, 2011 12:27 pm

Hi all,

Thanks for the feedback. So... short of "forking" some process that waits a few seconds and then does something over the tunnel, there is no way to get access to the tunnel without adding a new script callback?

- Steve

P.S. Besides complexity and timing issues, the forked process would also not have access to information about the tunnel going back down in the meantime.

Post Reply