Scheduled OpenVPN client reconnect

Started by senses118, August 07, 2024, 01:57:19 PM

Previous topic - Next topic
August 07, 2024, 01:57:19 PM Last Edit: August 08, 2024, 07:32:35 PM by senses118
I'm running an OpenVPN client on opnsense to a VPN provider for all my network devices to share. I would like to reconnect daily to refresh the IP. Looking at the standard Cron options there is 'Periodic interface reset' which doesn't seem to create a new IP when used on the VPN interface. I see there is also 'Restart Wireguard'. But nothing for OpenVPN by default.

Can anyone offer a suitable command and parameters to cron an OpenVPN disconnect / reconnect? Any help greatly appreciated.

August 08, 2024, 07:28:24 PM #1 Last Edit: August 14, 2024, 11:29:35 AM by senses118
Got what I needed working. Instead of leaving this as a worthless empty post for someone to trip over while searching for a solution (be handy if we could delete posts?), here's what I did in summary:

1. SSH into OPNsense as root or a user with su
2. Go to: /usr/local/opnsense/service/conf/actions.d/
3. Create a new file called something like: actions_custom.conf
4. File should contain:


[stop]
command:/usr/local/sbin/pluginctl -s openvpn stop
parameters:
type:script_output
message:stop openvpn service
description:Stop OpenVPN Service

[start]
command:/usr/local/sbin/pluginctl -s openvpn start
parameters:
type:script_output
message:start openvpn service
description:Start OpenVPN Service

[restart]
command:/usr/local/sbin/pluginctl -s openvpn restart
parameters:
type:script_output
message:restart openvpn service
description:Restart OpenVPN Service


5. Once saved, load the new template using: # service configd restart
6. In OPNsense GUI go to: System > Settings > Cron
7. Click + to add a new job and under the 'Command' lookup you should see the new Stop, Start and Restart OpenVPN options listed.


Hey, it worked perfectly on my setup. Thanks a lot for sharing, i created an account to thank you lol

August 27, 2024, 05:57:03 PM #3 Last Edit: August 27, 2024, 11:48:02 PM by senses118
Good to know it was useful!