Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    OpenVPN Script for Switching VPN Server via Crontab

    Scheduled Pinned Locked Moved OpenVPN
    5 Posts 2 Posters 1.1k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      rsaanon
      last edited by

      I currently have a OpenVPN Client configured on the pfsense to connect to my VPN Provider. In my configuration, I have specified the VPN Server that the client/pfsense should connect to (eg: region1.vpn.provider.com). What I would like is to do, via a cron job, is to switch to a set different VPN server (eg: region2, region3, ..) every 4 hours via a script. Logic for the script should be something like:

      1. Disable VPN Client Configuration, if not already disabled.
      2. Change "***server or host address*** field to reflect a different VPN server
      3. Save configuration
      4. Enable VPN Client Configuration.
      

      Does anyone already have a similar script and would be willing to share?

      K 1 Reply Last reply Reply Quote 0
      • K
        Konstanti @rsaanon
        last edited by Konstanti

        @rsaanon You can consider this option

        1. installed is 1,2.3 .... OpenVPN tunnels
        2. Firewall / schedules - create a schedule for firewall rules (1,2,3....schedules = openvpn tunnels)
        3. create a few rules on the lan interface, each of them set the gateway OpenVPN tunnel (rule 1-tunnel 1 schedule 1, rule2-tunnel2-schedule 2,.... )
        R 1 Reply Last reply Reply Quote 0
        • R
          rsaanon @Konstanti
          last edited by

          @konstanti Good idea!, but due to VPN Provider concurrent tunnel limit, I won't be able to create multiple tunnels and keep all the connections alive at the same time. Thanks for the suggestion.

          K 1 Reply Last reply Reply Quote 0
          • K
            Konstanti @rsaanon
            last edited by

            @rsaanon What vpn provider ? For example , Nordvpn supports up to 6 simultaneous connections

            R 1 Reply Last reply Reply Quote 0
            • R
              rsaanon @Konstanti
              last edited by

              @konstanti I get 3 simultaneous connections; One connection is dedicated to the pfSense box. The other two are used on family laptops when travelling.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.