@mcmax said:
Hi all!
running my Plex server on a Synology DS412+ behind an openVPN connection to Private Internet Access, I was also looking for a solution to have Plex bypass the VPN. @JB09 's script (which i adapted to Synology’s needs a little bit) works great when I run it from the terminal, however, running it as a cronjob just won’t work. I’d appreciate any ideas!
Here’s the script:
#!/bin/sh
#PATH=/opt/bin:/opt/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/syno/sbin:/usr/syno/bin:/usr/local/sbin:/usr/local/bin
#Fetch Current Server Address for plex.tv
DNS="$(dig plex.tv +short) $(dig serienjunkies.org +short)"
UNIQ_IP=$(echo "$DNS" | tr ' ' '
' | sort -u | tr '
' ' ')
for IP in $UNIQ_IP
do
#Create localroute variable to see if route exists
localroute=`ip route list table 2| grep $IP`
#Check if route exists
if [[ -z "$localroute" ]]; then
#route doesn't exist, add route
ip route add "$IP" via 192.168.100.1 dev eth0 table 2
echo "Route mit der IP "$IP" erfolgreich hinzugefuegt"
logger "Route mit der IP "$IP" erfolgreich hinzugefuegt"
else
#route exists, hurray
echo "Routen existieren bereits!"
logger "Routen existieren bereits!"
fi
done
exit 0
and here’s the relevant crontab line:
*/5 * * * * root /opt/skripte/addroutes.sh >> /opt/skripte/cron.log
there’s no output in the cron.log file.
EDIT: I do not know what I did, other than installing this script from jimmybonney.com/articles/manage_crontab_synology/ to manage crontab on Synology using the traditional “crontab” command. Maybe it checked my crontab file for syntax and fixed it. Anyway, cron seems to run the script now and it works great! Thanks again, @JB09 !
@mcmax Thanks for the script! Had to tweak it some to make it play nice on my synology (don’t really want to run any optware) but once tweaked it works perfectly through DSM’s Task Scheduler
EDIT 04/30/2020:
If anyone is interested in the changes/tweaks I made and how I am running this on my Synology here it is:
My script is almost exactly the same as the original, but, it utilizes the DNS Server package and Task Scheduler to avoid the need for any optware installation and cron modification.
The big caveat here is that static routes are probably not going to help you if you’re running your VPN on the Synology itself. In my case the VPN is running on another machine that acts as a proxy. The Synology then has two physical connections, one that goes to my VPN Proxy machine and one that goes directly to my router (and out to the internet).
On to the actual script and setup.
Lucky for us, we don’t actually need to use/run the DNS package, we just need the tools that are part of it, so you can leave the package “Stopped” on your synology, once it is installed. The script itself I saved as plexroutes.sh and stored in one of my Shared Folders. Then I created a task in Task Scheduler that runs daily to execute it. The script will update the Static Route table to force Plex to use the designated interface.
<Synology_IP_Here> this value should be replaced with the IP address of the interface Plex is using on the Synology
<Synology_Interface_Here> this value should be the interface name (Ex. eth0, eth1, etc.)
#!/bin/sh
#PATH=/volume1/@appstore/DNSServer/bin/:/opt/bin:/opt/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/syno/sbin:/usr/syno/bin:/usr/local/sbin:/usr/local/bin
PATH=/volume1/@appstore/DNSServer/bin/:/opt/bin:/opt/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/syno/sbin:/usr/syno/bin:/usr/local/sbin:/usr/local/bin
#Fetch Current Server Address for plex.tv
DNS="$(dig plex.tv +short)"
UNIQ_IP=$(echo "$DNS" | tr ' ' '\n' | sort -u | tr '\n' ' ')
for IP in $UNIQ_IP
do
#Create localroute variable to see if route exists
localroute=`ip route list table static-table | grep $IP`
#Check if route exists
if [[ -z "$localroute" ]]; then
#route doesn't exist, add route
ip route add "$IP" via <Synology_IP_Here> dev <Synology_Interface_Here> table static-table
echo "Route with the IP "$IP" successfully added"
logger "Route with the IP "$IP" sucessfully added"
else
#route exists, hurray
echo "Route already exists!"
logger "Route already exists!"
fi
done
exit 0