Auto connect and reconnect to VPN on Debian 8

7,005

I got a simple solution. It works perfect on ethernet or wifi and it even restores the connection on a disconnect.

At first you have to set up a vpn connection with your networkmanger. After that you have to place a file, i named it vpnautoconnect in the /etc/network/if-up.d directory. Do not forget to replace PrivateVPN with the Name of your VPN-Connection you created before.

#!/bin/sh
# vpnautoconnect-script
# Place this file in /etc/network/if-up.d
# Set the ovpn-confgiuration by name
# nmcli con up id <ovpn-name>
nmcli con up id PrivateVPN

If you're having problems with this not working, try running ifup --all -v, it should show you any error messages related to the startup script. In case it shows you the following message:

A password is required to connect to 'PrivateVPN'.

All you need to do is click on the icon on the right hand side of the password field and select Store the password for all users, which will allow nmcli to use the password.

Share:
7,005

Related videos on Youtube

w5e
Author by

w5e

Updated on September 18, 2022

Comments

  • w5e
    w5e over 1 year

    I am searching for a way to always enforce a VPN connection with a chosen profile (ovpn or network manager) whenever I use an internet connection. I want to use OpenVPN and Debian 8.

    Is there a package or a nice script that does this?

    Have I missed some possible configuration within OpenVPN or another utility to accomplish that?