Script to detect new gateway & rewrite routing rule?

I run almost all traffic through Mullvad VPN on my router(s), but there are a couple of cases where I need to bypass the VPN. I've done that successfully with a simple added routing table and policy rules, and it works fine.

However, my new ISP uses a CG-NAT implementation where not only my own IP changes regularly, but also the gateway address. When that happens, it makes the bypass route fail silently because the WAN gateway is specified explicitly and the old address is no longer valid. I have to notice that it's broken (usually by getting blocked from whatever I needed to do VPN-less) and manually fix the bypass route every time.

What I'd like is a script that checks occasionally (once per hour, maybe?) for a change of the WAN gateway (i.e. current gateway doesn't match what's listed in the bypass route), rewrites the bypass route if needed, and applies it.

As I mentioned in my other topic, I don't have any knowledge at all of shell scripting and this seems much more involved than that (if it's even possible) so I'm asking for some direct help here.

Would any kind soul be willing to A) write a script for this, and B) tell me how to use it (this could just be a link to the appropriate docs page, i.e. cron or whatever), please?

Maybe an update on the wan interface?
See https://openwrt.org/docs/guide-user/base-system/hotplug

Try the following:

  1. Remove the entry that creates a default route in the custom routing table.
  2. Add this to the wan interface section:
option ip4table '101' # <-- Correct table ID here 

This way the default route should be created automatically and updated if there are changes.

1 Like

Hmm. That doesn't appear to work. Traffic doesn't get out at all (using the bypass table).

EDIT: Nevermind, I'm an idiot. That seems to work! Thank you!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.