Using Plex Server with a VPN

@gadgeypop said:
For anyone using a Mac I put this together. It is a shell script/.app that finds the IP addresses of Plex.tv and routes them through your default gateway to avoid going over VPN. I’ve tested it on my setup and it works however I’d be grateful if anyone else is able to give it a try and provide some feedback.

Hey matey, looked like it works, but only for a few minutes, then I lose a connection. Its also very slow, I can only stream music, no video etc, thanks though

I’m not a mac guy, but speed should have nothing to do with his script.

For those having issues getting my windows script to work, try using OpenVPN GUI instead of the VPN provider’s software.

On another note, I just released a new script/app that I think might interest the same kind of people reading this…

"VPN Auto Connect" is a windows script will ensure you are always connected to your VPN (using OpenVPN GUI). If disconnected, it will try to reconnect to one or more pre-set ovpn configuration files. If a connection cannot be established, this script can (optionally) kill uTorrent and (optionally) send you email notifications. After a failed connection attempt, you will only be notified when a connection is re-established (i.e. you won’t get an email every X minutes if connection attempts keep failing). When a connection is re-established, you can (optionally) auto-restart uTorrent.

Read more about it and download at www.xflak40.WordPress.com

Sorry to hijack this convo, but this is the last you’ll hear from me on the subject.

This is great. New to using a VPN and was not happy when I couldn’t access Plex outside of my network. One problem I’m having though is that using PIA and their own Windows app, it works until I turn on the kill switch. When the kill switch is on the Remote Access status page in Plex lists my VPN Network Adapter IP as my private IP rather than the one assigned by my router. Is my only option here to use OpenVPN with the VPN Auto Connect script above? What I like about the PIA application is that I can enable port forwarding which I understand is much more complicated in OpenVPN

This is great, however, I have a question:

I have two NICs on my Windows Enterprise box.
2nd NIC is running as a VPN client
VPN is NOT installed on the router - I’m only trying to route internet traffic from the windows box to the VPN.

Plex runs as a service as does everything.
So, I can access the PLEX service remotely (thru the primary NIC) even if I’m OUTSIDE of my LAN (Via my DDNS FQDN which will forward me to the service port where I can manage the Plex service) But I I try to access my content outside my LAN, the server is unavailable because the service is attached to the VPN connection.

Essentially, how do I route the PLEXservice port thru my router and not thru the VPN?

I know it has something to do with routing the actual PLEX service port to my router instead of the VPN gateway, right?
Thanks,

@XFlak said:

@ms1760 said:
So I’m back. After a around six months this stopped working for me and I didn’t bother to fix it as i had no need. However I now do again and have come across something that may be disabling this for some of you. Im currently on windows 7 using this script but i also now use Kaspersky internet security 2015 (2016 breaks pia). Anyway i have noticed Kaspersky blocks this script from running. I realized this when booting up in safe mode with networking to try to figure this out. When Kaspersky is off this works flawlessly. When it is on it seems to break it. Now Kaspersky has recently (since the v58 update of pia) been blocking new services that are created in the temp folder by rubyw.exe (a necessary file for pia). I noticed this exe also opens up in the temp folder as a new instance every time. The problem I’m having is I cannot create an exclusion to this exe file as the exe runs the batch from the temp folder so Kaspersky thinks its a new service and automatically classifies it as low restricted in application control. Firewall is also reading it as a new instance every time. Any thoughts on this? I currently got the bright idea to put the batch by itself on my desktop and change the scheduler to run just the batch not the bundled exe. Hopefully this solves the problem. Ill check back. Also someone asked albeit last year what mask i got it work with … it worked for me with all of them. The first one that worked is ending in .252 i tinkered with it and got .255 to work as well. I’m currently on 255. I have yet to have a security related issue with pia but it certainly is a piTa and does not play well with other programs as does kaspersky (which breaks everything).

I have an idea to fix this, hold tight

@XFlak said:
v6 of my VPN Bypass for Plex Media Server script can be found here:
Apps | XFlak40

v6 of the script released on June 1, 2016: Changed how the exe is packaged so as to not run from the temp folder and should therefore not cause problems for folks using Kaspersky or other anti-viruses that similarly block services launched from the temp folder.

Awesome I will try this out and check back. Great work & Thank You for the help!

