I have an embedded device where I have three network connections, eth0, wwan0, and wlan0. wwan0 is a metered connection, so I would generally prefer eth0 or wlan0. The problem is that at any given time any interface can be connected but not actually be able to reach the internet. For various reasons any interface may not be present at all. In this case my routing table does not do what I want. Is there a better way to handle this than a script that constantly checks and modifies the routing table? Part of the problem is that there are too many combinations and permutations of available, not available, no internet, etc.
답변1
As you noticed, there are many possibilities. There are murky ones, for example: "has internet, but just the test servers are unavailable", and they can be unavailable because they are all failed or blocked by the government. It is also possible that "half" of the internet is accessible through one ISP and "other half" is inaccessible; but other ISP has the picture "reversed". (Trust me or not, I've seen such a situation once.) Which one you declare as "having internet"?
This is very tough question, that's why there exists a whole business niche for SOHO routers that are, more or less, able to make a decision in various situations, and those are generally not very easy to set up so they could make a good enough decision. This is also why all that BGP business in the telecom world.
So, as you see, no, you can't do much better and more efficient than the script. I don't know why you want that, but for the desktop/end user machine I think it is not worthy automating this at all. For the Linux router I'd make a standard split-access configuration with RPDB and default routes through each link with high metrics, in the order of preference, and then the script will only set or update the default route with low metric based on pings to, say, five geographically distributed test points, carefully selected (the most accessed or important ones).