Linux – OpenVPN run script after tunnel is set up

bashlinuxopenvpnping

I'm having a hard time figuring out exactly how can I update my A records on my cloudflare account. I have already set up a script that checks for IP changes, and pushes the changes through the CloudFlare API. The problem comes where, because I'm using the

up /usr/local/bin/script

directive, the script gets called when the TUN/TAP device is set up. (So I still have no IP change). I need it to run after the tunnel has been successfully applied.

I've tried using up-delay directive, and pinging (because it's an UDP server). But this doesn't seem to work either. It looks like this:

script-security 2
ping 10
ping-restart 60
up-delay /usr/local/bin/script
down /usr/local/bin/script

I've also tried setting a sleep 30 command inside the script itself, to be able to launch it with the up command, problem being, if I do this, OpenVPN waits for the script to complete before continuing the connection process (so the process pauses for 30 seconds, in which the OpenVPN connection process is also paused, therefore making it just 30 seconds longer).

Any ideas? Maybe the server doesn't reply to ping requests? I'm 100% lost here.

Best Answer

Did you check: ipchange cmd instead of up cmd?

Execute as:

cmd ip_address port_number

From the openvpn man:

If you are running in a dynamic IP address environment where the IP addresses of either peer could change without notice, you can use this script, for example, to edit the /etc/hosts file with the current address of the peer. The script will be run every time the remote peer changes its IP address.

Related Topic