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

How to customize and extend your OpenVPN installation.

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

Post Reply
Molt
OpenVpn Newbie
Posts: 3
Joined: Sat Dec 26, 2020 6:14 am

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

Post by Molt » Sat Dec 26, 2020 6:20 am

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

TinCanTech
OpenVPN Protagonist
Posts: 11139
Joined: Fri Jun 03, 2016 1:17 pm

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

Post by TinCanTech » Sat Dec 26, 2020 2:14 pm

OpenVPN expects all scripts to complete before the tunnel will pass data. It is a security measure ..

Molt
OpenVpn Newbie
Posts: 3
Joined: Sat Dec 26, 2020 6:14 am

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

Post by Molt » Sun Dec 27, 2020 5:19 am

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?

TinCanTech
OpenVPN Protagonist
Posts: 11139
Joined: Fri Jun 03, 2016 1:17 pm

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

Post by TinCanTech » Sun Dec 27, 2020 3:31 pm

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.

Molt
OpenVpn Newbie
Posts: 3
Joined: Sat Dec 26, 2020 6:14 am

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

Post by Molt » Mon Jan 04, 2021 6:35 am

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?

Post Reply