This is an update to my post I did a few years ago on how to make a script that will automatically keep you connected to VPN. You would think that it would still work in Ubuntu 15.04, but then you would be wrong.
There are a few reasons for this:
- For some reason Ubuntu 15.04 doesn't like people adding random scripts to init.d anymore. You get errors about lsb tags and overrides.
- nmcli changed their command line options. Namely status is now show. (Why? Who knows?!)
- Since we are no longer using /etc/init.d you don't need to add your password to the VPN file in /etc/NetworkManager/system-connections/. You also don't have to change the password flags.
- Network-manager-pptp package has a bug in it where it doesn't like to connect to PPTP VPN connections and errors out.
For the second item, your script should look like this:
#!/bin/bash
while [ "true" ]
do
VPNCON=$(nmcli con show uuid d42cc2a7-a582-418c-a018-188b89fbb471 | grep VPN.VPN-STATE | awk '{print $2}')
if [[ $VPNCON != "5" ]]; then
echo "Disconnected, trying to reconnect..."
(sleep 1s && nmcli con up uuid d42cc2a7-a582-418c-a018-188b89fbb471)
else
echo "Already connected !"
fi
sleep 20
done
The only difference from my original script is changing status to show. You can read the original post on how to find the UUID of your VPN connection.
Finally, to fix the issue with network-manager-pptp I had to create a file called /etc/modules-load.d/netfilter.conf. I did that by running:
#sudo nano /etc/modules-load.d/netfilter.confI then added the following lines:
nf_nat_pptpAfter I saved that file I rebooted and VPN connected fine.
nf_conntrack_pptp
nf_conntrack_proto_gre
For the record, here are some of the errors I was getting before I created that file:
May 6 20:33:14 Media-Server NetworkManager[753]: ** Message: nm-pptp-ppp-plugin: (nm_exit_notify): cleaning up
May 6 20:33:14 Media-Server NetworkManager[753]: ** (nm-pptp-service:11430): WARNING **: pppd exited with error code 16
May 6 20:33:14 Media-Server NetworkManager[753]: <warn> VPN plugin failed: connect-failed (1)
May 6 20:33:14 Media-Server NetworkManager[753]: <info> devices removed (path: /sys/devices/virtual/net/ppp0, iface: ppp0)
May 6 20:33:14 Media-Server NetworkManager[753]: <warn> VPN plugin failed: connect-failed (1)
May 6 20:33:14 Media-Server NetworkManager[753]: <warn> VPN plugin failed: connect-failed (1)
May 6 20:33:14 Media-Server NetworkManager[753]: <info> VPN plugin state changed: stopped (6)
May 6 20:33:14 Media-Server NetworkManager[753]: <info> VPN plugin state change reason: unknown (0)
May 6 20:33:14 Media-Server NetworkManager[753]: <warn> error disconnecting VPN: Could not process the request because no VPN connection was active.
It took me a while to sort this out, and it wasn't very fun. Hopefully it will help you! If it does, let us know in the comments.