L2TP IPsec keepalive ping

He everyone,
I need help please.

I have a problem with a vpn connection (l2tp/ipsec) to a l2tp/ipsec server (CyberGhost VPN).

As long as traffic flows within half an hour, the connection is not disconnected.
If there is no traffic, the connection is disconnected and re-established exactly every half hour.
it´s strange.

Keepalive timeout in the interface (PPP L2TP Client) it does not work. i have testet.
With PPTP-Protocol it work and it gives no disconnections.

My idea:
A script that sends a ping every 20 or 25 minutes to an ip on the internet via the L2TP / IPsec interface.
But only if the interface is enabled.

Unfortunately, I don’t have much experience script language.

Can someone send me a script please?

Thank you in advance for your response

Below two commands sort of fit your requirement.
The first one sets up a static route via the vpn (assuming it’s named “vpn”) with a routing mark, so it will only apply to traffic marked for that route.
The second command sets up a scheduler that fires every 10 minutes and runs a ping with 4 packets towards google dns.

It doesn’t only run when the vpn is up, but assuming you’re not on an extremely traffic limited connection, the 24 packets x 64 bytes, per hour, it doesn’t really matter.

/ip route add dst-address=8.8.8.8/32 gateway=vpn routing-mark=vpn-keepalive
/system scheduler add interval=10m on-event="ping count=4 address=8.8.8.8 routing-table=vpn-keepalive"

Thank you for your quick response.
good idea, should work, pings go out

the couple of pings are not interested in traffic, monthly traffic is about 150gb in both directions