Remote Access Plex Media Server on Windows Behind VPN

plexPlex Media Server is the popular choice for making your media collection available to an array of devices. If you use torrents for acquiring new content then you of course use a VPN as well for safety. Plex routes traffic through which goes through your VPN connection, meaning remotely accessing your media collection would require port forwarding through the VPN. Luckily XFlak has created a batch script to reroute Plex traffic through your normal network connection, bypassing the VPN and restoring Plex Media Server remote access behind the VPN. This tutorial is relatively easy to set up on Windows 7, 8 and 10. It should work on Windows Server 2008, 2012 and 2016 too.

Private Internet Access and PureVPN are popular VPN providers which you may want to access your Plex media collection while using.

VPN Service
All Platforms
Number of Connections
Monthly Cost
Annual Cost
Private Internet Access
($3.33 / month)
Pure VPN
($4.91 / month)
($6.41 / month)

Remote Access Plex Media Server on Windows Behind VPN

All credit for this script goes to XFlak (his site) on the Plex forum. The original post by XFlak is here and may have a newer version of the Windows batch script than here.

Create an empty file somewhere on your machine, I put it in C:\HTPCGuides\PlexVPN.bat

Paste the batch script written by XFlak for allowing Plex to map its port back without the VPN by correcting the routes for Plex

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

echo VPN Bypass for Plex Media Server
echo by XFlak

::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= echo Getting current IP addresses... echo. echo Note: Log of's routed IP's saved here: echo %userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs.txt echo. nslookup ""|findstr /I /V "Server: Address: Name: timeout" >"%temp%\temp.txt"
findstr /I /C:"  " "%temp%\temp.txt" >"%temp%\"

cd /d "%temp%"
for /F "tokens=*" %%A in ( do call :list %%A

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)

echo route -p add %PlexIP% mask %gateway%
route -p add %PlexIP% mask %gateway%
echo %PlexIP% >>"%userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs.txt"


::clean no longer used IPs
echo Removing routed IPs no longer used by

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

set PlexIP=%*
findstr /I /C:"%PlexIP%" "%temp%\" >nul
IF ERRORLEVEL 1 goto:remove

echo IP still used: %PlexIP%
echo %PlexIP% >>"%userprofile%\AppData\Local\Plex Media Server\PermittedPlexIPs2.txt"

echo IP no longer used: route delete %PlexIP%
route delete %PlexIP%

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

echo Finished, exiting...
@ping -n 3 -w 1000> nul

You can create a task for the Plex VPN Windows script. Personally I have never needed it and just run it as a batch file on boot, however XFlak and this site recommend it in case Plex IPs change.

Load up the Windows Run menu with Windows+R


Click Create Task..

plex vpn task scheduler 1

Enter a Name for the Task

Select Run whether user is logged on or not

Check Run with highest privileges

plex vpn task scheduler 2

Click the Triggers tab and click New


For Begin the task: choose At startup

Check Repeat task every: and choose 1 hour to make sure the route is always up to date for a duration of Indefinitely

Check Enabled and click OK

plex vpn task scheduler 4

Now click the Action tab and click New


Click Browse and choose your PlexVPN.bat file

Click OK


Now just click OK and your task is created.


Now you will be able to access Plex Media Server behind a VPN on Windows. If you found this useful consider donating to XFlak so he continues to update this valuable script.