Simple OpenVPN autostart client connection command to be executed at session start

I have been looking at both FreeBSD specific and OpenVPN specific resources, trying to figure out how to execute a simple OpenVPN autostart client connection command at session start - without any luck. I would like to execute the following:

# openvpn /path/to/your/vpn/config/file/Vpn_Config.ovpn

Unfortunately, I don’t have any scripting or other background that I can draw on to make this happen. I am hoping that there is someone in the forum that has more insight…

Edit: Can DSBAutostart be used for this?

OpenVPN is best started via rc. From /usr/local/etc/rc.d/openvpn:

This script supports running multiple instances of openvpn.
# To run additional instances link this script to something like
# % ln -s openvpn openvpn_foo
# and define additional openvpn_foo_* variables in one of
# /etc/rc.conf, /etc/rc.conf.local or /etc/rc.conf.d/openvpn_foo
#
# Below NAME should be substituted with the name of this script. By default
# it is openvpn, so read as openvpn_enable. If you linked the script to
# openvpn_foo, then read as openvpn_foo_enable etc.
#
# The following variables are supported (defaults are shown).
# You can place them in any of
# /etc/rc.conf, /etc/rc.conf.local or /etc/rc.conf.d/NAME
#
# NAME_enable="NO"      # set to YES to enable openvpn
# NAME_if=              # driver(s) to load, set to "tun", "tap" or "tun tap"
#                       # it is OK to specify the if_ prefix.
#
# # optional:
# NAME_flags=                           # additional command line arguments
# NAME_configfile="/usr/local/etc/openvpn/NAME.conf"    # --config file
# NAME_dir="/usr/local/etc/openvpn"     # --cd directory
#
# You also need to set NAME_configfile and NAME_dir, if the configuration
# file and directory where keys and certificates reside differ from the above
# settings.
# mkdir /usr/local/etc/openvpn
# cp your_openvpn_config_file.conf /usr/local/etc/openvpn/openvpn.conf
# sysrc openvpn_enable="YES"
# sysrc openvpn_if="tun"
# sysrc openvpn_configfile="/usr/local/etc/openvpn/openvpn.conf"
# sysrc openvpn_dir="/usr/local/etc/openvpn"

Then reboot or:

# service openvpn start

Thanks for the reply. I understand a bit better now and have followed the instructions exactly. The weird thing is that I for some reason I am only able at this time to connect to the NomadBSD Forum. All other URL give the response “server not found”. Very strange. I was unable to post this reply until I ran:
# service openvpn stop

The only things that I can think of that could give this weird behavior are that I have Firefox set to:
WebRTC:
Firefox - open about:config
Search for: media.peerconnection.enabled set it to false.
AND
I have enabled DNS over HTTPS custom provider:
https://doh.mullvad.net/dns-query
However, neither of these settings were a problem when running:

# openvpn /path/to/your/vpn/config/file/Vpn_Config.ovpn

Email and I assume other Internet based services work fine with OpenVPN running…

Are there any files in the directory where you copied your openvpn config file from that are not in /usr/local/etc/openvpn/?

I have another .conf file for an alternative location that I don’t use and a text file with some notes that include the following line:

eval ": \${${name}_configfile:=\"/usr/local/etc/openvpn/${name}.conf\"}"

Nothing that is used in the cli command and certainly nothing that to my knowledge gets accessed by OpenVPN. Also, why would it only affect the web browser and no other protocols?

Very strange. I can install packages and use Lynx to surf the Internet from the cli, get my emails with Thunderbird, etc. without problems. The variable appears to be either WebRTC and / or DNS over HTTPS custom provider with Firefox. I will try to disable one at a time tomorrow and see if one of them are the problem. Otherwise, I have only physically moved my computer Denmark, so unless there is something with Danish providers where you can’t use WebRTC and / or DNS over HTTPS custom provider that I am not aware of… I use Mullvad VPN (a different VPN provider from the one that I use for my tower computer) with Wireguard for my iPad, but that works fine. No other variables that I can think of that I haven’t included in this post…

I just tried running # service openvpn stop and then tried running the one line cli command to get a VPN connection by way of OpenVPN # openvpn /path/to/your/vpn/config/file/Vpn_Config.ovpn which didn’t work either. I tried switching to another server, but that didn’t help either.

DNS over HTTPS appears to be the problem all of a sudden. I disabled it and suddenly things started working again. Perhaps Mullvads service is down? It would be interesting to try another DNS service to see if that works…

Yes, restarted and it is definitely Mullvad that is the problem.