Ubuntu network-manager wont start VPN at boot

I recently ran across a problem where network-manager would not start my VPN connection at boot, even though I have the ‘Connect Automatically’ option checked.

It turns out this is an existing bug that has been around for a while, and the solution is to add a script file in the /etc/network/if-up.d folder ( I call mine connect-to-vpn ).

The script is provided below, basically it waits for the required connection to become enabled, and then starts the VPN.  At the top of the script, it requires three variables to be set. The name of the connection that is required to make the VPN connection, the name of the VPN connection and your desktop username.

#! /bin/bash

REQUIRED_CONNECTION_NAME="xxx"      # change xxx to your network connection name
VPN_CONNECTION_NAME="xxx"           # change xxx to your VPN connection name
USERNAME="xxx"                      # change xxx to your desktop username

if  [[ $(nmcli con status) == *${REQUIRED_CONNECTION_NAME}*  &&  $(nmcli con status) != *${VPN_CONNECTION_NAME}* ]]
su ${USERNAME} -c "nmcli con up id ${VPN_CONNECTION_NAME}"

You can test this script by simply disabling and re-enabling the required network connection in network manager.

Good Luck!

Bookmark the permalink.

Comments are closed.