[HOWTO] OSMC/Rasp Pi as OpenVPN client

That sound you are talking about the openvpn kodi addon, or?
Have you installed and configured openvpn on the OS level?

When run through putty, this is the log:

login as: osmc
osmc@192.168.0.5ā€™s password:

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Mon Nov 30 12:33:40 2015 from 192.168.0.3
osmc@osmc:~$ sudo openvpn /home/osmc/vpn-config/TCP/USA-FLORIDA-TCP.ovpn
Mon Nov 30 13:02:13 2015 OpenVPN 2.3.4 arm-unknown-linux-gnueabihf [SSL (OpenSSL)] [LZO] [EPOLL] [PKCS11] [MH] [IPv6] built on Dec 1 2014
Mon Nov 30 13:02:13 2015 library versions: OpenSSL 1.0.1k 8 Jan 2015, LZO 2.08
Mon Nov 30 13:02:13 2015 WARNING: file ā€˜/home/osmc/vpn-config/pass.txtā€™ is group or others accessible
Mon Nov 30 13:02:13 2015 WARNING: No server certificate verification method has been enabled. See How To Guide: Set Up & Configure OpenVPN Client/server VPN | OpenVPN for more info.
Mon Nov 30 13:02:13 2015 WARNING: file ā€˜/home/osmc/vpn-config/Wdc.keyā€™ is group or others accessible
Mon Nov 30 13:02:13 2015 Control Channel Authentication: using ā€˜/home/osmc/vpn-config/Wdc.keyā€™ as a OpenVPN static key file
Mon Nov 30 13:02:13 2015 Attempting to establish TCP connection with [AF_INET]172.111.134.3:80 [nonblock]
Mon Nov 30 13:02:14 2015 TCP connection established with [AF_INET]172.111.134.3:80
Mon Nov 30 13:02:14 2015 TCPv4_CLIENT link local: [undef]
Mon Nov 30 13:02:14 2015 TCPv4_CLIENT link remote: [AF_INET]172.111.134.3:80
Mon Nov 30 13:02:14 2015 WARNING: this configuration may cache passwords in memory ā€“ use the auth-nocache option to prevent this
Mon Nov 30 13:02:23 2015 [PureVPN] Peer Connection Initiated with [AF_INET]172.111.134.3:80
Mon Nov 30 13:02:25 2015 TUN/TAP device tun2 opened
Mon Nov 30 13:02:25 2015 do_ifconfig, tt->ipv6=0, tt->did_ifconfig_ipv6_setup=0
Mon Nov 30 13:02:25 2015 /sbin/ip link set dev tun2 up mtu 1500
Mon Nov 30 13:02:25 2015 /sbin/ip addr add dev tun2 172.111.134.194/26 broadcast 172.111.134.255
RTNETLINK answers: File exists
Mon Nov 30 13:02:28 2015 ERROR: Linux route add command failed: external program exited with error status: 2
RTNETLINK answers: File exists
Mon Nov 30 13:02:28 2015 ERROR: Linux route add command failed: external program exited with error status: 2
RTNETLINK answers: File exists
Mon Nov 30 13:02:28 2015 ERROR: Linux route add command failed: external program exited with error status: 2
Mon Nov 30 13:02:28 2015 Initialization Sequence Completed
^CMon Nov 30 13:03:25 2015 event_wait : Interrupted system call (code=4)
Mon Nov 30 13:03:25 2015 /sbin/ip addr del dev tun2 172.111.134.194/26
Mon Nov 30 13:03:25 2015 SIGINT[hard,] received, process exiting

I have been trying to follow the Brian Hornsby instructions.

It is really hard to remotely trouble shoot that and I also donā€™t think that this thread is the right place. I will sent you a PM and we can try from there

Hey, thanks A LOT for this thread. Managed to follow Bryanā€™s tutorial (followed the raspbmc steps but some things are still outdated for OSMC - be sure youā€™re on the right paths) and also your tweaks with the sudoers file.

I know just have one question: is there anyway I can auto-start this add-on, or should I just create a normal linux init script? If I go the linux startup script, wonā€™t I loose that once OSMC is updated?

Cheers and, again, big thanks!

Iā€™d like to know this too.
Pedro if you manage to figure out a working script, please share it! I have no idea how to make one of those. Would be nice to have some indication on the main screen that the OpenVPN is running.

Hey,
I ended up creating a simple startup script which gets the job doneā€¦

Just create a script:
sudo vi /etc/init.d/startOpenVPN
with

#! /bin/sh
# /etc/init.d/startOpenVPN
### BEGIN INIT INFO
# Provides:          openVPN
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Simple script to start a program at boot
# Description:       Start / stop OpenVPN at boot / shutdown.
### END INIT INFO

openvpn /{YOUR_PATH}/{yourOwn}.ovpn

(edit the last line and make sure the path to your .ovpn file is correct)

and just make executable:
sudo chmod 755 /etc/init.d/startOpenVPN

and register it to start at startup:

sudo update-rc.d startOpenVPN defaults

reboot the Pi and check if it has started:
ps aux | grep openvpn

For what I need, it gets the job done. Thanks, again, to the OP for his tweaks!

1 Like

Hello

First of all iā€™m a total noob about ssh, linux and such but i was able to success on connecting to my private vps vpn server via openVPN client on osmc. The problem is i can only connect it via ssh command without any error and working fine but when i try to connect it from OSMC interface after i choose my vpn name it says ā€œAn existing OpenVPN instance appears to be running. Disconnect it?ā€ If i say yes it asks me again and upon clicking no nothing happens. Also i tried to add an automated script which Pedro_Diogo mentioned, after i save script via :wq command and try to run sudo chmod 755 startOpenVPN it gives me an error of no such a file or directory.