Current working rundown of my setup with this script
Windows 7 PIA (killswitch smallpackets ipv6, DNS leak)
My plex can be reached perfectly around vpn. Plex is on local network and I’m reaching it remotely through my mobile network on the plex app (connection reads direct)

Also Not directly related but can confirm previous script fully functioning with
sickrage > couchpotato > utorrent

This works! Thanks @XFlak !!

However, is there any way to get this working with IPv6?

So I’ve been using this for about a week and seems to work great!

Two questions -

when I connect to my server outside of my LAN, my server SHOULD say “indirect”, correct?

Also, in server settings / remote access, it says “not available outside your network” This is correct as well, right?

Again, thanks for the dope work-around!

@gadgeypop said:
For anyone using a Mac I put this together. It is a shell script/.app that finds the IP addresses of Plex.tv and routes them through your default gateway to avoid going over VPN. I’ve tested it on my setup and it works however I’d be grateful if anyone else is able to give it a try and provide some feedback.

Gadgeypop,

First off, thank you for writing something for OSX! I’ve been looking for an OSX solution for a LONG time now, as opening my server and turning off the vpn every time I want to watch something from my ps4 is getting quite annoying…

I tried your script out… Looks like it runs correctly (I see the “add host xx.xx.xx.xx: gateway xxx.xxx.x.x” lines print out in the terminal and it gave me about 6 different IPs). Also, I ran a “netstat -rn” to see if it worked and the ips are showing as being routed to the gateway.

Unfortunately, it still doesn’t look like I am getting the green check for a remote connection in plex when the VPN is on. In fact, when I launch the Plex server with the vpn on after running the script, the server actually gives me a message saying “An unclaimed media server has been found on your network. Claim it now” in which case I have to turn off the vpn so it lets me log back in, and reassign the server to my account…

Are there any other additional steps that need to be set up? A specific order these steps need to be taken in? …Router port forwarded? Manual port forward setting in Plex settings?

I am using PIA, have tested both the US NYC and CA Toronto VPNs and neither worked. I also tried setting the manual port forward in plex media settings to the port that CA Toronto forwards to with no luck.

Thanks again for your help!
Ethan

Holy crap! I figured it out!

For anyone else where this is NOT working:

so I use torgaurrd which has port opening capabilities. I opened the port via their dashboard as well as on my router (same port 32400), and was running the script every hour. I was pulling my hair out why it wasn’t working.

I found out that I was running the script every hour that was routing all the local LAN traffic to my router’s gateway (not the VPN) and this was making it conflict.

so, essentially, if you can open a port via your VPN provider, I would do that. but don’t try to run this script AND do that as they will conflict and it won’t work.

Also, an important part of this is that you must use the script that uses the subnet of the VPN (I think). that can be figured out with a simply ipconfig. someone correct me if I’m wrong here.

Hey @ethanopp sorry it took so long to reply. It was a while ago now but I don’t think there are any additional steps that I took to get this working. The main issue is getting the script to do its thing properly and it sounds like it has.

I do forward port 32400 using my router but I’m not sure why you are getting the unclaimed media server issue. I never had that myself, although you mention you restart the server after running the script - I never do this and leave the server on all the time but I don’t think that is the reason.

Have you had any luck troubleshooting since you posted your comment? Any new clues as to what is going on?

I’ve having a bit of trouble getting this working. The only script that works is the 255.0.0.0 one. I can’t connect remotely when using any of the others. Also, when I connect remotely after using the 255.0.0.0 script the Plex app says the connection is “Indirect” and says that streaming quality may be poor. Is that correct behaviour? Any ideas why I can’t get any of the other scripts to work like 255.255.255.255 or 255.255.255.0? Thanks!

@jaydee77ca said:
I’ve having a bit of trouble getting this working. The only script that works is the 255.0.0.0 one. I can’t connect remotely when using any of the others. Also, when I connect remotely after using the 255.0.0.0 script the Plex app says the connection is “Indirect” and says that streaming quality may be poor. Is that correct behaviour? Any ideas why I can’t get any of the other scripts to work like 255.255.255.255 or 255.255.255.0? Thanks!

