1

I've spent hours attempting this via the if-up.d method as described in: Question 258580

The script just won't trigger and I realized that this method is outdated because Ubuntu no longer uses etc/network/interfaces - since v. 17.10 we are using Netplan.

Then I spent a couple more hours researching and trying the 'systemd service' method as described in:Question 1184648 which appears to be the more modern method, but my service fails during execution and I don't know why.

I don't know where to go from here. It would sure be nice if my ProtonVPN could connect automatically whenever I have a network connection. Please advise, sympathize, or anesthetize.

hoatzin
  • 647

2 Answers2

1

This answer is about starting ProtonVPN when connected to network, and not about the general question.

Use the OpenVPN Configuration file

See the ProtonVPN's site for how to manually configure OpenVPN for ProtonVPN.

This guide will walk you through how to create, download and set up the OVPN file from ProtonVPN.

Once you have done everything on that site open the app Advanced Network Configuration. If you can't find this app by searching for apps, then open a terminal and enter:

nm-connection-editor

Select the network you want to use VPN in. For example, Ethernet Connection, and click on the gear icon at the bottom left corner of the window.

enter image description here

Go to the General Tab and then select the check box next to Automatically connect to VPN.

Then use the drop-down menu next to it to select the ProtonVPN set up you have already done.

Repeat for each WiFi network you want to use VPN.

See 20.04LTS NetworkManager VPN - Always on for more.

A Script to run at login

Write a script that checks if there is any internet connection and if ProtonVPN has no active connections. If these conditions are met, the script will start ProtonVPN using the commandline client.

Create a script called /home/your_username/bin/start_proton. You may need to create the folder /home/your_username/bin/ to keep all your scripts. The content of the script is:

#!/bin/bash
# Sccript:/home/username/bin/start_proton 
# Purpose: Check if there is internet and if proton is not running, then start VPN

STATUS=$(protonvpn-cli status | grep No) # Checks VPN is not running ping -c1 -4 google.com > /dev/null # Check Internet is working if [[ $? -eq 0 && $STATUS == "No active Proton VPN connection." ]]; then echo $STATUS protonvpn-cli connect --fastest else echo "FAIL: Either no Internet Or VPN is running already" fi

Note: I have used the --fastest option for the VPN server choice. You may edit that line and use other options that suits you.

Make the script executable by Right-Clicking the script in Files going to its Properties > Permission Tab.

Test the script

make sure you are connected to the Internet and ProtonVPN is not running.

Open a terminal and enter the command:

start_proton

If all goes well you will see ProtonVPN starting up and connecting to its server.

Add to Startup Applications

Now open the Startup Applications app and click on the Add button. Fill up the fields as below:

Name: Start VPN
Command: /home/username/bin/start_proton
Comment: starts VPN if there is any Internet

Replace username with your username for this computer.

Click on the Save button to save the new entry. Make sure the check box next to Start VPN is checked.

Next time when you start your computer and login ProtonVPN will start.

Hope this helps

user68186
  • 37,461
1

Answering only this part

It would sure be nice if my ProtonVPN could connect automatically whenever I have a network connection.

You can use the builtin feature of Network Manager to do this.

Edit the connection you are using and tick the box Automatically Connect to VPN.

enter image description here