Static Route Based on interface?

I have a cable Internet connection as my main gateway backed up by a cellular connection. Both are DHCP and not assigned permanent IPs. The IP on the cable takes a heroic effort to change, but the cellular one changes every reconnection.

There are certain hosts that I would like to always use the cellular connection. Right now, I have that working by establishing static routes that push the data to the IP address of the cellular gateway.

The problem is since the IP address of that gateway changes, I would like the routing to simply say “use wwan0 instead of wlan” so I don’t have to update the route every time the static IP changes.

I supposed I could do this with a script, but is there an automatic way?

Tia

https://openwrt.org/docs/guide-user/network/wan/multiwan/mwan3

2 Likes

That is... yes, that's helpful for setting up the failover. That's not my issue though.

Sure looks like you issue to me...

OK, enlighten me then. Using mwan3 and the instructions in that link, please show me where it says how I can route all traffic to 139.59.209.225 through wwan0 instead of the default gateway without knowing the current IP assigned to wwan0. (Pro-tip: it's not there)

What I am doing in the meantime is using hotplug to write a shell script that will awk in the new address when there's a DHCP change into /etc/config/network

Make a rule to that IP address to use the policy utilizing only the wwan0 member interface.
Not all use case scenarios are described in the guide, however it doesn't take too much brains to think that you can create a rule and bind it to policy wan_only or wanb_only.
And don't be a smart-ass towards people who offer to help you.

I stand corrected but your first answer to a very long link got the response it deserved. Don't expect people to thank you profusely when you answer in that fashion.

It is stated in the capabilities in the beginning of the page, so you wouldn't have to go through the whole page.

provides specific outbound traffic rules to customize which outbound connections should use which WAN interface
this can be customized based on source IP, destination IP, source port(s), destination port(s), type of IP protocol

Also a bit further down, why should I use mwan3.

If you have multiple internet connections, you want to control which traffic goes through which WANs

1 Like

@trendy's first answer was absolutely correct. I use mwan3 for exactly the use case you described.

I don't use the failover. Certain traffic for certain hosts and other traffic for specific protocols goes over one link and the rest over another link. The combination of policies and rules is quite powerful.

It's the right tool for the job. It would be fair to give a word of thanks, even if the document he pointed you at didn't necessarily explain all its capabilities.

And you don't need to use awk in a shell script to get the new ip. There is an inbuilt function that will get it if you supply the interface name. In the hotplug script

. /lib/functions/network.sh

network_get_ipaddr ipaddr ${INTERFACE}
echo ${ipaddr}
2 Likes