Skip to content

Network Manager – Autostart VPN

UPDATE: Dorian Scholz writes in the comments; There is now a command line tool nmcli which can interact with the nm-applet and Network Manger directly. Connecting to a VPN is as easy as: nmcli con up id NAME_OF_THE_VPN

Recently I started a new job, to get my laptop on the network I first connect to their wireless LAN and then VPN into the network. Network Manager makes this fairly easily, it will automatically try and associated with the wireless network, I then have to start the VPN connection manually.

This wouldn’t be a problem if I only had to do it once or twice a day. However, wireless being wireless, drops out 4-5 times a day. While, Network Manager will automatically reassociated, I have to manually reconnect to the VPN which is a pain.

To fix this I have developed two small scripts, the first is a small shell script which will automatically call a command when connecting to certain wireless networks (/etc/NetworkManager/dispatcher.d/02runcmd). The second is a little Python script which will tell Network Manager to connect to a VPN from the command line (/usr/local/bin/nm-startvpn). When you combind these two, you get auto VPN connection goodness, yay!!

If people find this useful I might put together a config utility and properly package them.

{ 12 } Comments