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