#!/bin/bash

INTERFACE=eth0
GATEWAY_IFUP=192.168.0.1
GATEWAY_IFDOWN=192.168.2.1
TARGET_HOST=8.8.8.8

ping -c 3 $TARGET_HOST > /dev/null

if [ $? -eq 0 ]; then
    /sbin/ip route replace default via $GATEWAY_IFUP
else
    /sbin/ip route replace default via $GATEWAY_IFDOWN
fi