No that’s not right. Look up what your gateway IP address is (run the command prompt as admin, type “ipconfig”, and see what your default gateway IP address is). Then search within this thread for how to hard code the gateway into the bat file. That is what got it working for me with private internet access and the 255.255.255.252 script.

@jerry121802 said:

@jaydee77ca said:
I’ve having a bit of trouble getting this working. The only script that works is the 255.0.0.0 one. I can’t connect remotely when using any of the others. Also, when I connect remotely after using the 255.0.0.0 script the Plex app says the connection is “Indirect” and says that streaming quality may be poor. Is that correct behaviour? Any ideas why I can’t get any of the other scripts to work like 255.255.255.255 or 255.255.255.0? Thanks!

No that’s not right. Look up what your gateway IP address is (run the command prompt as admin, type “ipconfig”, and see what your default gateway IP address is). Then search within this thread for how to hard code the gateway into the bat file. That is what got it working for me with private internet access and the 255.255.255.252 script.

I’m confused about this as well. Are we supposed to put the gateway of our VPN in, or the local LAN gateway 192.x.x.x.?

@seanvree@hotmail.com said:

@jerry121802 said:

@jaydee77ca said:
I’ve having a bit of trouble getting this working. The only script that works is the 255.0.0.0 one. I can’t connect remotely when using any of the others. Also, when I connect remotely after using the 255.0.0.0 script the Plex app says the connection is “Indirect” and says that streaming quality may be poor. Is that correct behaviour? Any ideas why I can’t get any of the other scripts to work like 255.255.255.255 or 255.255.255.0? Thanks!

No that’s not right. Look up what your gateway IP address is (run the command prompt as admin, type “ipconfig”, and see what your default gateway IP address is). Then search within this thread for how to hard code the gateway into the bat file. That is what got it working for me with private internet access and the 255.255.255.252 script.

I’m confused about this as well. Are we supposed to put the gateway of our VPN in, or the local LAN gateway 192.x.x.x.?

I deleted the “::” at the beginning of the line, and changed the ip address to the gateway of the local LAN 192.x.x.x. If you are using certain routers, it could start with something else, like 10.x.x.x.

I’ve been trying to get @XFlak script to work but every time I run it, it just closes real fast. I realize that’s what some .bat files do but it doesn’t seem to be working. There are no logs and the server is still inaccessible remotely.
I have deleted out the comment and put in my default gateway per the instructions but it still doesn’t seem to work.
I’m sure I’m doing something wrong somewhere.
Any help is appreciated. (I am also using PIA VPN as some others mentioned above.)

Add a pause command at the end of the bat so you can see what’s going on. If it’s crashing, move the pause further up until we identify the problematic line

Hi. Thanks for the reply. It doesn’t seem to matter where I put the pause, it still closes immediately after opening. I have tried hardwiring the gateway ip according to previous posts but other than that haven’t edited much else. Should I be editing more of the bat file?
I have also been trying to use the port forwarding steps for PIA according to some of the other posts. I have been unsuccessful at that also.
I much prefer the workaround if I can get it to work. I apologize if it’s something simple. I’ve been working on it for a while. Thanks for the help.

It works! I have been working on this for days. I was trying both your script/bat file and the other method of port forwarding through PIA. I’m glad that this works instead.

Here was the problem for me just in case someone else might be having the same.
When I ran it in cmd it was stopping after the ipconfig gateway text. The error message “The filename, directory name, or volume label syntax is incorrect.” Looking at the code after the “C:“1”>”%temp%\gateway.txt", the “>” had an extra space. After I deleted the space it worked!
(For me it was 255.255.255.252 on PIA with the earlier steps followed)

``@echo off
setlocal
set PATH=%SystemRoot%\system32;%SystemRoot%\system32\wbem;%SystemRoot%
chcp 437>nul

title VPN Bypass for Plex Media Server
chdir /d “%~dp0”
if not exist support cd…

echo VPN Bypass for Plex Media Server
echo by XFlak
echo.

::get Default Gateway
ipconfig|findstr /I /C:“Default Gateway”|findstr /I /C:“1(here–)”>"%temp%\gateway.txt"
set /p gateway= <"%temp%\gateway.txt"``

Now I need to set it up for automation but at least I know it works.
Thanks for the help. Good luck to all.

Another alternative solution here if it helps anyone :