Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In Raspbian (Debian) on the RaspberryPi, I've got two interfaces, eth0 and wlan0, and I'm using eth0 (a cellular modem) as the primary connection, with only some heavy traffic going out through wlan0. To that end, I'm using the ip route command.
Eg: (Routing Google's stuff through wlan0)

ip route add 74.125.228.0/24 dev wlan0

But, unfortunately, the power in our building occasionally goes out, rendering wlan0 useless.

How can I keep this static connection routed only when the host (eg. Google.com) is reachable via wlan0 (ie. wireless), but switch to eth0 (ie. cellular) when the power goes out (eg. Hurricane Sandy), and the wireless router is useless?

share|improve this question
    
Write a script that pings the first hop (the AP) IP address. If it's not available, reconfigure so that the wireless is disabled. Note, you can either then write a script that attempts to reconnect every 30 mins by turning the port on and attempting to ping the AP, or you have to reset it by hand. –  Everett Feb 19 '13 at 3:37
    
There are routing protocols that do this for you. You just need to have OSPF or BGP enabled (instead of using a static route). –  Everett Feb 19 '13 at 3:38
    
@Everett That first suggestion sounds promising. Could you point me towards some material I could use as examples for that kind of scripting? As for the second suggestion, while it is true that those routing protocols could handle it, I'm worried that they may forego the use of the cellular eth0 all together (by definition, that's what OSPF would want to do, I feel). –  tamsanh Feb 19 '13 at 4:41
    
@Everett, it seems like going the script route will be the best option. Probably I'll set up something on a cron job which checks if it can ping a certain domain via the wlan0. If it can't ping it, then it'll just reroute everything. –  tamsanh Feb 20 '13 at 22:06

1 Answer 1

up vote 2 down vote accepted

Does the command support an argument called metric - if two routes are all equal except for the metric then the lower metric is used Normally typing in ip route add 74.125.228.0/24 dev wlan0 will add it into the table with metric =1 ie a manually added route is always used first But you should be able to adda second route to your less desirable card with metric =2

share|improve this answer
    
I think that's probably the answer I'm looking for, and indeed it is available in the route command. However, according to the manpage, it says it's not used by recent kernels. Once I get the opportunity, I will test it, and report back. –  tamsanh Feb 19 '13 at 4:50
    
The metric command is still available in recent kernels. (The difficulty you might have is if, when the power goes out, the WLAN connection does not loose its route). BTW, if you can't use a metric, you may be able to hack a similar solutions with 2 routes - 0.0.0.0 netmask 127.0.0.0 and 128.0.0.0 netmask 127.0.0.0 on the LAN interface. Because these are more specific routes they will be prefered if they are available - of-course, the problem is making them unavailable when WIFI goes down, and automatically adding them when WIFI comes back. –  davidgo Feb 19 '13 at 5:57
    
@davidgo, you're absolutely correct with that wifi problem. Ross's metric solution was half correct, but (as you said) the wlan0 is still technically a route. From what my tests have shown, it isn't the full solution. –  tamsanh Feb 20 '13 at 22:04
    
So, for now, while the proposed answer doesn't completely answer the question, it's the best one available, and certainly did help with most of the problems. –  tamsanh Feb 21 '13 at 16:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.