Brian Hornsby's openvpn script doesn't work after stretch update

@Loop,

When you “import” the OVPN into the addon, it creates a copy in /home/osmc/.kodi/userdata/addon_data/script.openvpn.

I suggest re-importing them or changing them in that folder.

You can confirm the exact path of the OVPN being used by using ps.

osmc@osmc-Test:~$ ps -ef |grep openvpn
root 2098 1 3 19:22 ? 00:00:00 /usr/sbin/openvpn --cd /home/osmc/.kodi/userdata/addon_data/script.openvpn --daemon --management 127.0.0.1 1337 --config /home/osmc/.kodi/userdata/addon_data/script.openvpn/blah.ovpn --log /home/osmc/.kodi/userdata/addon_data/script.openvpn/openvpn.log

1 Like

Thanks for that extra bit of info! I finally had some time this morning to set this up and check that things are working as they were before.
I went into the add-on settings and deleted all my ovpn configs (I had WAY too many) and then reimported the ones I had changed and copied over to vpn-config. The add-on is now working great!! I checked the IP by using my ssh connection and the command “curl ipv4.icanhazip.com” (Thanks @stim) and it seems to be working. One slightly worrying thing is that initially this morning that command gave me my actual home IP and not the VPN one - I had tested it last night and it was working but must have disconnected by this morning. I chose the same ovpn config as last night and it has been showing that one since. I wish there was some indication if the VPN servers connection drops. Another weird thing I noticed is that although under the OSMC/Settings/System Information it shows internet as ‘connected’, when I was checking my DNS settings under My OSMC/Network it says 'Status: eth0 (no internet). But the internet is definitely working and I can stream some video with no problem.
Anyway @gmccauley I want to thank you for all your help and for giving me that extra little bit of information which so ofter makes all the difference!!

If you want to enable automatic restart of openvpn in the event of the process being killed, see here.

Glad I could help!

Such great folks here always willing to help, it’s nice to be able to give back every once in a while.

Thats just the way it is.

No sorry, thats the Bruce Hornsby script.

Hi all,
I’m having similar issues with openvpn. I’m trying to use it independently of the Add-on but it should be doing just the same.
Everything was working fine before the December update but ever since I don’t seem to have an internet connection when the VPN is active.
curl ipinfo.io just times out when the vpn is active.

