You are hereBlogs / meck's blog / Linux: Automatically reconnect NetworkManager's VPN Plugin using D-Bus

Linux: Automatically reconnect NetworkManager's VPN Plugin using D-Bus


By meck - Posted on 10 May 2009

In a previous post, I talked about how to use D-Bus to get information about network status changes. Now, since I have been using a private VPN with my Ubuntu as a client, I came across another scenario, where a script using D-Bus could help: The VPN works fine, but sometimes just disconnects. It does not happen very often, but when it happens, it is annoying and I'd like to see it reconnecting automatically. Moreover I'd like to stay in the VPN whenever I have a network connection available. Unfortunately, I didn't found any option within the NetworkManager to manage this. I ended up in writing this script which can be invoked like autovpn <VPN_NAME>, where <VPN_NAME> is the name of the VPN which is displayed in the NetworkManager under VPNConnections. You can even run it automatically on system startup by placing it in "Startup Applications". It does two things:

It tries to connect the VPN whenever it detects an active internet connection.
It tries to reconnect the VPN, whenever it disconnects unintentionally. The number of attempts is limited to 5 and there is artificial delay of 5 seconds between attempts.

I got quite a lot of inspiration from this post and mainly used the NetworkManager D-Bus API specification to get the job done. What I also found very helpful was the dbus-monitor with the --system option to reveal the actual messages emitted by the network manager.

Thank you!! :)))

It works perfectly. :) Thanks a lot!

Вот это статейка сенкс расписали отлично видел подобное но не то