As i said iā€™m total noob so please excuse me
Regards

edit: iā€™m using raspberry pi B+ with manual OSMC installation. My private vps vpn server is not local and loaded with openVpn software

edit2: When i connect with ssh command it opens 2 client connections according to OpenVPN management tool which is the maximum concurrent client at the same time.

Hello there,

If you have followed my steps exactly, you might have problems with the chmod 755 as you might not have indicated the full path of the file. Just do chmod 755 /etc/init.d/startOpenVPN instead. Iā€™ve changed my post so others do not do same mistake.

Also, in my script, make sure you provide the full path of yourOwn.ovpn file. Iā€™ve written yourOwn.ovpn only, but you should point it to where youā€™ve saved it.

If you do it my way, you wonā€™t need the openvpn add-on as the Pi will automatically connect to the VPN server overtime you start it up. Not sure if thatā€™s what you want, though.

Let me know if you made it work.

The problem is the addon wonā€™t connect to the vpn server no matter how long i wait so thatā€™s why i need to use ssh command to connect. Should i delete the addon if i want to automate this process via your method?

Do you need Kodi on the Rasperry Pi to run the OpenVPN software?

Iā€™d like to setup my Raspberry Pi 2 running OSMC and NOT Kodi to establish an openVPN connection then on my FireTV Iā€™d to connect the Kodi part only not the fireTV to go through the Raspberry Pi OpenVPN, is this possible???

If you are running OSMC then YOU ARE running Kodi!!
Read this:

Donā€™t know where you are gonna find networking support for FireTVā€¦ Outside the scope of OSMCā€¦
Try here - Fire TV General | XDA Forums

Yeah I keep forgetting that OSMC is written for KODI, I keep thinking of it as a dedicated OS with KODI on it :slightly_smiling:
Iā€™ll just leave KODI in the background doing nothing then and run it on of the FireTV :slight_smile:

Iā€™m running into this issue now as well. OpenVPN starts up fine if I omit the line redirect-gateway but thatā€™s the exact feature Iā€™m looking for. When I leave that setting in, I get the same route add error:

Sun Jan 10 15:23:48 2016 us=824936 ERROR: Linux route add command failed: external program exited with error status: 2
Sun Jan 10 15:23:48 2016 us=825161 /sbin/ip route add 10.10.6.1/32 via 10.10.6.45
Sun Jan 10 15:23:48 2016 us=830796 Initialization Sequence Completed

Hereā€™s my config file:

client
management localhost 1337
dev tun
proto udp
remote myvpn.com 8888
resolv-retry infinite
redirect-gateway
nobind
persist-key
persist-tun
tls-client
remote-cert-tls server
auth-user-pass /etc/openvpn/pass.txt
auth-nocache
link-mtu 1557
verb 4
reneg-sec 0
cipher AES-256-CBC
<ca>
</ca>

Have you found a solution to the routing / connman issue many people have reported?

Thanks!

Hey, first of all; thnx to all contributing to this thread: I was able to get it running (almost).

There is one thing missing: if I check my external IP, it still reports my home IP, and not my VPN providers IP. I used wtfismyip.com with a browser in OSMC to check this.

I use the same VPN on my laptop, and then my IP changes, to that of the provider. But not on my OSMC.

In OSMC is says the VPN is connected just fine.

By the way, also when I check with my VPN provider, it shows that indeed the connection was madeā€¦ but then why is the IP not changing?

I also tried curl ifconfig.me and also got my home IP.

I had this same problem and havenā€™t been able to devise a solution to determine if all traffic from OSMC/the box is being tunneled over VPN.

Iā€™ve been wrestling with this too. When starting the service I also get the error:

Sun Mar  6 12:49:47 2016 us=612102 /sbin/ip route del 0.0.0.0/0
Sun Mar  6 12:49:47 2016 us=622373 /sbin/ip route add 0.0.0.0/0 via 213.179.213.                                                                                        193
RTNETLINK answers: File exists
Sun Mar  6 12:49:47 2016 us=630310 ERROR: Linux route add command failed: extern                                                                                        al program exited with error status: 2
Sun Mar  6 12:49:47 2016 us=630612 Initialization Sequence Completed

The IP-check also fails (shows my home IP), anyone with a solution for this issue?

1 Like

FYI, after reading this whole thread and trying a few different approaches, this method ended up being the easiest for me to get OpenVPN working on my OSMC/Raspberry Pi 3. Notably, I couldnā€™t get the openVPN kodi plug-in working at all.

The only slight variation, since I was modifying the *.opvn file using vi to include the path for the password file, like odin_smash:

auth-user-pass /etc/openvpn/pass.txt

P.S. For some reason, ā€˜sudo systemctl enable openvpn@vpn.service sudo systemctl start openvpn@vpn.serviceā€™ is getting put on one line whereas it should be two seperate commands.

Hi

I have tried following the info contained in this thread to get my VPN working. I have a box already running Openelec and the VPN works fine on that following Brian Hornsbyā€™s instructions. Now I have a new Pi3 I thought Iā€™d give OSMC a go and its proving to be a pain. First off I canā€™t find an openvpn directory under user/sbin/openvpn although there is an openvpn file and this presumably has been installed following sudo apt-get install openvpn.
In the kodi B.Hornsbys settings it also pints to this file so thats what Iā€™ve used as my openvpn . Am I right??
So using the B.Hornsbys kodi app I can see it connects to the vpn but
a: my IP is still showing as my local IP in OSMC
b: After about a minute or so it disconnects from the VPN without warning.
Is this a problem with the OSMC or have I got the setup wrong.

type in the console which openvpn :smiley: in order to see where the executable is. But you should be able to run it from commandline. sudo openvpn client.conf. and then check with ipconfig if a connection is made ā€¦

Maybe the connection is timing out?