Diagram:
PHP Code:
GRE Tunnel ISP A
|------ISP A------|
Site A----FW A (Linux)----| GRE Tunnel |----FW B (Linux)----Site B
|------ISP B------|
GRE Tunnel ISP A
Site A connect to Site B: 2 GRE Tunnel
- Site A --> GRE Tunnel ISP A --> Site B
- Site A --> GRE Tunnel ISP B --> Site B
Default routing Site A --> Site B: GRE Tunnel ISP A
The sometimes Site A --> GRE Tunnel ISP A --> Site B: packets loss, i want script checking ICMP Packet loss and change static route to GRE Tunnel ISP B.
PS: I have use monit (
http://mmonit.com/monit/) checking ICMP but only checking host down, up.
This is my script shell:
PHP Code:
#! /bin/bash
# ping_check.sh
ping_check()
{
ping_recv=`ping -W1 -f -c100 $1 | grep rtt | cut -f4 -d' ' | cut -f2 -d'/' | cut -f1 -d'.'`
ping_loss=`ping -W1 -f -c100 $1 | grep loss | cut -f3 -d',' | cut -f2 -d' ' | sed 's/\(.*\)./\1/'`
if [ "$ping_recv" -gt 200 ] || [ "$ping_loss" -gt 10 ]; then
return 0
else
return 1
fi
}
ispa_route()
{
ip ro re 10.10.0.0/16 dev gre_isp_a
ip ro re 10.20.0.0/16 dev gre_isp_a
ip ro re 10.30.0.0/16 dev gre_isp_a
current_route=ispa
echo $current_route > current_route
echo `date` $current_route >> change_route.log
}
ispb_route()
{
ip ro re 10.10.0.0/16 dev gre_isp_b
ip ro re 10.20.0.0/16 dev gre_isp_b
ip ro re 10.30.0.0/16 dev gre_isp_b
current_route=ispb
echo $current_route > current_route
echo `date` $current_route >> change_route.log
}
ISPA_IP=1.1.1.1
ISPB_IP=5.5.5.5
ispa_route
while [ "1" = "1" ]; do
case $current_route in
ispa)
!(ping_check $ISPA_IP) && ispb_route
;;
ispb)
!(ping_check $ISPB_IP) && ispa_route
;;
*)
esac
sleep 10
done