When I hover the mouse over the green PIA icon in the tray, it currently displays "Connected - CA Toronto [Port: 24050].
I type that port number into Plex ""Manually specify port", then click "Publish Server". Wait several seconds and it says it is published.
I do not type anything in the "Local Port" box in the PIA client.
I do not have any special setting in my router, like port forwarding, enable UPnP, etc. Although I DID try everything in various forum suggestions for folks who couldn't get Plex to publish...like turn off all security software (especially firewall), etc. nothing helped. It was very frustrating.
I have only 'published' Plex twice, in case I ever wanted to use it. Currently, I just use it at home on a Roku.
Afterthought:
I just tried it this morning and it wouldn't publish, even after 5-6 tries with the above settings! I was trying to think what was 'different' the first two times that it worked?
Previously, I also had Vuze running (torrent-file sharing software), so I ran it and BAM...Plex would publish.
In Vuze, tools/options/connection there are two boxes to type in listening port number port. Then 'advanced network settings' ...see attached files.
Maybe Vuze is opening up the port, which allows Plex to publish?
I really don't know...but the three times that I have been able to publish, Vuze was running.
EDIT:
Further 'experimenting' reveals...if Vuze is running I can publish, but NOT without Vuze running.
for IP in $UNIQ_IP
do
iptables -t mangle -A MYPLEX -d “$IP” -j MARK --set-mark 1
iptables -I myplex -d “$IP” -j ACCEPT
done
Then set script to run hourly in Scheduler
I've recently jumped on the VPN bandwagon and have been struggling to get Plex to bypass it. I believe my setup is pretty close to yours in that my VPN connection to PIA is done on my Asus Router (running Asus-Merlin firmware(s)), I have a couple tables being setup and routes being added in OpenVPN when it opens it's connection, but that's about it. I can't for the life of me get Plex to work through it. I have a port mapping open for 32400 and have that set in Plex.
So since you managed to get this working I was hoping you could look at my config and tell me what to add and where. All of what I have I got off the Asus-Merlin forums for selective routing. Keep in mind that when OpenVPN makes it's connection it is NOT setting any default route. So ALL of my traffic goes out my normal Wan connection UNLESS I specify to send it over the VPN. It's splitting off the Plex part that is killing me.
Anyway, here is what I have:
#!/bin/sh
#
# SHELL COMMANDS FOR MAINTENANCE.
# DO NOT UNCOMMENT, THESE ARE INTENDED TO BE USED IN A SHELL COMMAND LINE
#
# List Contents by line number
# iptables -L PREROUTING -t mangle -n --line-numbers
# iptables -t mangle -L -nv --line
#
# Delete rules from mangle by line number
# iptables -D PREROUTING type-line-number-here -t mangle
#
# To list the current rules on the router, issue the command:
# iptables -t mangle -L PREROUTING
#
# Flush/reset all the rules to default by issuing the command:
# iptables -t mangle -F PREROUTING
#
# iptables -L -n -v
ip route flush table 10
ip route del default table 10
ip rule del fwmark 10 table 10
ip route flush table 12
ip route del default table 12
ip rule del fwmark 12 table 12
ip route flush cache
iptables -t mangle -F PREROUTING
ip route add default via $tun_ip dev $tun_if table 10
ip rule add fwmark 10 table 10
ip route add default via $(nvram get wan0_gateway) dev eth0 table 12
ip rule add fwmark 12 table 12
iptables -t mangle -A PREROUTING -i br0 -s 192.168.1.100 -j MARK --set-mark 10 #this is where I'm sending my Plex server to the VPN
iptables -t mangle -A PREROUTING -i br0 -s 192.168.1.100 -p tcp --dport 563 -j MARK --set-mark 12 #So Sabnzb/news can go over the wan
logger -t "($(basename $0))" $$ Setting up routes for VPN connection......
exit
---
What do I need to add to this to make Plex work? It was suggested on the other forum to add routes for 2 blocks of IP's, but that didn't do anything for me:
If you read the comments, you should get a better feel for how it works.
Make sure you also add a Port Forwarding rule through the gui for 32400 and modify the rules at the bottom of the script (found at the above link) to always set traffic on that port to bypass the vpn in addition to using my script found here to mark the traffic on the 'flex' port.
I wrote a windows batch file to route plex.tv's current IP address (with various subnet masks to choose from) to your machine's default gateway (e.g. 192.168.2.1). I promise the bat file is safe, just google me and my reputation will speak for itself.
The code is below but I also uploaded a zip containing the bat file and an exe version of the bat file (same as the bat file except runs invisibly). For best results, use windows task scheduler to launch the exe (with highest privileges) as often as you'd like.
This will ensure that even if the IP for plex.tv changes, your setup will automatically route it past your VPN. A list of routed IPs will be saved here:
"%userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs.txt"
Tons of good stuff there, as well as donation links should you like my work and be feeling generous
@echo off
setlocal
set PATH=%SystemRoot%\system32;%SystemRoot%\system32\wbem;%SystemRoot%
chcp 437>nul
echo VPN Bypass for Plex Media Server
echo by XFlak
echo.
::get Default Gateway
ipconfig|findstr /I /C:“Default Gateway”|findstr /I /C:“1” >"%temp%\gateway.txt"
set /p gateway= <"%temp%\gateway.txt"
set gateway=%gateway:*: =%
::echo %gateway%
::If gateway is detected incorrectly, override it by uncommenting the below like (delete : and input your correct gateway
::set gateway=192.168.2.1
echo Getting plex.tv current IP addresses…
echo.
echo Note: Log of plex.tv’s routed IP’s saved here:
echo %userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs.txt
echo.
nslookup “plex.tv”|findstr /I /V “Server: Address: Name: timeout” >"%temp% emp.txt"
findstr /I /C:" " “%temp% emp.txt” >"%temp%\plex.tv.txt"
echo.
cd /d “%temp%”
for /F “tokens=*” %%A in (plex.tv.txt) do call :list %%A
goto:donelist
:list
set PlexIP=%*
set PlexIP=%PlexIP:* =%
echo %PlexIP%
if not exist “%userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs.txt” goto:skipcheck
findstr /I /C:"%PlexIP%" “%userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs.txt”>nul
IF NOT ERRORLEVEL 1 (echo IP already routed, skipping…) & (goto:EOF)
:skipcheck
::clean no longer used IPs
echo.
echo Removing routed IPs no longer used by plex.tv
echo.
if exist “%userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs2.txt” del “%userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs2.txt”>nul
if not exist “%userprofile%\AppData\Local\Plex Media Server” goto:doneclean
if not exist “%userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs.txt” goto:doneclean
cd /d “%userprofile%\AppData\Local\Plex Media Server”
for /F “tokens=*” %%A in (PermittedPlexIPs.txt) do call :clean %%A
goto:doneclean
:clean
set PlexIP=%*
findstr /I /C:"%PlexIP%" “%temp%\plex.tv.txt” >nul
IF ERRORLEVEL 1 goto:remove
echo IP still used: %PlexIP%
echo %PlexIP% >>"%userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs2.txt"
goto:EOF
:remove
echo IP no longer used: route delete %PlexIP%
route delete %PlexIP%
goto:EOF
:doneclean
if exist “%userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs.txt” del “%userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs.txt”>nul
if exist “%userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs2.txt” move /y “%userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs2.txt” “%userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs.txt”>nul
edit: code was missing a ">", old version still worked but log only retained latest IP, the 4 people who downloaded the last version may want to redownload the new one
edit2: updated script\attachments on May 12, 2015, it's now more efficient\secure by using nslookup instead of ping and using subnet mask 255.255.255.255 instead of 255.255.0.0. Thanks to John Doe at cutting cords for the suggestions.
edit3: updated on May 20, 2015, now includes a read me, an uninstaller, and multiple versions of the script for different subnet masks. Try them in the following order until you find one that works for you. Warning, the further you get to the bottom of the list the more IPs will bypass your VPN.
edit4: updated on June 16, 2015, now it removes old IP addresses no longer used by plex.tv from being routed past your VPN. So only the current IP addresses used by plex.tv will bypass your VPN and nothing else.
edit5: minor update, also added version # (v5) and icon to the exe's
I wrote a windows batch file to route my.plexapp.com's current IP address (with mask 255.255.0.0) to your machine's default gateway (e.g. 192.168.2.1). I promise the bat file is safe, just google me and my reputation will speak for itself.
The code is below but I also uploaded a zip containing the bat file and an exe version of the bat file (same as the bat file except runs invisibly). For best results, use windows task scheduler to launch the exe (with highest privileges) as often as you'd like.
This will ensure that even if the IP for my.plexapp.com changes, your setup will automatically route it past your VPN. A list of routed IPs will be saved here:
"%userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs.txt
I'm using PIA and this works perfectly.
Enjoy!
XFlak
Thanks for that, but it isn't going to work for me since I'm on a Mac. Although I should be able to use this to create a script that would work on Mac. The problem with my setup is that I was trying to use my router to establish the VPN connection and then route through it without having to mess with too much on my Mac. Didn't quite work out that way, but I actually think I know what I have to do to get it working properly. Just haven't had a chance to try it just yet.
I wrote a windows batch file to route my.plexapp.com's current IP address (with mask 255.255.0.0) to your machine's default gateway (e.g. 192.168.2.1). I promise the bat file is safe, just google me and my reputation will speak for itself.
The code is below but I also uploaded a zip containing the bat file and an exe version of the bat file (same as the bat file except runs invisibly). For best results, use windows task scheduler to launch the exe (with highest privileges) as often as you'd like.
This will ensure that even if the IP for my.plexapp.com changes, your setup will automatically route it past your VPN. A list of routed IPs will be saved here:
"%userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs.txt
I'm using PIA and this works perfectly.
Enjoy!
XFlak
@echo off
setlocal
set PATH=%SystemRoot%\system32;%SystemRoot%\system32\wbem;%SystemRoot%
chcp 437>nul
echo my.plexapp.com VPN Route Exception Builder
echo by XFlak
echo.
::get Default Gateway
ipconfig|findstr /I /C:“Default Gateway”|findstr /I /C:“1” >“%temp%\gateway.txt”
set /p gateway= <“%temp%\gateway.txt”
set gateway=%gateway:*: =%
::echo %gateway%
set /p PlexIP= <“%temp%\my.plexapp.com.txt”
set PlexIP=%PlexIP:*[=%
set PlexIP=%PlexIP:~0,-24%
echo %PlexIP%
echo.
set zero=%PlexIP:.=%
set zero=%zero:.=%
echo set PlexIP=%%PlexIP:%zero%=0.0%%>“%temp%\plex.bat”
call “%temp%\plex.bat”
::echo %PlexIP%
if not exist “%userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs.txt” goto:skipcheck
findstr /I /C:“%PlexIP%” “%userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs.txt”>nul
IF NOT ERRORLEVEL 1 (echo IP already routed, exiting…) & (goto:fin)
:skipcheck
echo Adding IP to %userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs.txt
echo.
echo %PlexIP% >>“%userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs.txt”
:fin
::echo fin
::pause
exit
edit: code was missing a ">", old version still worked but log only retained latest IP, the 4 people who downloaded the last version may want to redownload the new one
Thanks, I've been hoping for something like this for a long time. Im not very network savvy.
Anyways, I've tried this a few times (the updated .bat) and I cant get it to work. Is there anything in the file I need to edit to make it specific for my setup? For instance, I start Plex > verify that myPlex is able to publish > start PIA > run .bat > get 'myPlex could not reach your server'
I am behind a router and on Windows 7 if that makes a difference. Thanks
Make sure you're running it as an administrator. Also, for this to work you'll still need to set up port forwarding for port 32400 to forward to your plex server
I wrote a windows batch file to route my.plexapp.com's current IP address (with mask 255.255.0.0) to your machine's default gateway (e.g. 192.168.2.1). I promise the bat file is safe, just google me and my reputation will speak for itself.
The code is below but I also uploaded a zip containing the bat file and an exe version of the bat file (same as the bat file except runs invisibly). For best results, use windows task scheduler to launch the exe (with highest privileges) as often as you'd like.
This will ensure that even if the IP for my.plexapp.com changes, your setup will automatically route it past your VPN. A list of routed IPs will be saved here:
"%userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs.txt
I'm using PIA and this works perfectly.
Enjoy!
XFlak
@echo off
setlocal
set PATH=%SystemRoot%\system32;%SystemRoot%\system32\wbem;%SystemRoot%
chcp 437>nul
echo my.plexapp.com VPN Route Exception Builder
echo by XFlak
echo.
::get Default Gateway
ipconfig|findstr /I /C:“Default Gateway”|findstr /I /C:“1” >“%temp%\gateway.txt”
set /p gateway= <“%temp%\gateway.txt”
set gateway=%gateway:*: =%
::echo %gateway%
set /p PlexIP= <“%temp%\my.plexapp.com.txt”
set PlexIP=%PlexIP:*[=%
set PlexIP=%PlexIP:~0,-24%
echo %PlexIP%
echo.
set zero=%PlexIP:.=%
set zero=%zero:.=%
echo set PlexIP=%%PlexIP:%zero%=0.0%%>“%temp%\plex.bat”
call “%temp%\plex.bat”
::echo %PlexIP%
if not exist “%userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs.txt” goto:skipcheck
findstr /I /C:“%PlexIP%” “%userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs.txt”>nul
IF NOT ERRORLEVEL 1 (echo IP already routed, exiting…) & (goto:fin)
:skipcheck
echo Adding IP to %userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs.txt
echo.
echo %PlexIP% >>“%userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs.txt”
:fin
::echo fin
::pause
exit
edit: code was missing a ">", old version still worked but log only retained latest IP, the 4 people who downloaded the last version may want to redownload the new one
my default gateway is 192.168.1.1 is there a way to edit the .exe?
Make sure you're running it as an administrator. Also, for this to work you'll still need to set up port forwarding for port 32400 to forward to your plex server
It should auto detect your gateway based on your Windows settings. If u want to override it if for some reason auto detection isn’t working properly change this line from:
::set gateway=192.168.2.1
To
set gateway=192.168.1.1
I suggest you test with auto detection first.
After editing the bat, u can compile it into a new exe using bat to exe:
To just check what gateway is being auto detected u can uncomment these 2 lines:
::echo %gateway%
::pause
To uncomment them just delete the “::” at the start of the line. Then run the bat as an administrator and it will write on screen what the gateway is detected to be
Is anyone doing this from a DD-WRT router? Temporarily I have an exception in IPTABLES for the plex.tv IP address, which I specify manually on my Plex Server by modifying the local DNS to keep it from changing. So far I've been fine for the last few weeks and haven't had to change it, but I prefer a script like the ones above to automatically change it if need be in the future. I don't have a local VPN client on my PMS, my router does that so any script would need to run from that.
i've read through all of the posts here, and some of it seems a little over my head, but it looks like the VPN route exception file that XFlak uploaded seems to be the fix for this issue. I'm also using PIA and I have no issues whatsoever with streaming to devices on my network, but my remote sharing ability goes away after PIA is connected.
I have port 32400 forwarded on my router. Will running this bat upon startup fix this conflict? Or am I over simplifying it and skipping some key steps?
Running it at startup will get it working until the myplex IP changes, at which point remote access will stop working until the script is run again to route the new IP. I have the script running hourly for the past week and so far it’s only routed the following IPs:
184.72.0.0
50.18.0.0
184.169.0.0
54.241.0.0
So I could stop running the script today and until a new IP pops up it will continue to work, and that could take a long time, who knows. But if it stops working right now I know my script is going to run in <60min so even if I’m away from home I’ll never be without my files for more than an hour.
makes sense, i've now ran the script and I'm now showing that PMS is connected in the server tab!
I have set up a schedule as you suggested, so we will see how it goes from here out. thank you so much for doing this, you're saving me so much headache