Page 1 of 1

Ping in remote network does not work from --up script

Posted: Sat Dec 26, 2020 6:20 am
by Molt
Hey there, I thought I would try a rather simple setup for the beginning. Sadly fail quite early :-(

What I try is, to run a cronjob every night, which sets up an OpenVPN tunnel to a remote machine and then starts the backup script.


What works:

Code: Select all

    sudo openvpn --config /home/molt.ovpn
and then in another window:

Code: Select all

    ping 10.8.0.1

What does not work:

Code: Select all

    sudo openvpn --config /home/molt.ovpn --up /home/scripts/backup-worker.sh
I also tried --route-up

with backup-worker.sh:

Code: Select all

    ping -c 1 -W 120 10.8.0.1
What's going wrong?

I am on

Code: Select all

Ubuntu 18.04.5 LTS (Bionic Beaver)
OpenVPN 2.4.4 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on May 14 2019

Any help really appreciated, being stuck there since weeks o_O

Re: Ping in remote network does not work from --up script

Posted: Sat Dec 26, 2020 2:14 pm
by TinCanTech
OpenVPN expects all scripts to complete before the tunnel will pass data. It is a security measure ..

Re: Ping in remote network does not work from --up script

Posted: Sun Dec 27, 2020 5:19 am
by Molt
thanks!
So I hope there is also an idea how to send data then :-)

How is my use case supposed to be implemented? Having a script, which starts the tunnel in the background and asynchronously loops pinging and starts sending data, once the ping is successful?

Or is the idea to have the tunnel open as daemon 24/7?

Re: Ping in remote network does not work from --up script

Posted: Sun Dec 27, 2020 3:31 pm
by TinCanTech
Correction; Openvpn expects all scripts started by the openvpn binary to complete successfully before it will pass data over the tunnel.

The script you use to start openvpn can do whatever you like.

Re: Ping in remote network does not work from --up script

Posted: Mon Jan 04, 2021 6:35 am
by Molt
So the only option is to start the tunnel from within a script which afterwards while-loops until pinging a certain IP is successful and only then starts sending data?

Shouldn't it be a major use-case to setup a tunnel and then send data? Is the only supported use-case to have the tunnel open all the time?