Prior to the Stretch update, I had configured OpenVPN as an init.d “service”, but post Stretch update, OSMC expects the damon to be started via systemd/systemctl.
To see if you’ve also previously configured OpenVPN as an init.d service, issue the following:
ls -las /etc/init.d/openvpn.service
if you have a file by this name, you’ll need to move it, as the default startup method is not via systemctl vs service.
sudo mv /etc/init.d/openvpn.service ~/openvpn.service
…that essentially removes the init.d “service” startup of OpenVPN.
Now you’ll need to decide if you want to use the on-system-startup process for running OpenVPN, or use the GUI OpenVPN Kodi app. The first makes the OpenVPN connection every time you start your OSMC machine and is used across ALL non-lan OSMC network traffic, whereas the second you have to do manually, via the gui, after every reboot. It just depends on what kind of addons you run whether you want constant VPN, or VPN only for use of certain addons. Depending on your ISP network speed, and VPN provider, there can be a performance hit using VPN. In some cases, it has been enough that I was only able to reliably play 720p streams vs 1080p streams.
I prefer the command-line on-bootup approach, so the rest of this post is how to migrate from the init.d “service” configuration to the new Stretch/systemd configuration.
For users with a prior configuration (i.e. when you did the first command was a file there?):
First, you’ll need to figure out where your prior VPN service provider config files are, so do the following:
sudo cat ~/openvpn.service
That file contained the following for me:
[Unit]
After=syslog.target network.target[Service]
PrivateTmp=true
Type=forking
PIDFile=/var/run/openvpn/vpn.pid
ExecStart=/usr/sbin/openvpn --daemon --writepid /var/run/openvpn/vpn.pid --cd /home/osmc/vpn-conf --config servers.ovpn[Install]
WantedBy=multi-user.target
…the relevant line is:
ExecStart=/usr/sbin/openvpn --daemon --writepid /var/run/openvpn/vpn.pid --cd /home/osmc/vpn-conf --config servers.ovpn
This tells me that I had created a subdirectory in my home directory called vpn-conf
[--cd /home/osmc/vpn-conf
], and this is where I placed my OpenVPN config files [--config servers.ovpn
].
If I list out all the files in that subdirectory I see the following:
ls -las
4 drwxr-xr-x 2 root root 4096 Jan 10 12:24 .
4 drwxr-xr-x 11 osmc osmc 4096 Jan 10 12:24 …
4 -rw-r–r-- 1 root root 1684 Dec 7 13:10 ca.ipvanish.com.crt
4 -rw-r–r-- 1 root root 29 Dec 7 13:24 login.conf
4 -rw-r–r-- 1 root root 1811 Jan 10 12:10 servers.ovpn
…this may be different for you, as it all depends on how you originally configured your init.d based OpenVPN client and your specific VPN provider. There should be a minimum of two files: the .crt
file and the .ovpn
file. If your config files are not located in your home directory, I do recommend that you move your configuration files into a subdirectory of your home directory. That makes backing up all of your “customizations” very easy in the future.
Now, to setup OpenVPN to startup at boot, via systemd, it’s pretty straightforward, create a symlink to your current .ovpn file in the new /etc/openvpn directory.
sudo ln -s ~/vpn-conf/servers.ovpn /etc/openvpn/ipvanish.conf
You can name your symlink whatever you want. I use IPVanish as my VPN provider, so I named the symlink ipvanish.conf
The import piece is that the name of the symlink MUST end in .conf
this is what systemd uses to determine which config files to run at startup.
So now read the contents of your .conf file.
sudo cat /etc/openvpn/ipvanish.conf
…for me that gives:
client
dev tun
proto udp
remote iad-a01.ipvanish.com 443
resolv-retry infinite
remote-random
nobind
persist-key
persist-tun
persist-remote-ip
ca /home/osmc/vpn-conf/ca.ipvanish.com.crt
verify-x509-name iad-a01.ipvanish.com name
auth-user-pass /home/osmc/vpn-conf/login.conf
comp-lzo
verb 3
auth SHA256
cipher AES-256-CBC
keysize 256
tls-cipher TLS-DHE-RSA-WITH-AES-256-CBC-SHA:TLS-DHE-DSS-WITH-AES-256-CBC-SHA:TLS-RSA-WITH-AES-256-CBC-SHA
The important bits to notice are that the filename for ca
and auth-user
are fully qualified! If these files names are not fully qualified it will expect them to exist in your /etc/openvpn folder, but since we want to keep all of our custom files in our home directory, just make sure the filename is fully qualified to that location!
Now, let’s test that OpenVPN works:
openvpn /etc/openvpn/ipvanish.conf
If you receive any errors, you’ll need to use the output of this command to debug your config file. If you receive no errors, then press <ctrl-C>
and Enter, which will stop the OpenVPN client connection.
Now issue:
reboot
When the system reboots, enter:
systemctl --no-pager status openvpn@*
This should give you the status of your VPN connection. If there are any errors, you’ll need to use that output to debug (but if you received no errors via the direct run above, you shouldn’t receive any errors this way).
Now to test the VPN connection. Enter:
curl http://icanhazip.com
…this should give you the VPN provided IP address (not your home network’s “external” address. To test that open a browser from another machine, and enter: http://icanhazip.com which should then show a different address that represents you ISP provided IP address).
I created a script in my home directory for easy testing in the future:
nano ~/check_vpnstatus.sh
!/bin/bash
systemctl --no-pager status openvpn@*
echo -e “=================================================\nExternal IP: via ‘curl http://icanhazip.com’”
curl http://icanhazip.com
chmod 755 ~/check_vpnstatus.sh
Now in the future all you have to do is login to your OSMC device via SSH, and execute:
./check_vpnstatus.sh