Fallback-gw is a little Perl script to be called via cron
that (1) checks availibility of neighbor routers using ping
and (2) activates backup routing on ping failure.
It can be used as a stupid replacement for BGP/OSPF in a multihomed environment.
Tested platforms are FreeBSD and Linux/iproute2.
Contact author: ilya.evseev/gmail.com
Usage: fallback-gw [--dry] [--verbose] [/path/to/config]
<commands>
# Linux iproute2 hooks...
ping = /bin/ping -nq -t1 -w5 -c1
list_routes = /sbin/ip route list | grep -w via | awk '{print $1, $3}'
add_route = /sbin/ip route add
delete_route = /sbin/ip route delete
change_route = /sbin/ip route change
</commands>
<destination2gateway inet>
destination 0.0.0.0/0
gateway 1.1.1.1
gateway 2.2.2.2
</destination2gateway>
<commands> # FreeBSD hooks... ping = /sbin/ping -nq -m1 -c5 -o list_routes = /usr/bin/netstat -nr | grep -Ew 'UGH?S' add_route = /sbin/route add delete_route = /sbin/route delete </commands> <gateway first_isp> gateway 1.1.1.1 </gateway> <gateway second_isp> gateway 2.2.2.2 </gateway> <destination first_nets> destination 1.1.0.0/16 destination 3.3.3.0/24 </destination> <destination second_nets> destination 2.2.0.0/16 destination 4.4.4.0/24 </destination> <destination2gateway first> gateway first_isp destination first_nets </destination2gateway> <destination2gateway second> gateway second_isp destination second_nets </destination2gateway> <destination2gateway inet> destination 0.0.0.0/0 gateway first_isp gateway second_isp </destination2gateway>
You can use INCLUDES for sharing <commands> section between multiple configs, etc.
Enjoy! :-)