Ask Your Question
1

How do I automatically connect to a VPN on boot?

asked 2016-02-05 20:56:49 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

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
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-07-29 07:15:49 -0500

fedofix gravatar image

Did you activate the openVPN server at boot ?

systemctl enable openvpn

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-02-05 20:56:49 -0500

Seen: 900 times

Last updated: Jul 29 '18