Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save willemnviljoen/0044f2f89042f06bea35d8ffc0248e3d to your computer and use it in GitHub Desktop.
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
#!/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
@willemnviljoen
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment