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?

2 Answers 2


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.

# 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.


vpnautoconnect can do it.


Description : vpnautoconnect is a daemon that allow you to reconnect automatically (at startup too) a vpn create with network manager.It can reconnect very quickly and monitor the bandwith, It works with pptp and openvpn connection.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .