I am running Ubuntu 22 and I have openvpn (client) setup to run as a service. I used to have one .conf file in /etc/openvpn and I recently added another.
When openvpn starts, or I restart it, it only connects to the vpn from the first .conf file and not the second.
If I run sudo openvpn --config secondvpn.conf
it works fine and connects.
The script for the service, in /etc/init.d, says
# Description: This script will start OpenVPN tunnels as specified
# in /etc/default/openvpn and /etc/openvpn/*.conf
I don't have any tunnels specified in /etc/default/openvpn, and both config files are in /etc/openvpn/ and have the .conf extension.
I have tried systemctl daemon-reload
but that didn't seem to help.
I also tried commenting out the LimitNPROC line in /lib/systemd/system/[email protected]. (from OpenVPN won't start as a service with config file) but that didn't make a difference.
How do I get openvpn to recognize my second config file?
This:
only applies to systems without systemd (which is written in some of mentioned files, if I am not mistaken). Ubuntu 22 uses systemd, so this script and
/etc/default/openvpn
have absolutely no effect.You have to control (enable autostart or manage by hand) each VPN instance individually. You are having a luxury of being able to control them independently, I should have been saying. It is one of the rare things that really became better after introduction of systemd (though OpenRC got the similar feature ages before).
Notice that there are two kinds of subdirectories in
/etc/openvpn
:server
andclient
, and there are three systemd unit templates in/lib/systemd/system
:[email protected]
,[email protected]
and[email protected]
(in addition toopenvpn.service
).You have to stop using that latter one and disable it and start using templates.
It works as follows:
/etc/openvpn/somename.conf
, your unit name would be[email protected]
/etc/openvpn/client/somename.conf
, your unit name would be[email protected]
/etc/openvpn/server/somename.conf
, your unit name would be[email protected]
I don't know whether there are any differences except placement of configuration file. OpenVPN doesn't strictly distinguish clients and servers, all is implemented using the same binary and depends on the config file contents (or/and command-line arguments), so systemd can hardly control that.
So you just enable your VPN instances for autostart using
systemctl enable [email protected]
and start/stop them usingstart
orstop
in place ofenable
.