The log of my openvpn is
sudo openvpn --config US\ EastOrig.ovpn
Sat Jan 27 08:25:34 2018 OpenVPN 2.4.0 arm-unknown-linux-gnueabihf [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on Jul 18 2017
Sat Jan 27 08:25:34 2018 library versions: OpenSSL 1.0.2l 25 May 2017, LZO 2.08
Sat Jan 27 08:25:34 2018 TCP/UDP: Preserving recently used remote address: [AF_INET]208.167.254.55:1198
Sat Jan 27 08:25:34 2018 UDP link local: (not bound)
Sat Jan 27 08:25:34 2018 UDP link remote: [AF_INET]208.167.254.55:1198
Sat Jan 27 08:25:34 2018 WARNING: this configuration may cache passwords in memory – use the auth-nocache option to prevent this
Sat Jan 27 08:25:34 2018 [c0b32b019af33f76bb79148cb20adfb3] Peer Connection Initiated with [AF_INET]208.167.254.55:1198
Sat Jan 27 08:25:35 2018 TUN/TAP device tun0 opened
Sat Jan 27 08:25:35 2018 do_ifconfig, tt->did_ifconfig_ipv6_setup=0
Sat Jan 27 08:25:35 2018 /sbin/ip link set dev tun0 up mtu 1500
Sat Jan 27 08:25:35 2018 /sbin/ip addr add dev tun0 local 10.71.10.6 peer 10.71.10.5
Sat Jan 27 08:25:35 2018 Initialization Sequence Completed

Here is the output of the tun0 ifconfig while the vpn is running:
tun0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1500
inet 10.71.10.6 netmask 255.255.255.255 destination 10.71.10.5
inet6 fe80::5647:3e2f:a606:9af1 prefixlen 64 scopeid 0x20
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 100 (UNSPEC)
RX packets 5 bytes 380 (380.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 148 bytes 13567 (13.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Here are the things I already tried
- tcp rather than udp.
- --management localhost 1337
- --management 127.0.0.1 1337
- installing resolvconf

I’m really confused about what is happening and would appreciate any help.
Thanks,

Check this post

Thanks for the link. I saw it before but could not get it to work. But it indeed contains the solution. It was indeed the DNS server that was causing issues. I had to install resolvconf and I had to add 8.8.8.8 as a nameserver in the file /etc/resolv.conf. Watch out that it is modified at reboot.

Hi, I have Brian Hornsby openvpn script installed but cannot make it autostart. I try:

sudo mkdir /etc/systemd/system/openvpn@.service.d
sudo nano /etc/systemd/system/openvpn@.service.d/restart.conf
and in the file paste these three lines:

[Service]
Restart=always
RestartSec=5

and this:

It’s very easy in OSMC - and we do use systemd.

To enable OpenVPN to run at startup, run:

sudo systemctl enable openvpn

To specify which config file to run, you need to:

1 Place the config file in /etc/openvpn and give it a .conf suffix, not .ovpn.

2 Edit file /etc/default/openvpn and add a line

AUTOSTART=“NL”

so that it will look for file /etc/openvpn/NL.conf.

Then restart and see if it’s working as you expect.

but nothing work with that script. I also ask on script github but meybe You can help me?
Regards.

You say it doesn’t work, do you get any errors? Can you run those relevant commands with no issues?

Yes, everything looks OK but when I restart OSMC nothing happen and I must run openvpn from Kodi addons.

Hi,

I think dilthedog is referring to using systemd without the brian Hornsby addon. So you need to make sure the vpn configuration (comes as a opvn file) exists in:

/etc/openvpn/client

As a conf file, then open vpn should work on startup.

If not who is your openvpn provider?

Thanks Tom.

1 Like

Hi, thanks for reply, I have only osmc.conf (I rename my osmc.opvn fille) in /etc/openvpn/. Now I copy my osmc.ovpn file to that folder but don’t work either.

Hi,

The file needs to be called:

osmc.conf.

Whats output of:

cat /lib/systemd/system/openvpn@.service

&

cat /lib/systemd/system/openvpn.service

Thanks Tom.

I have now two files in /etc/openvpn/clients: osmc.conf and osmc.ovpn.
cat /lib/systemd/system/openvpn@.service

[Unit]
Description=OpenVPN connection to %i
PartOf=openvpn.service
ReloadPropagatedFrom=openvpn.service
Before=systemd-user-sessions.service
Documentation=man:openvpn(8)
Documentation=https://community.openvpn.net/openvpn/wiki/Openvpn23ManPage
Documentation=https://community.openvpn.net/openvpn/wiki/HOWTO

[Service]
PrivateTmp=true
KillMode=mixed
Type=forking
ExecStart=/usr/sbin/openvpn --daemon ovpn-%i --status /run/openvpn/%i.status 10 --cd /etc/openvpn --config /etc/openvpn/%i.conf --writepid /run/openvpn/%i.pid
PIDFile=/run/openvpn/%i.pid
ExecReload=/bin/kill -HUP $MAINPID
WorkingDirectory=/etc/openvpn
ProtectSystem=yes
CapabilityBoundingSet=CAP_IPC_LOCK CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_RAW CAP_SETGID CAP_SETUID CAP_SYS_CHROOT CAP_DAC_READ_SEARCH CAP_AUDIT_WRITE
LimitNPROC=10
DeviceAllow=/dev/null rw
DeviceAllow=/dev/net/tun rw

[Install]
WantedBy=multi-user.target

and
cat /lib/systemd/system/openvpn.service

# This service is actually a systemd target,
# but we are using a service since targets cannot be reloaded.

[Unit]
Description=OpenVPN service
After=network.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/true
ExecReload=/bin/true
WorkingDirectory=/etc/openvpn

[Install]
WantedBy=multi-user.target

I also see this and don’t understand:

osmc@osmc:~$ sudo systemctl enable openvpn
Synchronizing state of openvpn.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable openvpn
osmc@osmc:~$ sudo systemctl status openvpn
● openvpn.service - OpenVPN service
   Loaded: loaded (/lib/systemd/system/openvpn.service; enabled; vendor preset: enabled)
   Active: active (exited) since Mon 2020-03-16 17:58:41 CET; 22min ago
 Main PID: 344 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/openvpn.service

mar 16 17:58:41 osmc systemd[1]: Starting OpenVPN service...
mar 16 17:58:41 osmc systemd[1]: Started OpenVPN service.

Hi,

Sorry /etc/openvpn/client is on buster, please move osmc.conf to /etc/openvpn/

Then issue:

sudo systemctl start openvpn@osmc

Then provide the out of:

systemctl status openvpn@vpn

Thanks Tom.

1 Like

I have that:

osmc@osmc:/etc/openvpn$ sudo systemctl start openvpn@osmc
Job for openvpn@osmc.service failed because the control process exited with error code.
See "systemctl status openvpn@osmc.service" and "journalctl -xe" for details.
osmc@osmc:/etc/openvpn$ systemctl status openvpn@osmc.service
● openvpn@osmc.service - OpenVPN connection to osmc
   Loaded: loaded (/lib/systemd/system/openvpn@.service; disabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/openvpn@.service.d
           └─restart.conf
   Active: activating (auto-restart) (Result: exit-code) since Mon 2020-03-16 20:38:33 CET; 2s ago
     Docs: man:openvpn(8)
           https://community.openvpn.net/openvpn/wiki/Openvpn23ManPage
           https://community.openvpn.net/openvpn/wiki/HOWTO
  Process: 32401 ExecStart=/usr/sbin/openvpn --daemon ovpn-osmc --status /run/openvpn/osmc.status 10 --cd /etc/openvpn --config /etc/openvpn/osmc.conf --writepid /run/openvpn/osmc.pid (code=exited, status=1/FAILURE)

mar 16 20:38:33 osmc systemd[1]: openvpn@osmc.service: Unit entered failed state.
mar 16 20:38:33 osmc systemd[1]: openvpn@osmc.service: Failed with result 'exit-code'.
osmc@osmc:/etc/openvpn$ 

Hi,

Sorry I forget a couple of steps, been a while since I set this up:

Create the following file:

/etc/openvpn/pass.txt

with the following contents:

vpnusername
vpnpassword**

Then in osmc.conf change the following line:

auth-user-pass

to

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

Then issue:

sudo systemctl start openvpn@osmc

whats the out of:

systemctl status openvpn@osmc now?

** - These need to be username and password provided by your vpn provider.

Thanks Tom.

1 Like

OK, it’s working now and autostart is on. I copy that file and do in terminal:
sudo systemctl start openvpn@osmc.service
and
sudo systemctl enable openvpn@osmc.service

osmc@osmc:~$ systemctl status openvpn@osmc.service
● openvpn@osmc.service - OpenVPN connection to osmc
   Loaded: loaded (/lib/systemd/system/openvpn@.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/openvpn@.service.d
           └─restart.conf
   Active: active (running) since Mon 2020-03-16 21:03:50 CET; 6min ago
     Docs: man:openvpn(8)
           https://community.openvpn.net/openvpn/wiki/Openvpn23ManPage
           https://community.openvpn.net/openvpn/wiki/HOWTO
 Main PID: 329 (openvpn)
   CGroup: /system.slice/system-openvpn.slice/openvpn@osmc.service
           └─329 /usr/sbin/openvpn --daemon ovpn-osmc --status /run/openvpn/osmc.status 10 --cd /etc/openvpn --config /etc/openvpn/osmc.conf --writepid /run/openvpn/osmc.pid

mar 16 21:03:57 osmc ovpn-osmc[329]: ROUTE_GATEWAY 192.168.0.1/255.255.255.0 IFACE=eth0 HWADDR=b8:27:eb:c3:4a:53
mar 16 21:04:50 osmc ovpn-osmc[329]: TUN/TAP device tun0 opened
mar 16 21:04:50 osmc ovpn-osmc[329]: TUN/TAP TX queue length set to 100
mar 16 21:04:50 osmc ovpn-osmc[329]: do_ifconfig, tt->did_ifconfig_ipv6_setup=0
mar 16 21:04:50 osmc ovpn-osmc[329]: /sbin/ip link set dev tun0 up mtu 1500
mar 16 21:04:51 osmc ovpn-osmc[329]: /sbin/ip addr add dev tun0 10.8.0.4/24 broadcast 10.8.0.255
mar 16 21:04:51 osmc ovpn-osmc[329]: /sbin/ip route add 217.61.63.183/32 via 192.168.0.1
mar 16 21:04:51 osmc ovpn-osmc[329]: /sbin/ip route add 0.0.0.0/1 via 10.8.0.1
mar 16 21:04:51 osmc ovpn-osmc[329]: /sbin/ip route add 128.0.0.0/1 via 10.8.0.1
mar 16 21:04:51 osmc ovpn-osmc[329]: Initialization Sequence Completed

Thank You very much for help.
Regards,
Przemek

1 Like