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.
- If (A) is not providing internet, switch to (B)
- 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....
How about this?
You can also use the metric option to avoid any existing internet connection trying to use this route in the meantime.
You can try using iptables with the Route Patch to specify the gateway to use on your ICMP packets sourcing from that (A) interface.
Supposing your (A) interface is 10.0.0.1 with a default gw of 10.0.0.2
Then
ping -I 10.0.0.1 x.x.x.x
Are the upstream gateways on the same Ethernet segment(s) as your router? If so
nping --dest-mac …
might work. (Nping is one of the many tools that come with nmap so it may already be on your system.)