3

I've got a linux server with two possible connections to the net: one is a slow, high-latency cellular modem (ppp0), and the other is through fast wifi->broadband (wlan0).

The problem is that the broadband connection sometimes goes down. However, because the wifi is still there, wicd leaves the default route through wlan0. (If the wifi signal disappeared, then wicd would remove wlan0 from the routing tables and the default route would fail over to ppp0, but, in this case, the wifi, itself, looks fine).

What I need is a tool which will actually test for connectivity all the way to some selected servers and, if they are unreachable, set the default routing interface to be ppp0 for a time.

I can probably hack together a script which can do this, but it seems like something which other people would have needed to do. Is there not already a tool or script which does this?

  • The problem here is that you are using wicd, and it will probably deliver you 2 "default gateways", one of each media type you are connected. On linux, you will have to: Keep the default gateway empty, create 2 rules each one with the gateways of the 2 media types, change the rules priority based on a ping/icmp test. – user34720 Mar 17 '14 at 21:06
  • Cisco routers can do that using ip-sla tracking, where you set up a probe to a remote device (usually a ping to an IP) to determine whether a route is available (you set the route to track an ip sla test)... I'm not sure if that is currently possible on Linux, possibly using routing software like quagga or similar... – Gert van den Berg Sep 23 '15 at 18:53
1

It seems your question is more "How can I programmatically test available bandwidth?" For your ping test you could do something like this:

root@xxxxxxlp01 ~ $ ping ehswebvlp10 -c4 | egrep -wo "time=.*" | cut -f2 -d= |  awk '{ sum+=$1} END {print sum/4}'
0.49
root@xxxxxxlp01 ~ $ ping ehswebvlp10 -c4 | egrep -wo "time=.*" | cut -f2 -d= |  awk '{ sum+=$1} END {print sum/4}'
0.208
root@xxxxxxlp01 ~ $ ping ehswebvlp10 -c4 | egrep -wo "time=.*" | cut -f2 -d= |  awk '{ sum+=$1} END {print sum/4}'
0.217

Then do some branching logic based on the number you get. Another test would be with using nc to establish a TCP connection to a remote server within a specified timeframe by using the -w option to specify a timeout in seconds. Example:

root@xxxxxxlp01 ~ $ nc -vz google.com 80 -w 3
Connection to google.com 80 port [tcp/http] succeeded!

Then do your branching from that.

It's important for stability that your tests be done over some span of time to allow for temporary congestion. Otherwise your interfaces could end up flapping. For example, if the ping is above your threshold, if it is then you sleep 15 or something and check a second time.

I would also use logger to throw something at syslogd every time you do make a change to the default route. Otherwise you may forget you did this, get some weird networking thing 4-5 months from now and need help figuring out what keeps changing the default route.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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