Created
August 30, 2017 06:01
-
-
Save willemnviljoen/0044f2f89042f06bea35d8ffc0248e3d to your computer and use it in GitHub Desktop.
On OpenWRT routers configured to route all traffic through VPN by default, force NTP to be routed via the local default gateway
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
DEFAULTROUTE=`/sbin/route | /bin/grep -v '*' | /bin/grep eth0 | /usr/bin/awk '{print $2}' | /usr/bin/head -n1` | |
NTPSERVERS=`/bin/grep 'list server' /etc/config/system | /usr/bin/awk '{print $3}' | /bin/sed "s/'//g"` | |
for HOST in $NTPSERVERS; do /sbin/route add $HOST gw $DEFAULTROUTE; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For some reason, this doesn't work when run from /etc/rc.local, likely because no routes exist by the time that executes. Running it from cron every few minutes works, it doesn't matter if it runs multiple times.