How do I automatically connect to a VPN on boot?
I currently use PIA as my VPN provider. I'm running Fedora 22. I know that I can run "nmcli c up <name>" to connect to the VPN or just click in the VPN gui in the upper right in Gnome. However, I was wondering how I can automatically connect to a VPN on boot. I've attempted a bunch of different things, but I can't seem to get anything to work correctly. First off I have a script to randomize the VPN I'm connecting to:
#!/bin/bash
check_vpn=`nmcli c | grep eno1 | grep US | cut -f 1,2 -d " "`
echo "VPN is currently" $check_vpn
if [ -n "$check_vpn" ];
then
nmcli c down "$check_vpn";
sleep 5;
fi
rand_num=$((RANDOM%7))
case "$rand_num" in
0)
VPN='US Florida'
;;
1)
VPN='US Texas'
;;
2)
VPN='US West'
;;
3)
VPN='US Seattle'
;;
4)
VPN='US Midwest'
;;
5)
VPN='US California'
;;
6)
VPN='US East'
;;
esac
nmcli c up "$VPN"
And then I had a systemd service to try to run this script, which I'm sure this isn't correct and could possibly be my issue:
[Unit]
Description=Custom VPN Script
[Service]
ExecStart=/usr/lib/systemd/scripts/VPN.sh start
ExecStop=/usr/lib/systemd/scripts/VPN.sh stop