How to connect OpenVPN automatically on BOOT using openvpn3-autoload?

I am trying to make a OpenVPN solution of my Ubuntu 20.04 VM. I found that there are two clients which can connect to OpenVPN server (running in pfSense), one is network-manager-gnome and the other is openvpn3.

For the network-manager-gnome, I can import the .ovpn file but I cannot connect to the OpenVPN server using the profile. Then I try the openvpn3, which require command-line to make it work, and it is able to connect to the OpenVPN server. I also find that the openvpn3-autoload can be used to connect to OpenVPN server by a single command.

However, I want to make an automatically solution which the desktop can connect to the OpenVPN server on startup without any manually action. I would like to know if there is a solution to do this job.

Thank you.

1 Answer

Found the solution.
Although I had read and follow the guide (), I forget to run "systemctl daemon-reload" Without this command, the systemd don't know there is a new service file

First, we need to follow the guide to make a directory, copy the client.ovpn files and make the client.autoload files for the openvpn3-autoload service
Remind to edit the privilege
chmod 600 $HOME/.openvpn3/autoload/.ovpn && chmod 600 $HOME/.openvpn3/autoload/.autoload

Then copy the service file

sudo cp /usr/lib/systemd/system/openvpn3-autoload.service /usr/lib/systemd/system/myvpn.service

and edit the service file to add the user and change the default configuration directory

sudo vim /usr/lib/systemd/system/myvpn.service

[Unit]
Description=OpenVPN 3 Linux configuration auto loader and starter
After=network.target dbus.service

[Service]
Type=oneshot
User=myusername
ExecStart=/usr/sbin/openvpn3-autoload --directory /home/myusername/.openvpn3/autoload
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Reload the daemon again, enable and start the service

systemctl daemon-reload
systemctl enable myvpn.service
systemctl start myvpn.service

Reboot the VM and confirm the result

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like