Ping with explicit next-hop selection (aka Monitoring multiple default gateways)

Posted by Michuelnik on Server Fault See other posts from Server Fault or by Michuelnik
Published on 2012-09-13T18:12:21Z Indexed on 2012/09/14 15:40 UTC
Read the original article Hit count: 239

Filed under:
|
|

I have a linux (debian) router with two internet connections (A) and (B).

(A) is preferred, (B) is fallback.

I want to monitor the internet connection (and not only the availability of the gateways!) and change the default route appropriately.

  1. If (A) is not providing internet, switch to (B)
  2. If (A) is providing internet again, switch back to (A).

Only problem I have is in case (2). My routing table points towards a working internet so I cannot easily detect whether internet is working over link (A) again.

I am search for a ping or traceroute (or other diagnosis-tool) which can select the next-hop explicitly.

  • ping -r looks promising, but can only ping a host on the lan. (It only has to write another destination address in the packet, damnit!)
  • traceroute -g gateway looks even more promising and nearly does what I want - but sets source routing options which my next-hops deny. (Not within my administrative boundary...)

I just want a $ping, that can:

  • select a source interface (and address)
  • select a next-hop on that interface
  • ping any arbitrary ip address

I could do evil trickery with policy-based routing but that would have production impact for all users. I would like to see a side-effect-free solution....

© Server Fault or respective owner

Related posts about linux

Related posts about networking