Set a route to default gateway without knowing default gateway

I think I have a very common situation: My WRT gets the default gateway via WAN interface (WAN; eth1.2).

Now I am setting up an OpenVPN tunnel (which overwrites the default route) and I want to explicitely prevent the VPN gateway (and a few other IPs!!) to go over the VPN ... but instead the normal WAN interface.

Everything works if I read out the default gateway manually and create a route. But of course, this default gateway changes.

I tried setting up a static route with "interface: wan" and target my VPN gateway ip and leaving "IPv4 Gateway" blank (= the route entry is created with:

(VPN-Gateway-IP)   *      UH    0      0        0 eth1.2

and I can't ping it.
I know that I could certainly create a hacky script which reads out the current default gateway and executes something like

route $VPNGWIP gw $DEFGW

from /etc/rc.local or similar ... but this doesn't sound reliable.

I wonder if there is as builtin way to accomplish this.

1 Like

Dynamic IPv4 gateway value for static route

1 Like

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