Wireless connection won't auto connect when VPN is set to auto connect
I have a wireless connection that connects automatically on its own just fine. In network settings it is set to:
"Automatically connect when it is available" & "All users may connect to this network".
When I check the box "Automatically connect to VPN when using this connection" it stops automatically connecting all together. What happens is the wireless icon spins as if it is trying to connect, then the disconnected notification pops up a couple times as if it failed. When I then manually click the wireless connection in the drop down it connects and logs into the VPN perfectly.
After searching the internet for solutions the only answer I found was to unencrypt my default key ring. I am on a personal desktop so this is potentially fine however it didn't fix my issue.
Any help debugging or advice getting me closer to a solution would be greatly appreciated. Thanks!
Edit - In case it matters, my wireless card is a Rosewill RNWD-N9003PCe.
Solution 1:
I found a solution here.
First, figure out the UUID of your VPN connection.
nmcli con list | grep -i vpn
The UUID is the second column with the letters, numbers and dashes.
Simple solution: Add the following command to the startup application list. (Follow the above link to see how.)
nmcli con up uuid <put you UUID here>
Complicated/Advanced solution: It takes my wifi a while to connect, so if the above command is run immediately at startup (before wifi is connected), it will fail, without retrying. So I wrote a shell script to run at startup, which tries to connect every few seconds (and eventually gives up if it can't connect).
#This script autoconnects a vpn on startup.
#It just runs the vpn connect command in a while loop.
#Whatever is returned by nmcli con list | grep -i vpn
VPN_UUID=<Whatever your UUID is>
VPN_RETRY_TIME=2 #how many seconds until you retry?
MAX_RETRIES=30 #how many time will you try before you give up?
#run the command once, so the while loop has
#something to check the first time around
nmcli con up uuid $VPN_UUID
SUCCESS=($? = 0)
ATTEMPT_COUNT=1 #the number of times we've tried to connect.
#$ATTEMPT_COUNT <= $MAX_RETRIES
while [[ (!$SUCCESS) && ATTEMPT_COUNT -le MAX_RETRIES ]];
do
sleep $VPN_RETRY_TIME #it just keeps on trying
nmcli con up uuid $VPN_UUID
SUCCESS=($? = 0)
ATTEMPT_COUNT=$((ATTEMPT_COUNT+1))
done
Save the above code into a .sh file somewhere. Edit it so that "Whatever your UUID is" (line 5) is the long, complicated number you got from the first command. Make it executable (chmod +x fileName.sh), and then add it to the startup application list.)